WRITELOOP

NOTES ON POETRY

2022 May 5
  • Poetry is useful for dependency management AND packaging.

  • MUST be installed through curl. Any other way may cause problems on the future.

  • Create a new python package: poetry new [name]. It generates a project skeleton.

  • You can use poetry for development, and pip for production.

  • poetry init -n only generates pyproject.toml.

  • poetry install installs the project dependencies into a new virtualenv and generates poetry.lock. By default it installs the development libraries. For production, you must install as you install your packages normally (e.g. with pipx or as a dependency for other project).

  • poetry show --tree : shows all dependencies.

  • install a new dependency: poetry add [name]

  • install a new dev dependency: poetry add --dev [name]

  • remove a dependency: poetry remove [name]

  • remove a dev dependency: poetry remove --dev [name]

  • How to define as a script to be run:

[tool.poetry.scripts]
bagulho-cli = 'bagulho.cli:cli'  # package.script:main_function
  • generate the package and wheel: poetry build

  • publicar no PyPI: poetry publish

  • open a shell (to run pytest, your script, etc…): poetry shell

  • update dependencies: poetry update

  • update poetry: poetry self update

  • generate a requirements file (only the prod, not dev ddependencies): poetry export

  • If you need virtualenv cache (e.g. on CI pipelines), it will be a little hard to do that with poetry.

  • You can point another PyPi-like packages repository to poetry.

NOTE: The original content(s) that inspired this one can be found at:
https://www.youtube.com/watch?v=ZOSWdktsKf0
https://github.com/dunossauro/live-de-python/tree/main/codigo/Live179
All copyright and intellectual property of each one belongs to its' original author.