Skip to content

Commit 01fc41d

Browse files
committed
Unify uv path handling
1 parent 0ca85c7 commit 01fc41d

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

lib/pythonx/uv.ex

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,29 @@ defmodule Pythonx.Uv do
6565
project_dir = project_dir(pyproject_toml, priv?)
6666

6767
# Uv stores Python installations in versioned directories in the
68-
# Python install dir. We find the specific one by looking at
69-
# pyvenv.cfg. It stores an absolute path, so we cannot rely on
70-
# that in releases. However, releases should use priv, and in
71-
# that case we know there is only a single Python version, so we
72-
# can resolve it directly.
73-
root_dir =
74-
if priv? do
75-
python_install_dir(priv?) |> Path.join("*") |> wildcard_one!()
76-
else
77-
pyenv_cfg_path = Path.join(project_dir, ".venv/pyvenv.cfg")
78-
79-
executable_dir =
80-
pyenv_cfg_path
81-
|> File.read!()
82-
|> String.split("\n")
83-
|> Enum.find_value(fn "home = " <> path -> path end)
84-
|> Path.expand()
85-
86-
case :os.type() do
87-
{:win32, _osname} -> executable_dir
88-
{:unix, _osname} -> Path.dirname(executable_dir)
89-
end
68+
# Python install dir. To find the versioned name for this project,
69+
# we look at pyvenv.cfg. We could use the "home" path altogether,
70+
# however it is an absolute path, so we cannot rely on it for priv
71+
# in releases anyway, and for consistency we handle both cases the
72+
# same way.
73+
74+
pyenv_cfg_path = Path.join(project_dir, ".venv/pyvenv.cfg")
75+
76+
abs_executable_dir =
77+
pyenv_cfg_path
78+
|> File.read!()
79+
|> String.split("\n")
80+
|> Enum.find_value(fn "home = " <> path -> path end)
81+
|> Path.expand()
82+
83+
versioned_dir_name =
84+
case :os.type() do
85+
{:win32, _osname} -> Path.basename(abs_executable_dir)
86+
{:unix, _osname} -> Path.basename(Path.dirname(abs_executable_dir))
9087
end
9188

89+
root_dir = Path.join(python_install_dir(priv?), versioned_dir_name)
90+
9291
case :os.type() do
9392
{:win32, _osname} ->
9493
# Note that we want the version-specific DLL, rather than the

0 commit comments

Comments
 (0)