Skip to main content

Poetry application plugin that runs declarative shell actions before `poetry run <name>` based on the active environment.

Project description

Poetry Run Actions Plugin

A Poetry plugin that runs declarative shell actions immediately before poetry run <name>, gated by the active environment.

Use it to attach side effects (e.g. docker compose up -d redis) to a package or script without baking them into the entry point itself, so the same pyproject.toml can be deployed in production without firing dev-only setup.

Install

Install via Poetry:

poetry self add poetry-run-actions

To uninstall:

poetry self remove poetry-run-actions

Configure

Actions attach to a package declared in [tool.poetry] packages or a script declared in [project.scripts] / [tool.poetry.scripts]. Configure them under separate subtables:

[tool.poetry]
packages = [{include = "api"}, {include = "worker"}]

[project.scripts]
migrate = "myapp.db:migrate"

# Package target: fires on `poetry run python -m api` because `api` is in [tool.poetry] packages
[tool.poetry-run-actions.dev.packages.api]
setup-commands = ["docker compose up -d redis"]
pre-start-commands = ["echo 'starting api'"]

# Script target: fires on `poetry run migrate` because `migrate` is in [project.scripts]
[tool.poetry-run-actions.dev.scripts.migrate]
pre-start-commands = "echo 'about to migrate'"

Each entry under packages.<name> or scripts.<name> can take one of three shapes:

# 1. Shorthand: a single shell command (treated as `pre-start-commands`)
[tool.poetry-run-actions.dev.packages]
worker = "docker compose up -d postgres"

# 2. Shorthand: a list of shell commands (treated as `pre-start-commands`)
[tool.poetry-run-actions.dev.packages]
cli = ["docker compose up -d redis", "docker compose up -d postgres"]

# 3. Full form: a table with `setup-commands` and/or `pre-start-commands`
[tool.poetry-run-actions.dev.packages.api]
setup-commands = ["docker compose up -d redis"]
pre-start-commands = ["echo 'starting api'"]

setup-commands vs. pre-start-commands

Both are optional and accept either a single string or a list of strings. On every matching poetry run python -m <name> (for packages) or poetry run <name> (for scripts) invocation, the plugin runs:

Setup commands should be idempotent and run before the pre-start commands. This can be used to install dependencies. Pre-start commands are for application dependencies, such as Redis.

Environment Selection

The active environment is read from POETRY_ENVIRONMENT, defaulting to dev.

Example:

POETRY_ENVIRONMENT Behavior
unset (default) Looks up tool.poetry-run-actions.dev.{packages,scripts}.<name>
dev Same as default
production Looks up tool.poetry-run-actions.production.{packages,scripts}.<name>
any other value Looks up tool.poetry-run-actions.<value>.{packages,scripts}.<name>

Run Tests

Install development dependencies:

poetry install -E dev

Run tests:

poetry run pytest .

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_run_actions-0.0.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

poetry_run_actions-0.0.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file poetry_run_actions-0.0.2.tar.gz.

File metadata

  • Download URL: poetry_run_actions-0.0.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for poetry_run_actions-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a90cf3d58888c55f29a5e7a8824b6a9c5bd4d670928891193f46fa550ee65e56
MD5 6556420688ee14f3866d913ace38cce8
BLAKE2b-256 7f5de27dc1108daf8151df1439d36f09579d522c8fa1a78136741532d2a1bbc9

See more details on using hashes here.

Provenance

The following attestation bundles were made for poetry_run_actions-0.0.2.tar.gz:

Publisher: publish-to-pypi.yml on julien777z/poetry-run-actions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file poetry_run_actions-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for poetry_run_actions-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7bb08c14a54b5a1f3a7b7a438249e6f4904abf0c19f1a48e2b4606d3af42a1a9
MD5 b23610ce554b0447b00f9dd4efe5b0fb
BLAKE2b-256 465f0cfb531466f2b1b7b97816a85cd10325209a847aa9f7323eddbdbd7800ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for poetry_run_actions-0.0.2-py3-none-any.whl:

Publisher: publish-to-pypi.yml on julien777z/poetry-run-actions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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