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 --requirement option for pipx inject #1037

Closed
wants to merge 7 commits into from
Closed

Conversation

dukecat0
Copy link
Member

  • I have added an entry to docs/changelog.md

Summary of changes

Add --requirement option for pipx inject.
Close #934

Test plan

Tested by running

pipx inject black -r requirements.txt

@uranusjr
Copy link
Member

Do we want to allow pipx inject foo -r bar.txt? If not maybe we can use add_mutually_exclusive_group (not sure if it can be used grouping arguments and flags together).

@dukecat0
Copy link
Member Author

Do we want to allow pipx inject foo -r bar.txt?

Did you mean something like pipx inject black foo -r bar.txt?

@uranusjr
Copy link
Member

Yes, sorry

@dukecat0
Copy link
Member Author

Probably no then, since I guess most users will choose to edit their requirements files directly.

@dukecat0
Copy link
Member Author

If not maybe we can use add_mutually_exclusive_group (not sure if it can be used grouping arguments and flags together).

Seems like it's impossible to do that currently. I've added a check and it will raise an exception if dependencies and --requirement are passed at the same time.

@uranusjr
Copy link
Member

Probably need to mention this exclusiveness in the flag help string. Otherwise looks good to me.

@dukecat0 dukecat0 marked this pull request as ready for review August 14, 2023 09:20
src/pipx/commands/inject.py Outdated Show resolved Hide resolved
if requirement_files:
packages_list = []
for file in requirement_files:
with open(Path(file), "r") as f:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of reading the files, should we just forward the path to pip to let it parse instead? Requirements files are technically a pip-specific format and parsing them ourselves seems like a big future source of code bloat down the road. Instead we should just redirect all the responsibilities to pip.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the question is that how should we determine package names?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the package names? This is inject not install.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we need to forward those package names to pipx_metadata.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be viable to do a pip freeze before and after installation and record the diff?

This comment was marked as off-topic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it looks like the installation report will also report the dependencies of a package, which are not specified in requirements.txt. Though we can exclude them from pipx_metadata by checking whether they are in the requires_dist field, I personally think this is too complicated

There’s a field requested for this, we can simply filter out entries with this set to true (meaning it’s from user input i.e. the requirements file).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, didn't notice that, thanks for pointing it out!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for the report to include options passed to pip (such as --pre, --index-url) in the requirements file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think either is strictly needed since pipx would install those packages with the exact URL (which the report contains), and the flag is irrelevant in this case.

Copy link
Contributor

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge conflicts need fixed.

@gaborbernat gaborbernat marked this pull request as draft December 2, 2023 05:44
@gaborbernat
Copy link
Contributor

Seems stalled, we can reopen if you pick it up again.

@jamesmyatt
Copy link
Contributor

I've made a new PR #1252 for this, based partially on this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for pipx inject <package> -r <requirements-file>
4 participants