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 flag for check to check requirements.txt #13059

Open
1 task done
danieldulaney opened this issue Oct 29, 2024 · 1 comment
Open
1 task done

Add flag for check to check requirements.txt #13059

danieldulaney opened this issue Oct 29, 2024 · 1 comment
Labels
state: awaiting PR Feature discussed, PR is needed state: needs discussion This needs some more discussion type: feature request Request for a new feature

Comments

@danieldulaney
Copy link

What's the problem this feature will solve?

I want to see if the environment I'm in fully satisfies a given requirements.txt file.

Describe the solution you'd like

Something like pip check -r requirements.txt (analogous to the existing pip install -r requirements.txt).

Alternative Solutions

There aren't a ton of workarounds.

There are a couple of ways to list all packages currently installed (either pip freeze or importlib.metadata), but they don't allow me to easily compare that list against a requirements.txt file.

Additional context

This came up for me while I was integrating some Python code with dependencies into a big C++ library that uses CMake. I want CMake to check if the current environment has all dependencies, and if so, use the current environment. Otherwise, it should create a venv and install dependencies from requirements.txt into that venv. This allows Python-aware devs to use their own environment, while C++-only devs don't have to think about it.

However, I can imagine a lot of other use-cases where it would be useful to check if an environment contains all required dependencies for some project.

Code of Conduct

@danieldulaney danieldulaney added S: needs triage Issues/PRs that need to be triaged type: feature request Request for a new feature labels Oct 29, 2024
@notatallshaw
Copy link
Member

Pip is a volunteer project, so someone would need to submit a PR, but there are some design options to consider.

First, if you want to keep your existing packages pinned the workaround is something like:

  1. pip freeze --quiet > temp-requirements.txt
  2. cat requirements.txt >> temp-requirements.txt
  3. pip install --dry-run -r temp-requirements.txt

But this isn't the same as installing requirements into an existing and seeing if checking if pip check passes or not. There are some things you could do to get it closer, such as replacing the output of pip freeze {package}=={version} with {package}, but this just shows there is a solution, not that a specific install in the existing command would find it.

So from a design point there is a problem with putting this interface on pip check because there are many install options that could change the outcome, so you would need to put most of the install API on the check API. So to me it would make sense for there to be a pip install --check and then you could run pip install --check --dry-run -r requirements.txt.

@notatallshaw notatallshaw added state: needs discussion This needs some more discussion state: awaiting PR Feature discussed, PR is needed and removed S: needs triage Issues/PRs that need to be triaged labels Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: awaiting PR Feature discussed, PR is needed state: needs discussion This needs some more discussion type: feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants