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 a --prepend option to the pipx ensurepath command #1451

Merged

Conversation

agriyakhetarpal
Copy link
Contributor

@agriyakhetarpal agriyakhetarpal commented Jun 13, 2024

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

Summary of changes

Closes #1424.

This PR adds an option to pipx ensurepath, i.e., pipx ensurepath --prepend to allow users to prepend pipx-installed applications to the PATH environment variable rather than appending to it. This is disabled and set to False by default; it is only enabled if the user does pipx ensurepath --prepend (or its --force counterparts such as pipx ensurepath --force --prepend or pipx ensurepath --prepend --force). The implementation is through userpath.prepend, which is similar to userpath.append (see https://github.com/ofek/userpath#api).

Test plan

Tested by running

# command(s) to exercise these changes
pipx ensurepath --prepend  # or pipx ensurepath --prepend --force if already in PATH

This modifies my ~/.zshrc file on macOS accordingly:

# Created by `pipx` on 2024-05-20 14:27:49
export PATH="$PATH:/Users/agriyakhetarpal/.local/bin"

# Created by `pipx` on 2024-06-13 14:24:36
export PATH="/Users/agriyakhetarpal/.local/bin:$PATH"

Therefore, the latter entry from these changes has prepended pipx's installation location to PATH. The earlier entry is from an older pipx installation I had that had appended the location. I'm happy to add additional tests in an appropriate place in tests/ as necessary (though I notice that ensurepath doesn't have tests yet), and update the documentation (not sure where a mention of this would be best appropriate to add, though).

agriyakhetarpal added a commit to agriyakhetarpal/pipx that referenced this pull request Jun 13, 2024
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.

Thanks for this contribution. I think a quick note about this in the installation docs would be nice. Else lgtm.

@agriyakhetarpal
Copy link
Contributor Author

Thanks for this contribution. I think a quick note about this in the installation docs would be nice. Else lgtm.

Thanks for the review – addressed in 435173f; I added a note to docs/installation.md, renaming the "Global installation" heading to "Customising your installation" as I felt that it was the best place to mention something related to pipx ensurepath, similar to the --global argument.

docs/installation.md Outdated Show resolved Hide resolved
docs/installation.md Outdated Show resolved Hide resolved
@chrysle
Copy link
Contributor

chrysle commented Jun 18, 2024

Please rebase.

@agriyakhetarpal agriyakhetarpal force-pushed the feat/add-prepend-option-to-ensurepath branch from 6fc30c0 to 6fa587a Compare June 18, 2024 15:19
@agriyakhetarpal
Copy link
Contributor Author

Done, @chrysle

@chrysle chrysle merged commit 786eb99 into pypa:main Jun 19, 2024
11 checks passed
@chrysle
Copy link
Contributor

chrysle commented Jun 19, 2024

Thanks!

@agriyakhetarpal agriyakhetarpal deleted the feat/add-prepend-option-to-ensurepath branch June 19, 2024 07:20
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.

pipx ensurepath appends to PATH. Option to prepend ?
3 participants