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

have a pdm shell command #2249

Closed
deronnax opened this issue Sep 10, 2023 · 17 comments · Fixed by j178/pdm#1
Closed

have a pdm shell command #2249

deronnax opened this issue Sep 10, 2023 · 17 comments · Fixed by j178/pdm#1
Labels
⭐ enhancement Improvements for existing features

Comments

@deronnax
Copy link
Contributor

deronnax commented Sep 10, 2023

Is your feature request related to a problem? Please describe.

No

Describe the solution you'd like

A pdm shell command, like Pipenv, Poetry and Hatch have. I have seen pdm venv activate but it isn't really the same (plus it does not seem to work).

@deronnax deronnax added the ⭐ enhancement Improvements for existing features label Sep 10, 2023
@pawamoy
Copy link
Contributor

pawamoy commented Sep 10, 2023

Workaround in the meantime, if you install dependencies in __pypackages__:

# pyproject.toml
[tool.pdm.scripts]
shell = {shell = "PATH=$(echo $(pdm info | grep __pypackages__)/bin):$PATH zsh"}
% type ruff
ruff not found
% pdm run shell
% type ruff
ruff is /media/data/dev/griffe/__pypackages__/3.11/bin/ruff

@deronnax
Copy link
Contributor Author

deronnax commented Sep 10, 2023

That looks like a good workaround, thank you. I don't use __pypackage__ but we can probably achieve the same thing with pdm venv activate.

@pawamoy
Copy link
Contributor

pawamoy commented Sep 10, 2023

You're welcome! The following seems to work for venvs:

# pyproject.toml
[tool.pdm.scripts]
shell = {shell = "zsh -c \"eval $(pdm venv activate 3.11); export PATH; export VIRTUAL_ENV; exec zsh\""}

@frostming
Copy link
Collaborator

Why not just pdm run $SHELL

@pawamoy
Copy link
Contributor

pawamoy commented Sep 11, 2023

Oh my. Right. pdm run does that already 👍

@deronnax
Copy link
Contributor Author

hmmm it's not really handy, plus the venv is not activated (it's just put in the path) and it's significant user experience disconcert since all other tools have the shell command, to which most user are used (it's a corner stone of our workflow at my company e.g)
If you don't feel like doing it, I will give a try.

@frostming
Copy link
Collaborator

plus the venv is not activated (it's just put in the path)

activating a venv is basically setting env vars, mainly VIRTUAL_ENV and PATH, plus some corner case handling.

@deronnax
Copy link
Contributor Author

OK. Are you against a pdm shell command? (If yes I will close the issue)

(but I think in few weeks someone will open another issue asking for a pdm shell command).

@Secrus
Copy link

Secrus commented Sep 12, 2023

Coming from Poetry, poetry shell was a mistake that I plan to fight with at some point. It's a pain to maintain it. What pdm does with venv activate is a much better solution in my opinion.

@frostming
Copy link
Collaborator

Coming from Poetry, poetry shell was a mistake that I plan to fight with at some point. It's a pain to maintain it. What pdm does with venv activate is a much better solution in my opinion.

Same story why I abandoned pdm shell

@Secrus
Copy link

Secrus commented Sep 12, 2023

I'd suggest that if someone wants it, it's a great plugin candidate.

@frostming
Copy link
Collaborator

I'd suggest that if someone wants it, it's a great plugin candidate.

There's already one pdm-shell

@pawamoy
Copy link
Contributor

pawamoy commented Sep 12, 2023

For reference: https://github.com/abersheeran/pdm-shell

@deronnax
Copy link
Contributor Author

I ran into it. No install instructions on the readme, last commit in Nov 2022, 1 man project, it would look the same if it was abandoned. It cannot be considered in a enterprise-grade environment.

@frostming
Copy link
Collaborator

Okay, it seems the plugin doesn't spawn a new shell either.

However, the conclusion remains the same, we are not going to add this command, as it can be achieved in many ways:

  1. pdm run $SHELL
  2. Add a shell function in your .bashrc that runs eval $(pdm venv active)

The docs will be updated accordingly

@frostming
Copy link
Collaborator

frostming commented Sep 13, 2023

For reference, this is a bash/zsh function that you can copy and paste it into your rc file:

pdm() {                                                                                                                            
    local command=$1

    if [[ "$command" == "shell" ]]; then 
        eval $(pdm venv activate)
    else 
        command pdm $@
    fi
}

After restarting your shell you are able to run pdm shell

@deronnax
Copy link
Contributor Author

Ah, I did not know it was something willingly removed. I thought it was just never implemented. OK then, I can understand. Thank you for the suggested alternatives.

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

Successfully merging a pull request may close this issue.

4 participants