Skip to content

Commit 32a4e04

Browse files
authored
Fix base python conflict (#77)
1 parent 18c1677 commit 32a4e04

File tree

6 files changed

+40
-41
lines changed

6 files changed

+40
-41
lines changed

.github/SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Supported Versions
44

55
| Version | Supported |
6-
|---------| ------------------ |
6+
| ------- | ------------------ |
77
| 1.0.0 + | :white_check_mark: |
88
| < 1.0.0 | :x: |
99

.github/workflows/check.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ jobs:
3030
- windows-latest
3131
- macos-latest
3232
include:
33-
- { os: ubuntu-latest, py: "pypy3.10" }
34-
- { os: ubuntu-latest, py: "pypy3.8" }
35-
- { os: windows-latest, py: "pypy3.10" }
33+
- { os: ubuntu-latest, py: "pypy3.10" }
34+
- { os: ubuntu-latest, py: "pypy3.8" }
35+
- { os: windows-latest, py: "pypy3.10" }
3636
steps:
3737
- name: setup python for tox
3838
uses: actions/setup-python@v5

.pre-commit-config.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
rev: 0.29.1
99
hooks:
1010
- id: check-github-workflows
11-
args: [ "--verbose" ]
11+
args: ["--verbose"]
1212
- repo: https://github.com/codespell-project/codespell
1313
rev: v2.3.0
1414
hooks:
@@ -24,11 +24,18 @@ repos:
2424
hooks:
2525
- id: pyproject-fmt
2626
- repo: https://github.com/astral-sh/ruff-pre-commit
27-
rev: "v0.5.5"
27+
rev: "v0.5.7"
2828
hooks:
2929
- id: ruff-format
3030
- id: ruff
3131
args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"]
32+
- repo: https://github.com/rbubley/mirrors-prettier
33+
rev: "v3.3.3" # Use the sha / tag you want to point at
34+
hooks:
35+
- id: prettier
36+
additional_dependencies:
37+
38+
- "@prettier/[email protected]"
3239
- repo: meta
3340
hooks:
3441
- id: check-hooks-apply

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ dynamic = [
4242
dependencies = [
4343
"importlib-resources>=6.4; python_version<'3.9'",
4444
"packaging>=24.1",
45-
"tox<5,>=4.16",
45+
"tox<5,>=4.18",
4646
"typing-extensions>=4.12.2; python_version<'3.10'",
47-
"uv<1,>=0.2.33",
47+
"uv<1,>=0.2.35",
4848
]
4949
optional-dependencies.test = [
5050
"covdefaults>=2.3",
@@ -90,6 +90,7 @@ lint.ignore = [
9090
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
9191
"D301", # Use `r"""` if any backslashes in a docstring
9292
"D401", # First line of docstring should be in imperative mood
93+
"DOC201", # no support for sphinx
9394
"ISC001", # Conflict with formatter
9495
"S104", # Possible binding to all interface
9596
]

src/tox_uv/_venv.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33
from __future__ import annotations
44

55
import json
6-
import os
76
import sys
87
from abc import ABC
98
from functools import cached_property
10-
11-
if sys.version_info >= (3, 9): # pragma: no cover (py39+)
12-
from importlib.resources import as_file, files
13-
else: # pragma: no cover (py38+)
14-
from importlib_resources import as_file, files
15-
16-
179
from pathlib import Path
1810
from platform import python_implementation
1911
from typing import TYPE_CHECKING, Any, Literal, Optional, Type, cast
@@ -22,18 +14,21 @@
2214
from tox.execute.request import StdinSource
2315
from tox.tox_env.errors import Skip
2416
from tox.tox_env.python.api import Python, PythonInfo, VersionInfo
17+
from tox.tox_env.python.virtual_env.api import VirtualEnv
18+
from uv import find_uv_bin
19+
from virtualenv.discovery.py_spec import PythonSpec
20+
21+
from ._installer import UvInstaller
2522

2623
if sys.version_info >= (3, 10): # pragma: no cover (py310+)
2724
from typing import TypeAlias
2825
else: # pragma: no cover (<py310)
2926
from typing_extensions import TypeAlias
3027

31-
from uv import find_uv_bin
32-
from virtualenv import app_data
33-
from virtualenv.discovery import cached_py_info
34-
from virtualenv.discovery.py_spec import PythonSpec
35-
36-
from ._installer import UvInstaller
28+
if sys.version_info >= (3, 9): # pragma: no cover (py39+)
29+
from importlib.resources import as_file, files
30+
else: # pragma: no cover (py38+)
31+
from importlib_resources import as_file, files
3732

3833
if TYPE_CHECKING:
3934
from tox.execute.api import Execute
@@ -64,8 +59,7 @@ def register_config(self) -> None:
6459
default=False,
6560
desc="add seed packages to the created venv",
6661
)
67-
# The cast(...) might seems superfluous but removing it
68-
# makes mypy crash. The problem is probably on tox's typing side
62+
# The cast(...) might seems superfluous but removing it makes mypy crash. The problem isy on tox typing side.
6963
self.conf.add_config(
7064
keys=["uv_python_preference"],
7165
of_type=cast(Type[Optional[PythonPreference]], Optional[PythonPreference]),
@@ -102,8 +96,7 @@ def installer(self) -> Installer[Any]:
10296
def runs_on_platform(self) -> str:
10397
return sys.platform
10498

105-
@staticmethod
106-
def _get_python(base_python: list[str]) -> PythonInfo | None:
99+
def _get_python(self, base_python: list[str]) -> PythonInfo | None: # noqa: PLR6301
107100
for base in base_python: # pragma: no branch
108101
if base == sys.executable:
109102
version_info = sys.version_info
@@ -121,10 +114,9 @@ def _get_python(base_python: list[str]) -> PythonInfo | None:
121114
platform=sys.platform,
122115
extra={},
123116
)
124-
if Path(base).is_absolute():
125-
info = cached_py_info.from_exe(
126-
cached_py_info.PythonInfo, app_data.make_app_data(None, read_only=False, env=os.environ), base
127-
)
117+
base_path = Path(base)
118+
if base_path.is_absolute():
119+
info = VirtualEnv.get_virtualenv_py_info(base_path)
128120
return PythonInfo(
129121
implementation=info.implementation,
130122
version_info=VersionInfo(*info.version_info),
@@ -151,6 +143,16 @@ def _get_python(base_python: list[str]) -> PythonInfo | None:
151143

152144
return None # pragma: no cover
153145

146+
@classmethod
147+
def python_spec_for_path(cls, path: Path) -> PythonSpec:
148+
"""
149+
Get the spec for an absolute path to a Python executable.
150+
151+
:param path: the path investigated
152+
:return: the found spec
153+
"""
154+
return VirtualEnv.python_spec_for_path(path)
155+
154156
@property
155157
def uv(self) -> str:
156158
return find_uv_bin()

tests/test_tox_uv_venv.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,6 @@ def test_uv_venv_spec_abs_path_conflict_impl(
105105
assert f"failed with env name {env} conflicting with base python {other_interpreter_exe}" in result.out
106106

107107

108-
def test_uv_venv_spec_abs_path_conflict_platform(
109-
tox_project: ToxProjectCreator, other_interpreter_exe: pathlib.Path
110-
) -> None:
111-
ver = sys.version_info
112-
env = f"py{ver.major}{ver.minor}-linux" if sys.platform == "win32" else f"py{ver.major}{ver.minor}-win32"
113-
project = tox_project({"tox.ini": f"[testenv:{env}]\npackage=skip\nbase_python={other_interpreter_exe}"})
114-
result = project.run("-vv", "-e", env)
115-
result.assert_failed()
116-
assert f"failed with env name {env} conflicting with base python {other_interpreter_exe}" in result.out
117-
118-
119108
def test_uv_venv_na(tox_project: ToxProjectCreator) -> None:
120109
# skip_missing_interpreters is true by default
121110
project = tox_project({"tox.ini": "[testenv]\npackage=skip\nbase_python=1.0"})

0 commit comments

Comments
 (0)