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

Support --unsafe-package in uv pip compile #1415

Closed
hauntsaninja opened this issue Feb 16, 2024 · 12 comments · Fixed by #1889
Closed

Support --unsafe-package in uv pip compile #1415

hauntsaninja opened this issue Feb 16, 2024 · 12 comments · Fixed by #1889
Assignees
Labels
compatibility Compatibility with a specification or another tool enhancement New feature or improvement to existing functionality

Comments

@hauntsaninja
Copy link
Contributor

pip-compile has this flag that's a useful escape hatch. There's some software we use where we care about the specific build. We don't want the build from the index and we don't want it in our lock file, we want to manually manage how it gets installed.

@charliermarsh charliermarsh added enhancement New feature or improvement to existing functionality compatibility Compatibility with a specification or another tool labels Feb 16, 2024
@kummerer94
Copy link

Strong +1 for this feature.

To add another usecase: If you develop on Windows and run uv pip compile ..., you will sometimes have dependencies in your output file that are only necessary for Windows (like pywin32).

Now, I understand that cross compilation is a problem itself (see here) and pip-compile itself does not solve it. But --unsafe-package gets you very far without having to go through the hassle of creating different requirements.in files.

@zanieb
Copy link
Member

zanieb commented Feb 19, 2024

Can you share a bit more about the workflow for this?

@hauntsaninja
Copy link
Contributor Author

hauntsaninja commented Feb 19, 2024

Sure! So one of the packages for which we care about the specific build is torch. Now we have some service that's a Python package that has torch in its dependencies. We run something that basically boils down to something like pip-compile package/pyproject.toml --unsafe-package torch --generate-hashes -o requirements.txt to produce a lock file that does not contain torch. When building the deployment, we pip install --no-deps -r requirements.txt and then do some custom thing to install the specific build of torch we want for that deployment.

This is not a critical feature in that we could be unblocked by writing a wrapper script that parses requirements.txt and removes the packages we don't want from it, but it is something pip-compile currently supports

(This is a thing that maybe sounds like it could be solved by using a custom index or maybe by using URL requirements, but neither of those really works for us in practice)

@hmc-cs-mdrissi
Copy link

hmc-cs-mdrissi commented Feb 20, 2024

I originally contributed unsafe-package to pip-compile mostly as an escape hatch. My main use case was handing multiple editable installs. I work in monorepo with several libraries. My requirements.in looks like this,

-e file:lib1/
-e file:lib2/
...

and I pip compile that with pip-compile requirements.in --unsafe-package lib1 --unsafe-package lib2. This allows resolving dependencies of repository with hashes but without editable requirements. Afterwards we then do pip install --no-dependencies requirements.txt && pip install --no-dependencies requirements.in.

pip requirements.txt does not support a dependency with hashes + editable dependency in same file. This is open issue. For my specific usage if requirements.txt file could support both hashed non-editable dependencies and editable dependencies together then I probably wouldn't use it. The feature was made as broader escape hatch though mostly because it was easier. pip-compile already had a few packages marked unsafe by default (setuptools/pip), so extending that logic to user custom unsafe was straight forward.

edit: Name unsafe only comes from it being based on default unsafe packages that existed for many years prior. A more obvious name might be --output-exclude-package (or maybe brief --exclude-package). Here exclusion applies only to output requirements file made. The package is still used as normal during resolution time.

@gilfree
Copy link

gilfree commented Feb 21, 2024

If I might add a use case - some packages depend on non-python stuff. For example, cupy depends on cuda. It uses naming scheme like cupy-cuda12x.

We pip compile our requirements, to pinned dependencies of such packages, but as we have multiple cuda versions we work with, we have a later command that checks the cuda version and installs the relevant package.

We want to have the dependencies of these packages to be pinned and be included in the generated requirements package, but we can't have these cuda-versioned packeges there.

Having a flag that says - "omit cupy from the generated file" will be great. (We can solve this by post processing the requirements file, but I think it will be safer to have this explicit)

@charliermarsh
Copy link
Member

I will add.

@charliermarsh
Copy link
Member

I'm tempted to use a different name but...

@charliermarsh
Copy link
Member

If anyone has suggestions, feel free to share, though I reserve the right to just go with --unsafe-package and move on :)

@charliermarsh
Copy link
Member

Actually, I'll likely at least use --unsafe-package for compatibility.

@nathanjmcdougall
Copy link
Contributor

I think --exclude would be a good alias.

charliermarsh added a commit that referenced this issue Feb 23, 2024
## Summary

In uv, we're going to use `--no-emit-package` for this, to convey that
the package will be included in the resolution but not in the output
file. It also mirrors flags like `--emit-index-url`.

We're also including an `--unsafe-package` alias.

Closes #1415.
@msharp9
Copy link

msharp9 commented Sep 20, 2024

I don't see --unsafe-package in the docs: https://docs.astral.sh/uv/reference/cli/#uv-pip-compile. I don't get an error when I include the flag and I see the PR.

@charliermarsh
Copy link
Member

It’s “no-emit-package”.

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 a pull request may close this issue.

8 participants