Skip to main content

Scaffolding

Pyproject.toml

Use poetry init to generate a pyproject.toml if you don't have one already. Run it from the repo root (it won't make a repo folder for you).

Here's a basic package setup for poetry.

[tool.poetry]
name = "..."              # Name of the package
version = "0.1.0"
description = "..."       # A short description
authors = ["Eivind Fonn <evfonn@gmail.com>"]
maintainers = ["Eivind Fonn <evfonn@gmail.com>"]
license = "..."           # I like LGPL-3.0-or-later
readme = "..."            # A filename in the root directory
homepage = "..."          # A githubpages URL or just the github URL
repository = "..."        # The github repo URL
documentation = "..."     # To githubpages if there is one
classifiers = []          # See https://pypi.org/classifiers/
                          # Add a classifier for the license too!
include = [
  "...",                  # Path to a file to include when building
  {                       # Or like this, where format is
    path = "...",         # "sdist" or "wheel" or both
    format = [],
  },
]

# This is the entry point that pip and other tools use.
# This is what invokes poetry to do the building.
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Compiled modules

Adding Cython modules is relatively easy. Add setuptools to build-system.requires, then add this section.

[tool.poetry.build]
generate-setup-file = true
script = "build.py"

Then the build.py file needs to provide for the Cython extension.

from setupools import Extension

from Cython.Build import cythonize

def build(setup_kwargs):
    setup_kwargs['ext_modules'] = cythonize(
        Extension("module", ["source.pyx"])
    )

Basically just update setup_kwargs as if you were using setuptools directly.

Dependencies

Add dependencies from the command line:

poetry add dependency
poetry add --group dev dependency
poetry add --optional -E extra -E extra dependency 

You can also specify that the dependency is required for certain combinations of Python version and/or platform. See poetry documentation for more details.