Skip to main content

A Poetry plugin that makes it possible to use relative package includes.

Project description

Poetry Multiproject Plugin

This is a Python Poetry plugin, adding the build-project and check-project commands.

CircleCI

The build-project command will make it possible to use relative package includes. This feature is very useful for monorepos and when sharing code between projects.

The check-project command is useful to check that dependencies are added properly in a project. It uses the MyPy tool under the hood, and will output any errors from the static type checker.

Usage

Navigate to the project folder (where the pyproject.toml file is).

Build a project:

poetry build-project

Check the code used in a project:

poetry check-project

Check the code, with a custom MyPy configuration to override the defaults:

poetry check-project --config-file <PATH-TO-MYPY.INI-CONFIG-FILE>

Installation

This plugin can be installed according to the official Poetry docs.

poetry self add poetry-multiproject-plugin

What does it do?

the poetry build-project command will:

  1. copy the actual project into a temporary folder.
  2. collect relative includes - such as include = "foo/bar", from = "../../shared" - and copy them into the temprary folder.
  3. generate a new pyproject.toml.
  4. run the poetry build command in the temporary folder.
  5. copy the built dist folder (containing the wheel and sdist) into the actual project folder.
  6. remove the temporary folder.

the poetry check-project command will:

  1. copy the actual project into a temporary folder.
  2. collect relative includes - such as include = "foo/bar", from = "../../shared" - and copy them into the temprary folder.
  3. generate a new pyproject.toml.
  4. run poetry install in the temporary folder.
  5. run poetry run mypy in the temporary folder.
  6. remove the temporary folder.

The default setting for the underlying MyPy configuration is:

--explicit-package-bases --namespace-packages --no-error-summary --no-color-output

How is it different from the "poetry build" command?

Poetry does not allow package includes outside of the project root.

# Note the structure of the shared folder: namespace/package

packages = [
    { include = "my_namespace/my_package", from = "../../shared" }
    { include = "my_namespace/my_other_package", from = "../../shared" }
]

This plugin will allow relative package includes. You will now be able to share code between projects.

An suggested Monorepo structure, with the shared code extracted into a separate folder structure:

projects/
  my_app/
    pyproject.toml (including a shared package)

  my_service/
    pyproject.toml (including other shared packages)

shared/
  my_namespace/
    my_package/
      __init__.py
      code.py

    my_other_package/
      __init__.py
      code.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

poetry_multiproject_plugin-1.1.4.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

poetry_multiproject_plugin-1.1.4-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file poetry_multiproject_plugin-1.1.4.tar.gz.

File metadata

File hashes

Hashes for poetry_multiproject_plugin-1.1.4.tar.gz
Algorithm Hash digest
SHA256 ccd8ba3ad7a9b69964948c0bdbcddac970fd01b98a268257efcaecdde28274da
MD5 f16e3dc04b61dd231e2abc643b947665
BLAKE2b-256 9c4c280b97ca999ea7d281b13d2dc37a1e3f0e97c88eb117e845cb07b9adf7f1

See more details on using hashes here.

File details

Details for the file poetry_multiproject_plugin-1.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for poetry_multiproject_plugin-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2075da2196093ce0deb0a399f0beadbbfd24b9c6a7420135edf05e9bc2c07912
MD5 b997c6bbc6cf1b979a061a209505bd9e
BLAKE2b-256 9c05f174e70c4f35685ff6c69959b8ae8b1ee9460d21f924799b40a47e88dc86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page