Skip to content

Commit f443960

Browse files
authored
Remove one of the dependencies on uv-python (#695)
At first I thought this was the only dep and was excited to drop it, but then I realized we also use it to detect the interpreter. Still, it seems reasonable to avoid parsing an already-parsed version string and this leaves us 1 step closers to trimming the dep. While I was here, I prepped the action for path mapping so we could avoid duplicating it across configs ### Changes are visible to end-users: no ### Test plan existing tests?
1 parent a301fad commit f443960

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

py/private/py_unpacked_wheel.bzl

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,18 @@ def _py_unpacked_wheel_impl(ctx):
1212

1313
unpack_directory = ctx.actions.declare_directory("{}".format(ctx.attr.name))
1414

15-
arguments = ctx.actions.args()
16-
arguments.add_all([
17-
"--into",
18-
unpack_directory.path,
19-
"--wheel",
20-
ctx.file.src.path,
21-
"--python-version",
22-
"{}.{}.{}".format(
23-
py_toolchain.interpreter_version_info.major,
24-
py_toolchain.interpreter_version_info.minor,
25-
py_toolchain.interpreter_version_info.micro,
26-
),
27-
])
15+
args = ctx.actions.args()
16+
args.add_all([unpack_directory], expand_directories = False, before_each = "--into")
17+
args.add("--wheel", ctx.file.src)
18+
args.add("--python-version-major", py_toolchain.interpreter_version_info.major)
19+
args.add("--python-version-minor", py_toolchain.interpreter_version_info.minor)
2820

2921
ctx.actions.run(
3022
outputs = [unpack_directory],
3123
inputs = depset([ctx.file.src], transitive = [py_toolchain.files]),
3224
executable = unpack_toolchain.bin.bin,
33-
arguments = [arguments],
25+
arguments = [args],
26+
execution_requirements = {"supports-path-mapping": "1"},
3427
mnemonic = "PyUnpackedWheel",
3528
progress_message = "Unpacking wheel {}".format(ctx.file.src.basename),
3629
toolchain = UNPACK_TOOLCHAIN,

py/tools/py/src/unpack.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ use std::{
44
str::FromStr,
55
};
66

7-
use miette::{miette, IntoDiagnostic, Result};
8-
9-
pub fn unpack_wheel(version: &str, location: &Path, wheel: &Path) -> Result<()> {
10-
let python_version: uv_python::PythonVersion = version
11-
.parse()
12-
.map_err(|_| miette!("Failed to parse Python version"))?;
7+
use miette::{IntoDiagnostic, Result};
138

9+
pub fn unpack_wheel(version_major: u8, version_minor: u8, location: &Path, wheel: &Path) -> Result<()> {
1410
let wheel_file_reader = fs::File::open(wheel).into_diagnostic()?;
1511

1612
let temp = tempfile::tempdir().into_diagnostic()?;
@@ -21,8 +17,8 @@ pub fn unpack_wheel(version: &str, location: &Path, wheel: &Path) -> Result<()>
2117
.join("lib")
2218
.join(format!(
2319
"python{}.{}",
24-
python_version.major(),
25-
python_version.minor()
20+
version_major,
21+
version_minor,
2622
))
2723
.join("site-packages");
2824

@@ -37,7 +33,7 @@ pub fn unpack_wheel(version: &str, location: &Path, wheel: &Path) -> Result<()>
3733

3834
let layout = uv_install_wheel::Layout {
3935
sys_executable: PathBuf::new(),
40-
python_version: (python_version.major(), python_version.minor()),
36+
python_version: (version_major, version_minor),
4137
// Don't stamp in the path to the interpreter into the generated bins
4238
// as we don't want an absolute path here.
4339
// Perhaps this should be set to just "python" so it picks up the one in the venv path?

py/tools/unpack_bin/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ struct UnpackArgs {
1515
#[arg(long)]
1616
wheel: PathBuf,
1717

18-
/// Python version, eg 3.8.12
19-
/// Must be separated by dots.
18+
/// Python version, eg 3.8.12 => major = 3, minor = 8
2019
#[arg(long)]
21-
python_version: String,
20+
python_version_major: u8,
21+
#[arg(long)]
22+
python_version_minor: u8,
2223
}
2324

2425
fn unpack_cmd_handler(args: UnpackArgs) -> miette::Result<()> {
25-
py::unpack_wheel(&args.python_version, &args.into, &args.wheel)
26+
py::unpack_wheel(args.python_version_major, args.python_version_minor, &args.into, &args.wheel)
2627
}
2728

2829
fn main() -> miette::Result<()> {

0 commit comments

Comments
 (0)