Skip to content

Instantly share code, notes, and snippets.

@kasteph
Last active February 11, 2021 16:52
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasteph/5626db636fbd37967a9d25fd2bf7dcbf to your computer and use it in GitHub Desktop.
Save kasteph/5626db636fbd37967a9d25fd2bf7dcbf to your computer and use it in GitHub Desktop.
PyCon Berlin 2019: Poetry Workshop

Package and Dependency Management with Poetry

The Poetry repository can be found here and the website here.

For documentation on the pyproject.toml file specific to Poetry, go here.

The goal of this workshop is to have a pyproject.toml that poetry can use to build your package to a distribution and then publish it to a private repository.

Installation

Run the following command to install Poetry on to your machine. Don't worry, this won't pollute your system's environment since poetry vendorizes its dependencies.

curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python

Tutorial

There are several ways we can go about this tutorial and it is up to you how you want to go through it.

1 / Writing a pyproject.toml

Docs

  • If you are already a library author using anything other than poetry to build and publish your package, you can take your current configuration files and translate it to a pyproject.toml.

  • Similar to the above, you can take an existing Python project (for example, python-datamuse) and using the current configuration files of that project, translate it to a pyproject.toml.

  • You can create a new Python project using Poetry using poetry new <awesome_package_name> and fill out the generated pyproject.toml file as we go along.

2 / Building Distributions

Docs

To build your Python package, run poetry build [-f|--format] (wheel|sdist). Specify the format only if you want one or the other format.

3 / Publishing

Docs

We must first add the remote repository to the list of repositories that poetry can publish to.

poetry config repositories.workshop http://10.66.5.80:8080/

To publish to the remote repository:

poetry publish -r workshop -u <some_username> -p <some_password>

If no arguments are passed to the publish command, it will use PyPI as the default repository to publish to.

Good Examples

Some repositories that are good examples of how to use poetry are:

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