fix(poetry): make psh and psync work with Poetry 2 (#14283)

This commit is contained in:
Srinivas Chippagiri authored and GitHub committed 2026-11-24 11:37:22 -08:00
1 parent 27506acc8a
commit f68e5ec392
2 files changed
+21 -4

No files matched your search

+2 -2
View File
@@ -28,11 +28,11 @@ plugins=(... poetry)
| prm | `poetry remove` | Remove packages from `pyproject.toml` and uninstall them |
| prun | `poetry run` | Executes the given command inside the project’s virtualenv |
| psad | `poetry self add` | Add the Poetry plugin and install dependencies to make it work |
| psh | `poetry shell` | Spawns a shell within the virtual environment. If one doesn’t exist, it will be created |
| psh | `poetry shell` | Spawns a shell within the virtual environment. With Poetry 2.0+ and no shell plugin, activates it with `poetry env activate` |
| pshw | `poetry show` | List all the available dependencies |
| pslt | `poetry show --latest` | List latest version of the dependencies |
| psup | `poetry self update` | Update Poetry to the latest version (default) or to the specified version |
| psync | `poetry install --sync` | Synchronize your environment with the `poetry.lock` |
| psync | `poetry sync` | Synchronize your environment with the `poetry.lock` (`poetry install --sync` before Poetry 2.0) |
| ptree | `poetry show --tree` | List the dependencies as tree |
| pup | `poetry update` | Get the latest versions of the dependencies and to update the `poetry.lock` |
| pvinf | `poetry env info` | Get basic information about the currently activated virtualenv |
+19 -2
View File
@@ -14,11 +14,9 @@ alias ppub='poetry publish'
alias prm='poetry remove'
alias prun='poetry run'
alias psad='poetry self add'
alias psh='poetry shell'
alias pshw='poetry show'
alias pslt='poetry show --latest'
alias psup='poetry self update'
alias psync='poetry install --sync'
alias ptree='poetry show --tree'
alias pup='poetry update'
alias pvinf='poetry env info'
@@ -26,6 +24,25 @@ alias pvoff='poetry config virtualenvs.create false'
alias pvrm='poetry env remove'
alias pvu='poetry env use'
# Poetry 2.0 moved `poetry shell` to the poetry-plugin-shell plugin, so fall
# back to activating the virtualenv in the current shell when it's missing.
function psh {
if poetry shell --help &>/dev/null; then
poetry shell "$@"
else
eval "$(poetry env activate)"
fi
}
# Poetry 2.0 replaced `poetry install --sync` with `poetry sync`.
function psync {
if poetry sync --help &>/dev/null; then
poetry sync "$@"
else
poetry install --sync "$@"
fi
}
# Return immediately if poetry is not found
if (( ! $+commands[poetry] )); then
return