Execute pipeline stages and steps
Project description
Staging
About
Automate your commands - be it for environment setup or in CI/CD pipeline. Parallelize execution, and make it easier to handle dependent commands.
Requirements
This package requires tomlkit and dataclass-wizard packages.
Usage
Full description
Staging is configurable in pyproject.toml file and is accessible through CLI interface.
In order to use staging, you have to define steps and then stages. Stages are built from steps.
Let's see example below (which uses all available options):
[tool.staging.steps]
# Test
get_test_packages = {execute = "command to get test packages", output="test_packages"}
coverage = { prepare = "coverage run -m pytest -xv {packages}", execute = "coverage report {flags}", cleanup = "coverage erase", output = "coverage_result", format = {flags = "flags", packages= "test_packages"} }
# Lint
clean = {execute = "command to execute", success_codes=[0,1,2,3,4,5]}
isort = { execute = "isort {flags} . tests", format = {flags = "flags"}}
black = { execute = "black {flags} . tests", format = {flags = "flags"}}
pylint = { execute = "pylint {package} tests", format = {package = "package"}}
noprint = { execute = "noprint -ve {package} tests", format = {package = "package"}, error_codes=[1,2]}
finish = { execute = "finishing command" }
[tool.staging.stages.format]
description = "Format code"
format = {package="staging"}
steps = [
{step = "isort"},
{step = "black"},
]
[tool.staging.stages.lint]
description = "Check linting"
format = {flags="--check", package="staging"}
steps = [
{step = "clean", continue_on_failure=true},
{parallel = {steps = ["isort", "black", "pylint", "noprint"]}, continue_on_failure=true},
{step = "finish"},
]
[tool.staging.stages.test]
description = "Test the package"
format = {flags="-m --fail-under=30"}
steps = [
{step = "get_test_packages"},
{step = "coverage"},
]
Here we have defined 7 different steps: get_test_packages, coverage, clean, and so on.
These 7 steps are later used in 3 stages: test, lint, and format.
Let's say we execute staging format. What happens?
- Stage context is updated with formatter {key=
package, value=staging}. - Step
isortis executed. Commandisort {flags} . testsis formatted using stage formatter. Since flags is empty, the final command is simplyisort . tests. - Step
blackis executed. This works the same asisortabove.
Now let's say we execute staging lint.
- Context has formatter for value
package, but also forflags. - Step
cleanis executed. It might fail, but we don't care and instead the process is continued. - Steps
isort,black,pylintandnoprintare all executed in a thread pool due to being specified in aparallelblock. This time however, even though some of the steps are the same as in thestaging format, we now have aflagsformatter defined. Thanks to this, we now have executedisort --check . testscommand that would verify if the formatting was properly applied. Due to how steps are configured - specified custom success and error codes - the parallel block would fail (one command will crash others). However, the parallel block allows to specifycontinue_on_erroras well, just like step block. - As such,
finishblock is also executed.
Last but not least, staging test.
- Similarly to previous stages, we set up the stage formatter context.
- Step
get_test_packagesoutputs a package name to stdout. This value will be saved undertest_packageskey in the staging context. - Step
coveragehas a bit of a different structure, it hasprepareandcleanupblocks on top of typicalexecute. Prepare is executed beforeexecute. However, it's not taken into account when writing to output. Moreover, it will always fail when status code is different to 0. Block calledcleanupis just like what it says it is. It's a cleanup process executed afterexecute. It will be executed no matter what is the final status of theexecutecommand.
You can also chain your stages in one command. Keep in mind however that formatting contexts are defined on per stage basis.
So if you execute staging format lint - formatting context from stage format won't be propagated to stage lint.
Running stages in one execution is also performed in serial manner - no parallelism.
Example
For real-life examples, see pyproject.toml file for this package.
Development
Installation
Install virtual environment and check_bump package in editable mode with dev dependencies.
python -m venv venv
source venv/bin/activate
pip install -e .[dev]
How to?
Automate as much as we can, see configuration in pyproject.toml file to see what are the flags used.
staging format # Reformat the code
staging lint # Check for linting issues
staging test # Run unit tests and coverage report
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file staging-0.0.3.tar.gz.
File metadata
- Download URL: staging-0.0.3.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc7ad4894140ad970b6c9d31e8a21f4f2a97db6d1f8bb53ab4b1baaa1939fbba
|
|
| MD5 |
2790f7befcd6d5315e3d4a368514211b
|
|
| BLAKE2b-256 |
2c938356291e76c3b0797f48837c5f1cea1e2aa53d7dc109c8bfcfdef1f7cc2a
|
File details
Details for the file staging-0.0.3-py3-none-any.whl.
File metadata
- Download URL: staging-0.0.3-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3a816c1f17918394f951c3b1f5bbd842f028cc70678d783c69b6ce72d83daa9
|
|
| MD5 |
f871a7ea872ac55cc7f6fcffe2b16a8f
|
|
| BLAKE2b-256 |
87842051bdb66c8e0d0035924f203cdaa653de29f8218b509521c3f603498113
|