Skip to content

Conversation

@davidsanfal
Copy link
Contributor

Changelog: (Feature | Fix | Bugfix): Describe here your pull request
Docs: https://github.com/conan-io/docs/pull/XXXX

  • Refer to the issue that supports this Pull Request.
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

pip_env = PipEnv(self, py_version="3.11.6")
pip_env.install(["{pip_package_folder}"])
pip_env.generate()
self.run(pip_env._get_env_python(pip_env._env_dir) + " --version")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ugly access, need some nicer public API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for testing purposes to verify that we are using the defined python version, but it has no real use in any recipe

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to the other ticket, if we want to give more visibility over the tools (uv or the Python version)
Once uv is there, and it is possible to install different python versions inside the PipEnv i'd say it is super likely that users might want to run python -m ... or python -c ..., with that specific Python that they explicitly requested.
So this self.run("python --version") is evidencing a very likely need of making that public API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! In that case we can expose it without any problems, of course

"Scripts" if platform.system() == "Windows" else "bin")
# init the venv
if py_version:
self._crete_uv_venv(py_version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other advantages of using uv could PipEnv enjoy?
Do we want a generic access interface to it like def install(self, packages, pip_args=None):?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The install interface is the same, It only affects how the virtual environment is created

:param py_version: Optional python version for the virtualenv using UV
"""
super().__init__(conanfile, folder, name)
self._base_env_dir = os.path.abspath(os.path.join(folder or conanfile.build_folder))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._base_env_dir = os.path.abspath(os.path.join(folder or conanfile.build_folder))
self._base_env_dir = os.path.abspath(folder or conanfile.build_folder)

:param conanfile: The current conanfile "self"
:param folder: Optional folder, by default the "build_folder"
:param name: Optional name for the virtualenv, by default "conan_uvenv"
:param py_version: Optional python version for the virtualenv using UV
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here says it's optional but it's not

f"environment using '{self._default_python}': {e}")


class UVEnv(PythonVirtualEnv):
Copy link
Contributor

@czoido czoido Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered not exposing a new UVEnv class? Because in the end uv is just the method we use for creating the environment but the functionality is the same for both exposed public classes. Maybe it should be a single class that you instance like this?

pip = PipEnv(self, backend="uv", ...)

If we keep the two different public classes (which I think is fine) maybe you should consider composition instead of inheritance for the common functionality.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could make sense, maybe that would also be a rename of the class to PyEnv?
We could do an alias first, deprecate the PipEnv with a warning to not break existing usage.

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.

3 participants