|
4 | 4 |
|
5 | 5 | import json |
6 | 6 | import logging |
| 7 | +import os |
7 | 8 | import sys |
8 | 9 | from abc import ABC |
9 | 10 | from functools import cached_property |
@@ -73,7 +74,9 @@ def register_config(self) -> None: |
73 | 74 | self.conf.add_config( |
74 | 75 | keys=["uv_python_preference"], |
75 | 76 | of_type=cast("Type[Optional[PythonPreference]]", Optional[PythonPreference]), # noqa: UP006 |
76 | | - default=lambda conf, name: self.environment_variables.get("UV_PYTHON_PREFERENCE", "system"), # noqa: ARG005 |
| 77 | + # use os.environ here instead of self.environment_variables as this value is needed to create the virtual |
| 78 | + # environment, if environment variables use env_site_packages_dir we would run into a chicken-egg problem. |
| 79 | + default=lambda conf, name: os.environ.get("UV_PYTHON_PREFERENCE", "system"), # noqa: ARG005 |
77 | 80 | desc=( |
78 | 81 | "Whether to prefer using Python installations that are already" |
79 | 82 | " present on the system, or those that are downloaded and" |
@@ -240,10 +243,10 @@ def env_python(self) -> Path: |
240 | 243 | def env_site_package_dir(self) -> Path: |
241 | 244 | if sys.platform == "win32": # pragma: win32 cover |
242 | 245 | return self.venv_dir / "Lib" / "site-packages" |
243 | | - else: # pragma: win32 no cover # noqa: RET505 |
244 | | - py = self._py_info |
245 | | - impl = "pypy" if py.implementation == "pypy" else "python" |
246 | | - return self.venv_dir / "lib" / f"{impl}{py.version_dot}" / "site-packages" |
| 246 | + # pragma: win32 no cover |
| 247 | + py = self._py_info |
| 248 | + impl = "pypy" if py.implementation == "pypy" else "python" |
| 249 | + return self.venv_dir / "lib" / f"{impl}{py.version_dot}" / "site-packages" |
247 | 250 |
|
248 | 251 | def env_version_spec(self) -> str: |
249 | 252 | base = self.base_python.version_info |
|
0 commit comments