Poetry

Page content

Intro

Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Install OpenBSD

… and update path

pip install --user poetry

cat <<'EOF'>> ~/.profile

# Poetry
export PATH=$PATH:~/.local/bin
EOF

. ~/.profile

ev install as root ?

doas pip install --user poetry

cat <<'EOF'>> ~/.profile

# Poetry
export PATH=$PATH:/root/.local/bin
EOF

. ~/.profile

Install Debian

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

Basic Usage

$ poetry --version
Poetry version 1.1.11

$ poetry self update
You are using the latest version

$ poetry self update --preview
Updating to 1.2.0a2

  RuntimeError

  Could not find poetry-1.2.0a2-linux.sha256sum file

  at ~/.poetry/lib/poetry/console/commands/self/update.py:260 in _update
      256│         try:
      257│             r = urlopen(base_url + "/{}/{}".format(version, checksum))
      258│         except HTTPError as e:
      259│             if e.code == 404:
    → 260│                 raise RuntimeError("Could not find {} file".format(checksum))
      261│ 
      262│             raise
      263│ 
      264│         checksum = r.read().decode().strip()

# Downgrade
$ poetry self update 0.8.0

poetry new

$ poetry new poetry-demo
Created package poetry_demo in poetry-demo

$ tree poetry-demo/
poetry-demo/
├── poetry_demo
│   └── __init__.py
├── pyproject.toml
├── README.rst
└── tests
    ├── __init__.py
    └── test_poetry_demo.py

2 directories, 5 files

or if you have an existing project, you can do the poetry init

poetry init

$ poetry init

This command will guide you through creating your pyproject.toml config.

Package name [test]:  
Version [0.1.0]:  
Description []:  just a little test
Author [None, n to skip]:  That's Me
License []:  
Compatible Python versions [^3.9]:  

Would you like to define your main dependencies interactively? (yes/no) [yes] 
You can specify a package in the following forms:
  - A single name (requests)
  - A name and a constraint (requests@^2.23.0)
  - A git url (git+https://github.com/python-poetry/poetry.git)
  - A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
  - A file path (../my-package/my-package.whl)
  - A directory (../my-package/)
  - A url (https://example.com/packages/my-package-0.1.0.tar.gz)

Search for package to add (or leave blank to continue): 

Would you like to define your development dependencies interactively? (yes/no) [yes] 
Search for package to add (or leave blank to continue): 

Generated file

[tool.poetry]
name = "test"
version = "0.1.0"
description = "just a little test"
authors = ["That's Me"]

[tool.poetry.dependencies]
python = "^3.9"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"


Do you confirm generation? (yes/no) [yes] 

poetry add

$ poetry add pendulum
Creating virtualenv test-nWsx-QRW-py3.9 in /home/stoege/.cache/pypoetry/virtualenvs
Using version ^2.1.2 for pendulum

Updating dependencies
Resolving dependencies... (0.5s)

Writing lock file

Package operations: 4 installs, 0 updates, 0 removals

  • Installing six (1.16.0)
  • Installing python-dateutil (2.8.2)
  • Installing pytzdata (2020.1)
  • Installing pendulum (2.1.2)

poetry show tree

$ poetry show --tree
pendulum 2.1.2 Python datetimes made easy
├── python-dateutil >=2.6,<3.0
│   └── six >=1.5 
└── pytzdata >=2020.1

poetry show –latest

$ poetry show --latest
pendulum        2.1.2  2.1.2  Python datetimes made easy
python-dateutil 2.8.2  2.8.2  Extensions to the standard Python datetime module
pytzdata        2020.1 2020.1 The Olson timezone database for Python.
six             1.16.0 1.16.0 Python 2 and 3 compatibility utilities

poetry build

$ poetry build
Building test (0.1.0)

  ModuleOrPackageNotFound

  No file/folder found for package test

  at ~/.poetry/lib/poetry/_vendor/py3.9/poetry/core/masonry/utils/module.py:63 in __init__
       59│                             "from": str(src.relative_to(self._path)),
       60│                         }
       61│                     ]
       62│                 else:
    →  63│                     raise ModuleOrPackageNotFound(
       64│                         "No file/folder found for package {}".format(name)
       65│                     )
       66│ 
       67│         for package in packages:

poetry publish

$ poetry publish
No files to publish. Run poetry build first or use the --build option.

sha256: 91992ac4528353bdc8c8a2ad29e9f3a7c3e94a5404b1d1ff066745cd4b3047ff