Skip to content

Commit 479e994

Browse files
committed
use in-house unpacker
1 parent 1d698d0 commit 479e994

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

py/tools/py/src/unpack.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ use std::{
66

77
use miette::{miette, IntoDiagnostic, Result};
88

9+
const RELOCATABLE_SHEBANG: &'static str = r#"/bin/sh
10+
'''exec' "$(dirname -- "$(realpath -- "$0")")"/'python3' "$0" "$@"
11+
' '''
12+
"#;
13+
914
pub fn unpack_wheel(version: &str, location: &Path, wheel: &Path) -> Result<()> {
1015
let python_version: uv_python::PythonVersion = version
1116
.parse()
@@ -36,12 +41,12 @@ pub fn unpack_wheel(version: &str, location: &Path, wheel: &Path) -> Result<()>
3641
};
3742

3843
let layout = uv_install_wheel::Layout {
39-
sys_executable: PathBuf::new(),
44+
sys_executable: PathBuf::from(RELOCATABLE_SHEBANG),
4045
python_version: (python_version.major(), python_version.minor()),
4146
// Don't stamp in the path to the interpreter into the generated bins
4247
// as we don't want an absolute path here.
4348
// Perhaps this should be set to just "python" so it picks up the one in the venv path?
44-
os_name: "/bin/false".to_string(),
49+
os_name: "".to_string(),
4550
scheme,
4651
};
4752

uv/private/whl_install/rule.bzl

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ Installing wheels as a Bazel build action, rather than a repo step.
33
"""
44

55
load("@rules_python//python:defs.bzl", "PyInfo")
6+
load("//py/private/toolchain:types.bzl", "PY_TOOLCHAIN", "UNPACK_TOOLCHAIN")
67

7-
PYTHON_TOOLCHAIN_TYPE = "@rules_python//python:toolchain_type"
8-
UV_TOOLCHAIN = "@multitool//tools/uv:toolchain_type"
98

109
def _whl_install(ctx):
11-
py_toolchain = ctx.toolchains[PYTHON_TOOLCHAIN_TYPE].py3_runtime
12-
uv = ctx.toolchains[UV_TOOLCHAIN]
13-
10+
py_toolchain = ctx.toolchains[PY_TOOLCHAIN].py3_runtime
11+
unpack_toolchain = ctx.toolchains[UNPACK_TOOLCHAIN]
1412
install_dir = ctx.actions.declare_directory(
1513
"install",
1614
)
@@ -24,25 +22,28 @@ def _whl_install(ctx):
2422
#
2523
# Could probably use bsdtar here rather than non-hermetic unzip.
2624

25+
2726
# FIXME: Need the Python toolchain here?
2827
archive = ctx.attr.src[DefaultInfo].files.to_list()[0]
28+
29+
arguments = ctx.actions.args()
30+
arguments.add_all([
31+
"--into",
32+
install_dir.path,
33+
"--wheel",
34+
archive.path,
35+
"--python-version",
36+
"{}.{}.{}".format(
37+
py_toolchain.interpreter_version_info.major,
38+
py_toolchain.interpreter_version_info.minor,
39+
py_toolchain.interpreter_version_info.micro,
40+
),
41+
])
42+
2943
ctx.actions.run(
30-
executable = uv.executable,
31-
arguments = [
32-
"pip",
33-
"install",
34-
"--no-deps",
35-
# FIXME: What happens when this is a TreeArtifact?
36-
"--prefix",
37-
install_dir.path,
38-
"--python",
39-
py_toolchain.interpreter.path,
40-
archive.path,
41-
],
42-
inputs = [
43-
archive,
44-
uv.executable,
45-
] + py_toolchain.files.to_list(),
44+
executable = unpack_toolchain.bin.bin,
45+
arguments = [arguments],
46+
inputs = [archive],
4647
outputs = [
4748
install_dir,
4849
],
@@ -83,8 +84,8 @@ whl_install = rule(
8384
"src": attr.label(doc = ""),
8485
},
8586
toolchains = [
86-
PYTHON_TOOLCHAIN_TYPE,
87-
UV_TOOLCHAIN,
87+
PY_TOOLCHAIN,
88+
UNPACK_TOOLCHAIN,
8889
],
8990
provides = [
9091
DefaultInfo,

0 commit comments

Comments
 (0)