Skip to content

Commit bde2b07

Browse files
committed
Support Python imports with distinct package names
1 parent ebaa98a commit bde2b07

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

abxpkg/binprovider_uv.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,12 @@ def default_abspath_handler(
12201220
for line in proc.stdout.splitlines()
12211221
if line.startswith("Location: ")
12221222
]
1223-
module_names = [tool_name.replace("-", "_").replace(".", "_")]
1223+
module_names = list(
1224+
dict.fromkeys(
1225+
name.replace("-", "_").replace(".", "_")
1226+
for name in (str(bin_name), tool_name)
1227+
),
1228+
)
12241229
for line in proc.stdout.splitlines():
12251230
if line.startswith("Name: "):
12261231
package_name = line.split("Name: ", 1)[1].strip()

tests/test_cli.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4821,6 +4821,40 @@ def test_run_script_keeps_active_runtime_imports_with_uv_provider_cache(
48214821
assert Path(payload["rich_click_file"]).resolve() == Path(click.__file__).resolve()
48224822

48234823

4824+
def test_run_script_uv_dependency_can_expose_import_with_a_different_distribution_name(
4825+
tmp_path,
4826+
):
4827+
lib = tmp_path / "lib"
4828+
script = tmp_path / "import_sonic.py"
4829+
script.write_text(
4830+
"#!/usr/bin/env -S abxpkg run --script python3\n"
4831+
"# /// script\n"
4832+
'# requires-python = ">=3.12"\n'
4833+
'# dependencies = [{name = "sonic", binproviders = "uv", install_args = ["sonic-client>=1.0.0"], postinstall_scripts = false, min_release_age = 3}]\n'
4834+
"# ///\n"
4835+
"import json, sonic\n"
4836+
'print(json.dumps({"sonic_file": sonic.__file__}))\n',
4837+
)
4838+
script.chmod(0o755)
4839+
4840+
proc = _run_abxpkg_cli(
4841+
"run",
4842+
"--script",
4843+
"python3",
4844+
str(script),
4845+
env_overrides={
4846+
"ABXPKG_LIB_DIR": str(lib),
4847+
"ABXPKG_BINPROVIDERS": "env,uv",
4848+
},
4849+
)
4850+
4851+
assert proc.returncode == 0, proc.stderr
4852+
payload = json.loads(proc.stdout.strip().splitlines()[-1])
4853+
assert (
4854+
str(lib / "uv" / "packages" / "sonic-client" / "venv") in payload["sonic_file"]
4855+
)
4856+
4857+
48244858
def test_run_script_uses_default_lib_dir_without_env_override(tmp_path):
48254859
config_home = tmp_path / "xdg-config"
48264860
default_lib = config_home / "abx" / "lib"

0 commit comments

Comments
 (0)