Skip to content

Cookbook

Qik CLI examples, common command definitions, and useful snippets.

CLI Examples

Watch Repo-Cached Commands

qik --cache-type repo --watch

Run All Commands Serially

qik -n 1

Check for Warm Cache for Specific Commands

qik command_one command_two --cache-status warm --ls

Fail if Commands have Cold Cache

qik --cache-status cold --ls --fail

Run Commands Since main Branch

qik --since main

Show Output of Successful and Failed Commands

qik -v 2

Cache All Finished Commands

qik --cache-when finished

Set the Default Cache

qik --cache remote_cache_name

Common Command Definitions

Below are common command definitions. Note that we only provide basic dependencies in the examples. We also recommend to:

Linting, Formatting, and Type Checking

Pyright Type Checking

[commands.check-types]
exec = "pyright {module.dir}"
deps = [{type = "module", name = "{module.name}"}]
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 = "module", name = "{module.name}"}]

Pytest with Coverage

[commands.test]
exec = "pytest {module.dir} --cov-report xml:{module.name}-coverage.xml"
deps = [{type = "module", name = "{module.name}"}]
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')}"
        }
    }
}
[commands.test]
exec = "pytest {module.dir}"
deps = [{type = "module", name = "{module.name}"}]

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"