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 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 <name> 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.1.tar.gz (4.6 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.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: poetry_run_actions-0.0.1.tar.gz
  • Upload date:
  • Size: 4.6 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.1.tar.gz
Algorithm Hash digest
SHA256 feaac0f91ae7c1ac9f68a2bf60c908334911b286156417ec3e91577cd275524e
MD5 25c9e2c70f485a8f86603607f363b49c
BLAKE2b-256 05ab563191a8982986f020943ad32bd3e0bccb91f9d12795d493eebc5dd7b851

See more details on using hashes here.

Provenance

The following attestation bundles were made for poetry_run_actions-0.0.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for poetry_run_actions-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f6ff6e37182ecf4c89269dd6c2088407365d32b01c9d900d672bb9633407253a
MD5 d2dc42c9e7447ceec98224359cf65b4f
BLAKE2b-256 a0d917877effd288a062de532999ecec5e45e161834da2c72510160380b5cbb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for poetry_run_actions-0.0.1-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