Created
April 13, 2019 15:48
-
-
Save ulope/244eb62b52c59547500fb967c464107b to your computer and use it in GitHub Desktop.
Poetry Python version wrapper (ZSH)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This helps run a globally installed poetry with specific versions of python. | |
# When run from inside a poetry project the correct version is automatically | |
# picked up from pyproject.toml. | |
# Outside of a project (e.g. `poetry new`) a specific version can be chosen by | |
# setting a `PYTHON` env variable. | |
# e.g.: | |
# | |
# PYTHON=3.7 poetry new someproject | |
poetry() { | |
if [[ -f pyproject.toml ]]; then | |
PYVER=$(grep -E '^python =' pyproject.toml | sed -E 's/^python = "\^([0-9].[0-9])"/\1/') | |
python${PYVER} $(whence -p poetry) "$@" | |
else | |
if [[ -v PYTHON ]]; then | |
python${PYTHON} $(whence -p poetry) "$@" | |
else | |
$(whence -p poetry) "$@" | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!