Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --target support to sync and install #3257

Merged
merged 4 commits into from
Apr 25, 2024
Merged

Add --target support to sync and install #3257

merged 4 commits into from
Apr 25, 2024

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Apr 25, 2024

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.

@charliermarsh charliermarsh added enhancement New feature or improvement to existing functionality compatibility Compatibility with a specification or another tool labels Apr 25, 2024
@charliermarsh charliermarsh force-pushed the charlie/target branch 2 times, most recently from 50b2848 to 6b3c5c3 Compare April 25, 2024 00:33
@charliermarsh charliermarsh marked this pull request as ready for review April 25, 2024 02:01
@zanieb
Copy link
Member

zanieb commented Apr 25, 2024

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

@charliermarsh
Copy link
Member Author

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.

@charliermarsh charliermarsh merged commit ed8f6e4 into main Apr 25, 2024
40 checks passed
@charliermarsh charliermarsh deleted the charlie/target branch April 25, 2024 23:15
@henryiii
Copy link
Contributor

henryiii commented Apr 26, 2024

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
Copy link
Member Author

charliermarsh commented Apr 26, 2024

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Member Author

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
Copy link
Member Author

Okay, #3274 should give you something closer to what you're used to :)

@henryiii
Copy link
Contributor

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

charliermarsh added a commit that referenced this pull request Apr 26, 2024
## Summary

Based on feedback in
#3257 (comment).
@Pixel-Minions
Copy link

Works great! Thank you.

@mpderbec
Copy link

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
Copy link
Member Author

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
Copy link

Pixel-Minions commented Apr 27, 2024 via email

@mpderbec
Copy link

mpderbec commented Apr 28, 2024

--system works great.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with a specification or another tool enhancement New feature or improvement to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add -t/--target flag for uv pip install
6 participants