astral-sh / uv

An extremely fast Python package installer and resolver, written in Rust.
https://astral.sh/
Apache License 2.0
11.73k stars 321 forks source link

Add `--target` support to `sync` and `install` #3257

Closed charliermarsh closed 2 weeks ago

charliermarsh commented 2 weeks ago

Summary

The approach taken here is to model --target as an install scheme in which all the directories are just subdirectories of the --target. From there, everything else... just works? Like, upgrade, uninstalls, editables, etc. all "just work".

Closes #1517.

zanieb commented 2 weeks ago

This is different than pip right? Want to note this in the compatibility doc?

charliermarsh commented 2 weeks ago

Hmm, I don't think the user experience actually differs from pip in significant ways, or at least in ways that would work in pip but wouldn't work in uv.

henryiii commented 2 weeks ago

Hmm, I tried this out:

$ cargo run --release --bin uv -- pip install importlib_metadata --target tmpdir
$ ls
bin/                                importlib_metadata-7.1.0.dist-info/ zipp/
importlib_metadata/                 include/                            zipp-3.18.1.dist-info/

This looks close to what I'd expect, though the bin and include (empty) directories were unexpected. I would not expect to be able to import bin or import include :).

At least for the use case of building zipapps, which is what I use --target for, and seems to be a popular usage, you only want platlib/purelib (in the same folder) and don't want data/scripts/headers, which can't be used from a zipapp.

charliermarsh commented 2 weeks ago

Yeah, but if you pip install black --target tmpdir, you will get a tmpdir/bin that contains black and blackd -- this follows pip. We're just creating those directories upfront rather than lazily. Does it have a material impact?

charliermarsh commented 2 weeks ago

At least for the use case of building zipapps, which is what I use --target for, and seems to be a popular usage, you only want platlib/purelib (in the same folder) and don't want data/scripts/headers, which can't be used from a zipapp.

Yes, but pip adds all of these, as far as I can tell? It just adds them to the top-level. If you pip install jupyter --target foo, you will see foo/share which contains a bunch of icons and such for Jupyter.

charliermarsh commented 2 weeks ago

I understand that you don't need these things for a zipapp. What I'm trying to understand is why it's a problem to include them, if it matches pip's behavior.

henryiii commented 2 weeks ago

I think it's just surprising that these were here; I've not bundled a library with scripts or headers in a zipapp before so have never seen them and didn't know pip would stick them there.

charliermarsh commented 2 weeks ago

Perhaps I can change it to create those directories lazily so it's less surprising (since they typically would not be created at all in that case).

charliermarsh commented 2 weeks ago

Okay, https://github.com/astral-sh/uv/pull/3274 should give you something closer to what you're used to :)

henryiii commented 2 weeks ago

Nice, that feels a lot more pip-like. :)

Pixel-Minions commented 2 weeks ago

Works great! Thank you.

mpderbec commented 2 weeks ago

Just tried it out... With --target support, I wouldn't expect to have to create a virtual environment, correct?

(I'm getting this error:)

C:\WINDOWS\system32\cmd.exe /c "uv pip install --target="C:\GitHub\crab\site-packages\x64\prod" -r "C:\GitHub\crab\requirements.prod.txt" "
error: Failed to locate a virtualenv or Conda environment (checked: `VIRTUAL_ENV`, `CONDA_PREFIX`, and `.venv`). Run `uv venv` to create a virtualenv.
charliermarsh commented 2 weeks ago

Mmm, I could see arguments either way given our stance on environments, but probably shouldn't be required, no. You can run with --system in the meantime.

Pixel-Minions commented 2 weeks ago

You can use --python and pass thr path to the interpreter, it works great even with embedded versions of python with no venv

On Sat, Apr 27, 2024, 6:42 p.m. Charlie Marsh @.***> wrote:

Mmm, I could see arguments either way given our stance on environments, but probably shouldn't be required, no. You can run with --system in the meantime.

— Reply to this email directly, view it on GitHub https://github.com/astral-sh/uv/pull/3257#issuecomment-2081220303, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIXWF6KKNYFQXXREELY5CLY7QSVPAVCNFSM6AAAAABGX3QPZOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBRGIZDAMZQGM . You are receiving this because you commented.Message ID: @.***>

mpderbec commented 2 weeks ago

--system works great.

Success story: Our package install time went from 4m27s to 0m8s!