Skip to content

Instantly share code, notes, and snippets.

@franTarkenton
Last active December 6, 2024 17:31
Show Gist options
  • Select an option

  • Save franTarkenton/6076902ccd58549e90b785b7e270c100 to your computer and use it in GitHub Desktop.

Select an option

Save franTarkenton/6076902ccd58549e90b785b7e270c100 to your computer and use it in GitHub Desktop.
Cheatsheet for Poetry

Background

Global config for poetry is in: ~/.config/pypoetry Local config for poetry, whatever dir... poetry.toml

Configure project to store config locally

Basics

Create new poetry config for a project poetry init

Add a new dependency, in example below requests. poetry add requests

Config

Find out where the virtualenv is located: poetry run which python or poetry env info --path

View / verify config being used by poetry

poetry config --list

Local configs can go into the projects poetry.toml, example:

think that any parameter defined in the config can also be described in this file

[virtualenvs]
create = true
path = '.venv'
in-project = true

Virtualenv Specific

Sometimes you want to have control over where the virtual env is created. For example a docker compose config.

# env vars that will control how poetry behaves
export POETRY_NO_INTERACTION=1
export POETRY_VIRTUALENVS_IN_PROJECT=0
export POETRY_VIRTUALENVS_CREATE=0
export POETRY_CACHE_DIR=/tmp/poetry_cache
export VIRTUAL_ENV=/app/docker_venv

# create the virtual env outside of poetry and activate
python -m venv $VIRTUAL_ENV; . $VIRTUAL_ENV/bin/activate

# install deps into the active virtualenv
poetry install --without dev --no-root -v && rm -rf $POETRY_CACHE_DIR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment