-
Notifications
You must be signed in to change notification settings - Fork 18
Poetry Cheat Sheet
The purpose of this doc is to serve as a quick reference for some of the common workflow commands.
Most of the commands below can have -v|vv|vvv
added to them for increased verbosity when running the commands, the number of v
's added specifies the level,
- normal output
- verbose output
- for debug You can find all the juicy details in the official documentation.
poetry install
There are a number of ways you can include, exclude, or otherwise specify dependency groups when installing. Dependency groups are specified in pyproject.toml
with the following section specifier [tool.poetry.group.<desiredGroupName>.dependencies]
.
# Test dependencies only
poetry install --only test
# Exclude test dependencies
poetry install --without test
# Include test dependencies
poetry install --with test
Dependencies can be managed either via the shell or by editing pyproject.toml
directly. When editing pyproject.toml
directly, run poetry check
to validate the pyproject.toml
file before running poetry install
.
boto=="2.49.0"
# Becomes
boto = "2.49.0"
jinja2-cli[yaml]==0.8.2
# becomes
jinja2-cli = { extras = ["yaml"], version = "0.8.2" }
git+https://github.com/mitsuhiko/flask-sqlalchemy.git@500e732dd1b975a56ab06a46bd1a20a21e682262#egg=Flask-SQLAlchemy==2.3.2.dev20190108
# Becomes
Flask-SQLAlchemy = { git = "git+https://github.com/mitsuhiko/flask-sqlalchemy.git", rev = "500e732dd1b975a56ab06a46bd1a20a21e682262"}
git+https://github.com/cds-snc/[email protected]#egg=notifications-utils
# Becomes
notifications-utils = { git = "https://github.com/cds-snc/notifier-utils.git", tag = "50.1.0"}
poetry search <search term>
When adding a dependency and specifying a version, Version constraints can be used.
# Just the dependency name
poetry add pytest-mock-resources
# With a version
poetry add [email protected]
# Specify a dependency group target
poetry add [email protected] --group test
# Specify Extras (multiple can be specified separated by a space)
poetry add [email protected] --extras redis
# From a git url
poetry add git+https://github.com/mitsuhiko/flask-sqlalchemy.git
# From a git url with a revision
poetry add git+https://github.com/mitsuhiko/flask-sqlalchemy.git#500e732dd1b975a56ab06a46bd1a20a21e682262
# Just the dependency name
poetry remove pytest-mock-resources
# Specify a dependency group target
poetry remove [email protected] --group test
When changes are made to the lock file it should be committed along with any other work done.
# Validate the lock file
poetry lock --check
# Freeze the current requirements in the lock file
poetry lock
When pyproject.toml
is updated, either manually or via the CLI, the lock file needs to be refreshed.
poetry lock --no-update
When running poetry install
and the lock file is out of sync, you'll be notified of this.
When we need to package up a project, like notification-utils
, we no longer need to use setup.py
. Project metadata that was previously housed in setup.py
for this purpose is now found in pyproject.toml
:
[tool.poetry]
name = "notifications-utils"
version = "50.1.2"
description = "Shared python code for Notification - Provides logging utils etc."
authors = ["Canadian Digital Service"]
license = "MIT license"
readme = "README.md"
packages = []
# Create a source distribution
poetry build --format sdist
# Create a wheel
poetry build --format wheel
poetry show --tree
This command will list the package's dependencies, as well as which other packages depend on it.
poetry show SQLAlchemy
# Get the info as a tree instead
poetry show SQLAlchemy --tree
poetry show --outdated