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 for pipx inject <package> -r <requirements-file> #934

Closed
jamesmyatt opened this issue Feb 2, 2023 · 3 comments · Fixed by #1252
Closed

Support for pipx inject <package> -r <requirements-file> #934

jamesmyatt opened this issue Feb 2, 2023 · 3 comments · Fixed by #1252
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jamesmyatt
Copy link
Contributor

jamesmyatt commented Feb 2, 2023

How would this feature be useful?

I'd like to be able to inject packages into a package environment from a standard pip requirements file and have them registered individually as "injected" dependencies, e.g. for list --include-injected and upgrade(-all) --include-injected.

Alternatives listed below all have deficiencies in some way.

This is a different take on #359 and #357 (etc).

Describe the solution you'd like

As mentioned by @funkyfuture in #359 (comment).

pipx inject <package> -r <requirements-file>

Describe alternatives you've considered

The standard solution below is OK, but doesn't register the additional packages as "injected". Hence they're invisible to commands that support --include-injected.

pipx install <package>
pipx runpip <package> install -r <requirements-file>

The following solution by @Sispheor and @hanfried doesn't work on Windows, may miss edge-cases, and is generally clumsy.

cat <requirements-file> | sed -e 's/#.*//' | xargs pipx inject <package>
@dukecat0 dukecat0 added the enhancement New feature or request label Feb 2, 2023
sacundim pushed a commit to sacundim/covid-19-puerto-rico that referenced this issue Jul 16, 2023
…I think pulling these dependencies out of the Dockerfile and into the requirements file is a bit cleaner, it supports e.g. building a venv outside of Docker too. I think ideally pipx should support a requirements file, but that proposal hasn't gotten far:

* pypa/pipx#357
* pypa/pipx#359
* pypa/pipx#934
@gaborbernat gaborbernat added the help wanted Extra attention is needed label Dec 2, 2023
@JamesParrott
Copy link

I was able to just now do:

pipx install nox --pip-args "-r requirements.txt"

Where requirements.txt had the pinned dep I wanted. pipx runpip nox freeze confirmed the specified version was installed.

@jamesmyatt
Copy link
Contributor Author

@JamesParrott . I think that's equivalent to the first alternative I posted above. Can you check with pipx list --include-injected whether the additional dependencies are visible as "injected" packages, please?

@JamesParrott
Copy link

They're not listed as injected - you're right.

jamesmyatt added a commit to jamesmyatt/pipx that referenced this issue Feb 7, 2024
jamesmyatt added a commit to jamesmyatt/pipx that referenced this issue Apr 22, 2024
jamesmyatt added a commit to jamesmyatt/pipx that referenced this issue Apr 26, 2024
jamesmyatt added a commit to jamesmyatt/pipx that referenced this issue May 8, 2024
huxuan added a commit that referenced this issue May 14, 2024
* Naive `pipx inject <package> -r requirements.txt`
Fixes #934

* Fix imports

* Better combination of packages

* Better help text for `inject -r`

* Add unit test

* Add changelog

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename changelog file

* Fix pylint and mypy errors

* Fix default for requirements

* Use assignment operator since Python >= 3.8

* Update src/pipx/commands/inject.py

Co-authored-by: chrysle <[email protected]>

* Update src/pipx/main.py

Co-authored-by: chrysle <[email protected]>

* Update tests/test_inject.py

Co-authored-by: chrysle <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update changelog.d/1252.feature.md

Co-authored-by: chrysle <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update tests/test_inject.py

Add comments to test file

Co-authored-by: chrysle <[email protected]>

* Update test_inject.py

Add a blank line in inject-requirements file

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Logging at INFO level

Also move after exception

* Discard duplicated package specifications

* Update 1252.feature.md

* Update install-all command

* Expand pipx inject example

* Clarify changelog entry

* Mention in main README

* Check stdout and logs in test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Better test for injected packages

* Clarify ignoring of comments in example

Co-authored-by: chrysle <[email protected]>

* Clarify use of "requirement" file

Co-authored-by: chrysle <[email protected]>

* Update README.md

Co-authored-by: chrysle <[email protected]>

* Update README.md

Co-authored-by: chrysle <[email protected]>

* Check can inject each package independently

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix handling of tricky characters

* Use logger where possible

* More messages in logs

* More debugging messages

* Inject additional package that isn't already installed

* Make inject order deterministic

* Fix mypy error

* tidy test_inject_single_package cases

* Better comments on tests

* Update 1252.feature.md

Simplify news fragment

* Update 1252.feature.md

Fix new fragement

* Update examples.md

Be more explicit about the syntax for the "inject -r" files.

* Fix  examples.md

* Update 1252.feature.md

Fix markdown link

* Update 1252.feature.md

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: chrysle <[email protected]>
Co-authored-by: chrysle <[email protected]>
Co-authored-by: Xuan (Sean) Hu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
4 participants