Skip to content

Commit 00c0a63

Browse files
committed
fix: correct the uv python dir with platformdirs
Signed-off-by: Frost Ming <me@frostming.com>
1 parent 195e191 commit 00c0a63

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

pdm.lock

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ authors = [
66
]
77
dependencies = [
88
"packaging>=20",
9+
"platformdirs>=4.3.6",
910
]
1011
requires-python = ">=3.8"
1112
license = {text = "MIT"}

src/findpython/providers/uv.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,18 @@
44
import typing as t
55
from pathlib import Path
66

7+
import platformdirs
8+
79
from findpython.providers.rye import RyeProvider
8-
from findpython.utils import WINDOWS
910

1011

1112
class UvProvider(RyeProvider):
1213
@classmethod
1314
def create(cls) -> t.Self | None:
14-
# See uv#13877(https://github.com/astral-sh/uv/issues/13877)
15-
if WINDOWS:
16-
default_root_str = os.getenv("APPDATA")
17-
else:
18-
default_root_str = "~/.local/share"
19-
assert default_root_str is not None
15+
default_root_str = platformdirs.user_data_dir("uv", appauthor=False, roaming=True)
2016
root_str = os.getenv("UV_PYTHON_INSTALL_DIR")
2117
if root_str is None:
22-
root_str = os.getenv("XDG_DATA_HOME")
23-
if root_str is None:
24-
root_str = default_root_str
25-
root = Path(root_str).expanduser() / "uv" / "python"
18+
root = Path(default_root_str).expanduser() / "python"
2619
else:
2720
root = Path(root_str).expanduser()
2821
return cls(root)

tests/test_posix.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import platform
12
import stat
23
import sys
34
from pathlib import Path
@@ -97,11 +98,15 @@ def test_find_python_from_rye_provider(mocked_python, tmp_path, monkeypatch):
9798

9899

99100
def test_find_python_from_uv_provider(mocked_python, tmp_path, monkeypatch):
101+
if platform.system() == "Linux":
102+
python_root = tmp_path / ".local/share/uv/python"
103+
else: # macos
104+
python_root = tmp_path / "Library/Application Support/uv/python"
100105
python310 = mocked_python.add_python(
101-
tmp_path / ".local/share/uv/python/cpython@3.10.9/install/bin/python3", "3.10.9"
106+
python_root / "cpython@3.10.9/install/bin/python3", "3.10.9"
102107
)
103108
python311 = mocked_python.add_python(
104-
tmp_path / ".local/share/uv/python/cpython@3.11.8/bin/python3", "3.11.8"
109+
python_root / "cpython@3.11.8/bin/python3", "3.11.8"
105110
)
106111
monkeypatch.setenv("HOME", str(tmp_path))
107112

@@ -112,13 +117,6 @@ def test_find_python_from_uv_provider(mocked_python, tmp_path, monkeypatch):
112117
find_311 = Finder(selected_providers=["uv"]).find_all(3, 11)
113118
assert python311 in find_311
114119

115-
monkeypatch.setenv("XDG_DATA_HOME", str(tmp_path / "xdg"))
116-
python310_xdg = mocked_python.add_python(
117-
tmp_path / "xdg/uv/python/cpython@3.10.9/install/bin/python3", "3.10.9"
118-
)
119-
find_310 = Finder(selected_providers=["uv"]).find_all(3, 10)
120-
assert python310_xdg in find_310
121-
122120
monkeypatch.setenv("UV_PYTHON_INSTALL_DIR", str(tmp_path / "uv_dir"))
123121
python311_uv_dir = mocked_python.add_python(
124122
tmp_path / "uv_dir/cpython@3.11.8/bin/python3", "3.11.8"

0 commit comments

Comments
 (0)