PYTHON := 'python -X dev'

_default:
    @just --list

# {{{ formatting

alias fmt: format

[doc('Reformat all source code')]
format: isort black pyproject justfmt

[doc('Run ruff isort fixes over the source code')]
isort:
    ruff check --fix --select=I src tests
    ruff check --fix --select=RUF022 src tests
    @echo -e "\e[1;32mruff isort clean!\e[0m"

[doc('Run ruff format over the source code')]
black:
    ruff format src tests
    @echo -e "\e[1;32mruff format clean!\e[0m"

[doc('Run pyproject-fmt over the configuration')]
pyproject:
    {{ PYTHON }} -m pyproject_fmt \
        --indent 4 --max-supported-python '3.14' \
        pyproject.toml
    @echo -e "\e[1;32mpyproject clean!\e[0m"

[doc('Run just --fmt over the justfile')]
justfmt:
    just --unstable --fmt
    just -f docs/justfile --unstable --fmt
    @echo -e "\e[1;32mjust --fmt clean!\e[0m"

# }}}
# {{{ linting

[doc('Run all linting checks over the source code')]
lint: ruff clippy mypy

[doc('Run ruff checks over the source code')]
ruff:
    ruff check src tests
    @echo -e "\e[1;32mruff clean!\e[0m"

[doc("Run clippy lint checks")]
clippy:
    cargo clippy --all-targets --all-features
    @echo -e "\e[1;32mclippy clean!\e[0m"

[doc('Run mypy checks over the source code')]
mypy:
    {{ PYTHON }} -m mypy src tests
    @echo -e "\e[1;32mmypy clean!\e[0m"

# }}}
# {{{ pin

[private]
requirements_in:
    #!/usr/bin/env python

    import tomllib

    with open("requirements.in", "w", encoding="utf-8") as outf:
        with open("pyproject.toml", "rb") as pyf:
            config = tomllib.load(pyf)

        outf.write("# This file is autogenerated. Do not modify it!\n\n")
        outf.write("\n".join(config["build-system"]["requires"]))

[private]
requirements_test_txt: requirements_in
    uv pip compile --upgrade --universal --python-version '3.10' \
        --extra test \
        -o requirements-test.txt pyproject.toml requirements.in

[private]
requirements_txt:
    uv pip compile --upgrade --universal --python-version '3.10' \
        -o requirements.txt pyproject.toml

[doc('Pin dependency versions to requirements.txt')]
pin: requirements_txt requirements_test_txt
    cargo update --verbose

# }}}
# {{{ develop

[doc('Install project in editable mode')]
develop:
    @rm -rf build
    @rm -rf dist
    {{ PYTHON }} -m pip install \
        --verbose \
        --no-build-isolation \
        --editable .

[doc("Editable install using pinned dependencies from requirements-test.txt")]
pip-install:
    {{ PYTHON }} -m pip install --requirement requirements-test.txt
    {{ PYTHON }} -m pip install --verbose --no-build-isolation --editable .

[doc("Run pytest tests")]
test *PYTEST_ADDOPTS:
    {{ PYTHON }} -m pytest {{ PYTEST_ADDOPTS }}

[doc("Remove various build artifacts")]
clean:
    rm -rf build dist
    rm -rf target
    rm -rf docs/_build

[doc("Remove various temporary files and caches")]
purge: clean
    rm -rf .ruff_cache .pytest_cache .pytest-cache .mypy_cache tags

[doc("Regenerate ctags")]
ctags:
    ctags --recurse=yes \
        --tag-relative=yes \
        --exclude=.git \
        --exclude=docs \
        --python-kinds=-i \
        --language-force=python

# }}}
