Skip to content

Command Examples

Below are common command definitions. Note that we only provide basic dependencies in the examples.

Some examples that depend on the Python import graph assume the Pygraph plugin is installed and also parametrize the command across modules.

Pair these commands with a space to run them in an isolated environment.

Linting, Formatting, and Type Checking

Pyright Type Checking

[commands.check-types]
exec = "pyright {module.dir}"
deps = [{type = "pygraph", pyimport = "{module.pyimport}"}]
cache = "repo"

Black Formatting

[commands.format]
exec = "black {module.dir}"
deps = ["{module.dir}/**.py"]
cache = "repo"

Flake8 Linting

[commands.lint]
exec = "flake8 {module.dir}"
deps = ["{module.dir}/**.py"]
cache = "repo"

Ruff Formatting and Linting

[commands.format]
exec = "ruff format {module.dir}"
deps = ["{module.dir}/**.py"]
cache = "repo"

[commands.lint]
exec = "ruff check {module.dir}"
deps = [
    "{module.dir}/**.py",
    {type = "command", name = "format"},
]

Locking Environments

Pip Tools

[commands.lock]
exec = "pip-compile > requirements.txt"
deps = ["requirements.in"]
artifacts = ["requirements.txt"]

Poetry

[commands.lock]
exec = "poetry lock"
deps = ["pyproject.toml"]
artifacts = ["poetry.lock"]

Building Documentation

MkDocs

[commands.build-docs]
exec = "mkdocs build"
deps = ["docs/**", "mkdocs.yml"]
artifacts = ["site/**"]

Sphinx

[commands.build-docs]
exec = "cd docs && make html"
deps = ["docs/**"]
artifacts = ["docs/build/**"]

Unit Tests

Pytest

[commands.test]
exec = "pytest {module.dir}"
deps = [{type = "pygraph", pyimport = "{module.pyimport}"}]

Pytest with Coverage

[commands.test]
exec = "pytest {module.dir} --cov-report xml:{module.name}-coverage.xml"
deps = [{type = "pygraph", pyimport = "{module.pyimport}"}]
artifacts = ["{module.name}-coverage.xml"]

Pytest with Django

In settings.py:

import os

# Ensure parallel runs name the DB based on the worker
DATABASES = {
    "default": {
        ...,
        "TEST": {
            "NAME": f"test_db_name_{os.environ.get('QIK__WORKER')}"
        }
    }
}
[plugins]
pygraph = "qik.pygraph"

[commands.test]
exec = "pytest {module.dir}"
deps = [{type = "pygraph", pyimport = "{module.pyimport}"}]

Generating API Clients

Orval

[commands.generate-api-client]
exec = "python manage.py generate_openapi_spec > openapi.json && npm run orval"
deps = ["backend/**/api/**.py"]
cache = "repo"

Database Schemas

Cache Migrated Django Postgres Database

[commands.migrate-db]
exec = "python manage.py migrate && pg_dump db_name > dump.sql"
deps = ["requirements.txt", "**/migrations/**.py"]
cache = "repo"