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

Inject additional packages from text file #1252

Merged
merged 52 commits into from
May 14, 2024

Conversation

jamesmyatt
Copy link
Contributor

@jamesmyatt jamesmyatt commented Feb 8, 2024

  • I have added a news fragment under changelog.d/ (if the patch affects the end users)

Summary of changes

Fixes #934. Provides for injecting dependencies from a text (requirements) file.

Replaces #1037, which it's partially based on. Thanks, @dukecat0!

I don't think it's necessary to match the pip functionality when the "runpip" command also exists. Instead it replaces the workaround with xargs:

cat <requirements-file> | sed -e 's/#.*//' | xargs pipx inject <package>

It could be extended to support the full pip-requirements syntax in the future, if necessary, but I'd prefer "good" rather than "perfect".

Test plan

Tested by running unit tests

@jamesmyatt jamesmyatt changed the title Inject requirements Inject dependencies from text file Feb 8, 2024
@jamesmyatt jamesmyatt marked this pull request as ready for review February 8, 2024 11:43
@chrysle chrysle changed the title Inject dependencies from text file Inject dependencies from requirements file Feb 8, 2024
Copy link
Contributor

@chrysle chrysle left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! I'm a bit unsure regarding the naming, though, since "Requirements File" is a reserved term.

src/pipx/main.py Outdated Show resolved Hide resolved
tests/test_inject.py Outdated Show resolved Hide resolved
src/pipx/commands/inject.py Outdated Show resolved Hide resolved
src/pipx/commands/inject.py Show resolved Hide resolved
changelog.d/1252.feature.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Gitznik Gitznik left a comment

Choose a reason for hiding this comment

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

Also flagging that in the original PR by @dukecat0 the decision was made to make the requirements file and passing a requirement directly mutually exclusive.

I personally don't see a technical reason to stick to that, so not a blocker for me.

src/pipx/main.py Outdated Show resolved Hide resolved
src/pipx/commands/inject.py Show resolved Hide resolved
@chrysle chrysle added the awaiting response Awaiting re-engagement by contributor label Feb 10, 2024
@jamesmyatt
Copy link
Contributor Author

Also flagging that in the original PR by @dukecat0 the decision was made to make the requirements file and passing a requirement directly mutually exclusive.

I personally don't see a technical reason to stick to that, so not a blocker for me.

I think that's how pip works, but like you say, I don't see a good technical reason for it. I don't even think it's necessary to match the pip functionality. If you want to match the pip functionality, then runpip is there. My preference here is to be fairly naive and rely on the users to do sensible things.

@jamesmyatt
Copy link
Contributor Author

jamesmyatt commented Feb 12, 2024

Thank you for working on this! I'm a bit unsure regarding the naming, though, since "Requirements File" is a reserved term.

I agree that "Requirements File" is a reserved term and shouldn't be over-used. However, we're using a strict sub-set of the "Requirements File" syntax, won't accept changes that are incompatible and have ambitions to support the full syntax eventually.

edit: To summarise, I think it's better to describe it as "partial pip-requirements-file support" rather than "not a pip-requirements file".

@jamesmyatt
Copy link
Contributor Author

jamesmyatt commented Feb 12, 2024

On the subject of full pip-requirements file support. I wonder if the better long-term implementation would be to change the way that inject works to just create a temporary requirements file from the CLI inputs and then install that using pip (I think this is what conda does with pip requirements). Then pipx would record everything that's listed as requested in the installation report (based on #1037 (comment)).

But I think that needs more investigation (e.g. checking how it works with upgrade --include-injected) and would be a much more significant change to pipx. Hence, my preference is to implement this solution with partial pip-requirements-file support that is probably good enough for 99% of use cases, and investigate a solution for the remaining 1% in slower time.

tests/test_inject.py Outdated Show resolved Hide resolved
tests/test_inject.py Outdated Show resolved Hide resolved
src/pipx/commands/inject.py Show resolved Hide resolved
src/pipx/commands/inject.py Outdated Show resolved Hide resolved
@chrysle
Copy link
Contributor

chrysle commented Feb 13, 2024

But I think that needs more investigation (e.g. checking how it works with upgrade --include-injected) and would be a much more significant change to pipx. Hence, my preference is to implement this solution with partial pip-requirements-file support that is probably good enough for 99% of use cases, and investigate a solution for the remaining 1% in slower time.

This sounds like a good plan to me.

@chrysle chrysle removed the awaiting response Awaiting re-engagement by contributor label Feb 15, 2024
@chrysle chrysle added the awaiting response Awaiting re-engagement by contributor label Mar 14, 2024
@gaborbernat gaborbernat marked this pull request as draft March 25, 2024 17:38
@chrysle
Copy link
Contributor

chrysle commented Apr 22, 2024

@jamesmyatt Gentle ping on this.

@jamesmyatt jamesmyatt force-pushed the inject-requirements branch from 5aaf87a to 99b386e Compare April 22, 2024 20:12
@jamesmyatt jamesmyatt closed this Apr 22, 2024
@jamesmyatt jamesmyatt reopened this Apr 22, 2024
@jamesmyatt
Copy link
Contributor Author

jamesmyatt commented Apr 22, 2024

Thanks for the reminder. I think the outstanding actions are:

  • Fix merge
  • Check docs are clear about relationship to pip-requirements files
  • Add examples to documentation
  • Check log and std outputs in unit tests

Anything else?

@chrysle
Copy link
Contributor

chrysle commented Apr 23, 2024

Anything else?

I don't think so.

@jamesmyatt jamesmyatt force-pushed the inject-requirements branch from 5ca3a40 to f7a1303 Compare April 26, 2024 10:05
tests/test_inject.py Outdated Show resolved Hide resolved
@huxuan
Copy link
Member

huxuan commented May 8, 2024

@chrysle Do you have an idea why the new unit tests are sometimes failing?

isort is one of the dependencies of pylint, so you may need to change the test case.

@chrysle
Copy link
Contributor

chrysle commented May 8, 2024

isort is one of the dependencies of pylint, so you may need to change the test case.

I'd suggest to just drop pylint as a test package in this case.

@jamesmyatt
Copy link
Contributor Author

@chrysle Do you have an idea why the new unit tests are sometimes failing?

isort is one of the dependencies of pylint, so you may need to change the test case.

Ah yes. I wonder why it works sometimes then.

@jamesmyatt
Copy link
Contributor Author

I think this is actually done now

chrysle
chrysle previously approved these changes May 10, 2024
@chrysle
Copy link
Contributor

chrysle commented May 10, 2024

Waiting for @Gitznik's review before merging.

Copy link
Contributor

@Gitznik Gitznik left a comment

Choose a reason for hiding this comment

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

LGTM aside from the news fragment 👍

changelog.d/1252.feature.md Outdated Show resolved Hide resolved
Simplify news fragment
Fix new fragement
Be more explicit about the syntax for the "inject -r" files.
Fix markdown link
@huxuan huxuan merged commit fca8a40 into pypa:main May 14, 2024
14 checks passed
@huxuan
Copy link
Member

huxuan commented May 14, 2024

Great job!

@jamesmyatt jamesmyatt deleted the inject-requirements branch May 15, 2024 09:17
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