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

Provide ensurepath with a check option or create an init command #1014

Open
mrmeszaros opened this issue Jul 3, 2023 · 8 comments
Open

Provide ensurepath with a check option or create an init command #1014

mrmeszaros opened this issue Jul 3, 2023 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@mrmeszaros
Copy link

mrmeszaros commented Jul 3, 2023

How would this feature be useful?

Currently, pipx ensurepath does not tell me what changes will it make.
I would like to stay in control: see what changes it would make, and then decide if it's okay with me.

Describe the solution you'd like

  • Add a --check or --dry-run option that checks for necessary changes and outputs them.
    > pipx ensurepath --dry-run
    # append lines to ~/.config/fish/config.fish
    fish_add_path ~/.local/bin
    # ... and other configs

Describe alternatives you've considered

  • Add an init command that outputs the shell config changes - similarly to how pyenv does it:
    > pipx init --fish
    # Add this to your config.fish file if You haven't yet
    fish_add_path ~/.local/bin
    # ... other configs - similarly --zsh or --bash or --tcsh

Here is how pyenv does it:

> pyenv init
# Add pyenv executable to PATH by running
# the following interactively:

set -Ux PYENV_ROOT $HOME/.pyenv
set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths

# Load pyenv automatically by appending
# the following to ~/.config/fish/config.fish:

pyenv init - | source


# Restart your shell for the changes to take effect.
@dukecat0 dukecat0 added the enhancement New feature or request label Jul 3, 2023
@uranusjr
Copy link
Member

uranusjr commented Jul 4, 2023

Or --dry-run

@dukecat0
Copy link
Member

Currently it's impossible for pipx to show the content that will be added to the config, since that part of job is done by userpath. I think the only thing we can do here is to show what paths will be added to PATH.

@mrmeszaros
Copy link
Author

Okay, did some digging:

  • in fact pipx relies on the ofek/userpath library to change the PATH env variable
  • the userpath library however does the deed using the ~/.config/fish/config.fish file - manually: set PATH ...-ing
    as can be read at shells.py lines 56-64

AFAIK, userpath does not check whether the path is already on the path - does pipx do the check? I could not find.

What does ensurepath actually do? It's quite cryptic to me.
Does it only add ~/.local/bin to the PATH - or does it do anything else?
If so:

  • Could it check whether it already is (I hope it does).
  • Could it have a verbose mode at least, to say what it is doing? I do not enjoy running mysterious commands.
  • Could it add it's fish config to a ~/.config/fish/conf.d/pipx.fish? That would make unloading it's config much easier.

Sorry for the compounded question / comment, and thanks for Your effort!

@uranusjr
Copy link
Member

https://github.com/pypa/pipx/blob/c3d8de92b1b6c5c6f637ff16f591598fcf98567a/src/pipx/commands/ensure_path.py

I don’t feel the implementation is that difficult to understand. What part is cryptic to you?

@mrmeszaros
Copy link
Author

Thanks - I have read that file - and I think I get what it intends to do (correct me if I'm wrong):

  • it adds (if necessary) two directories:
    • the ~/.local/bin dir or $PIPX_BIN_DIR if it is set.
    • the directory containing the pipx executable

Would it be then possible to add the option to check and log what PATHs need to be added?

Also, is it possible (if ensurepath cannot be changed) to add an init command that works like many other tools (pyenv, pyenv-virtualenv, rbenv, jenv) do?

These would make it possible to investigate what the tools does.

@gaborbernat
Copy link
Contributor

PR welcome.

@gaborbernat gaborbernat added the help wanted Extra attention is needed label Dec 2, 2023
@mrmeszaros
Copy link
Author

@gaborbernat I see that the project uses hatch.
I have installed the tool but was so far unable to create a virtual env where I could run the tests (and nox eg.)

I figured out hatch creates a default env at ~/Library/Application Support/hatch/env/virtual/pipx/iXL76-S_/pipx and that I can open a shell at it, but nox is not installed there.

Could You help out how could I run tests or how to set up the env for contributing?
Also - is there a preferred way to install my local version of pipx to try the new feature?
I would rather not install it globally and possibly break my system.

@Gitznik
Copy link
Contributor

Gitznik commented Feb 1, 2024

Hi @mrmeszaros, please refer to our contributing docs
Let me know if you have any further questions.

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
Development

No branches or pull requests

5 participants