uv/crates/install-wheel-rs
Charlie Marsh e811070ef1
Wrap unsafe script shebangs in /bin/sh (#2097)
## Summary

This is based on Pradyun's installer branch
(d01624e5f2/src/installer/scripts.py (L54)),
which is itself based on pip
(0ad4c94be7/src/pip/_vendor/distlib/scripts.py (L136)).

The gist of it is: on Posix platforms, if a path contains a space (or is
too long), we wrap the shebang in a `/bin/sh` invocation.

Closes https://github.com/astral-sh/uv/issues/2076.

## Test Plan

```
❯ cargo run venv "foo"
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/uv venv foo`
Using Python 3.12.0 interpreter at: /Users/crmarsh/.local/share/rtx/installs/python/3.12.0/bin/python3
Creating virtualenv at: foo
Activate with: source foo/bin/activate

❯ source "foo bar/bin/activate"

❯ which black
black not found

❯ cargo run pip install black
Resolved 6 packages in 177ms
Installed 6 packages in 17ms
 + black==24.2.0
 + click==8.1.7
 + mypy-extensions==1.0.0
 + packaging==23.2
 + pathspec==0.12.1
 + platformdirs==4.2.0

❯ which black
/Users/crmarsh/workspace/uv/foo bar/bin/black

❯ black
Usage: black [OPTIONS] SRC ...

One of 'SRC' or 'code' is required.

❯ cat "foo bar/bin/black"
#!/bin/sh
'''exec' '/Users/crmarsh/workspace/uv/foo bar/bin/python' "$0" "$@"
' '''
# -*- coding: utf-8 -*-
import re
import sys
from black import patched_main
if __name__ == "__main__":
    sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
    sys.exit(patched_main())
```
2024-02-29 23:19:06 +00:00
..
src Wrap unsafe script shebangs in /bin/sh (#2097) 2024-02-29 23:19:06 +00:00
Cargo.toml Add a --python flag to allow installation into arbitrary Python interpreters (#2000) 2024-02-28 02:10:29 +00:00
Readme.md Copy over install-wheel-rs crate (#33) 2023-10-06 21:38:38 -04:00

Reimplementation of wheel installing in rust. Supports both classical venvs and monotrail.

There are simple python bindings:

from install_wheel_rs import LockedVenv

locked_venv = LockedVenv("path/to/.venv")
locked_venv.install_wheel("path/to/some_tagged_wheel.whl")

and there's only one function: install_wheels_venv(wheels: List[str], venv: str), where wheels is a list of paths to wheel files and venv is the location of the venv to install the packages in.

See monotrail for benchmarks.