- Poetry lets you easily define and install dependencies
- And resolve dependency issues automatically
- Bonus: Poetry makes it super easy to pusblish libraries to PyPI
pip install poetry
# update poetry to [latest]
poetry self update
# update poetry to [latest-dev]
poetry self update --preview
pyenv install <python_version>
pyenv local <python_version> # go into your project directory and set the local python version
Instead of creating a new project, Poetry can be used to ‘initialise’ a pre-populated directory. To interactively create a pyproject.toml file in directory pre-existing-project:
cd pre-existing-project
poetry init
poetry config virtualenvs.in-project true
pyenv local <python_version>
poetry install
poetry env info # display info where the virtual env is located
poetry env -p # get the path where the virtual env is located
poetry shell
poetry add <package> # install package
poetry remove <package> # remove package
poetry add --group dev black
poetry add --group dev pytest@latest
deactive
exit
rm -fr $pwd/.env
poetry env list --full-path # path that belongs to poetry’s virtual environment (venv).
poetry env info --executable
- Within the project, make a new folder called .vscode.
- Within the folder, make a file called settings.json
- In the file, add the following configuration:
{
"python.pythonPath": "<copied path>"
}
poetry run <script.py>
print -l $fpath | grep '.oh-my-zsh/completions'
poetry completions zsh > $HOME/.antigen/bundles/zsh-users/zsh-completions/_poetry
For oh-my-zsh you must then enable poetry in your ~/.zshrc plugin
antigen bundle poetry
FROM python:3.8
# Metadata
LABEL name="PBG Poetry Example"
LABEL maintainer="PBG"
LABEL version="0.1"
ARG YOUR_ENV="virtualenv"
ENV YOUR_ENV=${YOUR_ENV} \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.1.6 \
LC_ALL=C.UTF-8 \
LANG=C.UTF-8
# System deps:
RUN DEBIAN_FRONTEND=noninteractive apt update && apt install -y libpq-dev gcc
# Install poetry
RUN pip install "poetry==$POETRY_VERSION"
# Copy only requirements to cache them in docker layer
WORKDIR /app
#Copy all the project files
COPY . .
# Install libraries
RUN poetry config virtualenvs.create false \
&& poetry install $(test "$YOUR_ENV" = production) --no-dev --no-interaction --no-ansi
# Set the launching script exec
RUN chmod +x launch.sh
# Launch the script for cron
CMD ["bash", "launch.sh"]
# Launch main python script
# CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "core.app:app"]