Skip to content

refactor(venv): use ensurepip and common methods #29

Merged
joabech merged 2 commits intoanalogdevicesinc:mainfrom
gastmaier:cim-venv
Apr 20, 2026
Merged

refactor(venv): use ensurepip and common methods #29
joabech merged 2 commits intoanalogdevicesinc:mainfrom
gastmaier:cim-venv

Conversation

@gastmaier
Copy link
Copy Markdown
Contributor

@gastmaier gastmaier commented Apr 15, 2026

There is no guarantee pip is installed in the host to inherit to the
virtual environment. It is a bad practice to use host pip without
upgrading since it will be out-of-date.
The rationale behind the command is described at:
https://peps.python.org/pep-0453/

ensurepip --upgrade is not used because it ensures pip is at least as
recent as the one available in ensurepip, not the latest released.
Instead, upgrade explicitly with pip.

The method run_python_venv_creation was added to remove the repeated
venv creation logic.

Also loosely fix for windows (checked paths only), but tests should run on windows if we want to (pretend) to support (for unknown reasons).

Removed:

  • get_venv_pip_path: invoked vevn's pip directly. Despite functional, for all other logic we require invoke as venv/bin/python -m, it was a weird exception.

Tests:

Notes:

This pr does not investigate doc_manager, I touched it solely to move on with the venv refactor.
I believe there is a need for true venv generics, there is an assumption that venv is only for the documentation but there are many handy tools on it across the sdks.

Simple, inline fixes to handle the windows path and format.

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
There is no guarantee pip is installed in the host to inherit to the
virtual environment. It is a bad practice to use host pip without
upgrading since it will be out-of-date.
The rationale behind the command is described at:
https://peps.python.org/pep-0453/

ensurepip --upgrade is not used because it ensures pip is at least as
recent as the one available in ensurepip, not the latest released.
Instead, upgrade explicitly with pip.

The method run_python_venv_creation was added to remove the repeated
venv creation logic.

Signed-off-by: Jorge Marques <jorge.marques@analog.com>
@joabech
Copy link
Copy Markdown
Contributor

joabech commented Apr 17, 2026

Thanks, this looks like a good improvement. I'll run a few tests, then I'll merge if I see nothing strange.

there is an assumption that venv is only for the documentation but there are many handy tools on it across the sdks.

No, that's not the case, but it's only the docs that automatically creates and runs the venv. Like you implied, we use various Python script in our builds for a lot of other things as well. In hindsight and although this is neat from user point of view, I think the way of doing this auto install/enable should've been done in another way. But, I live the clean-up you've done, thanks!

@joabech
Copy link
Copy Markdown
Contributor

joabech commented Apr 20, 2026

I've tested this out in a few scenarios now and it's all good, thanks, this is a great improvement. Merging!

@joabech joabech merged commit 09869a1 into analogdevicesinc:main Apr 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants