# Note: This justfile is meant for MetaKernel developer use only.
# Run `just` to list all available recipes.

# Default: list all recipes
default:
    @just --list

# Install for development
install:
    poetry sync --only main,dev
    poetry run pre-commit install

# Clean build artifacts
clean:
    rm -rf build dist
    find . -name "*.pyc" -delete
    find . -name "*.py,cover" -delete

[private]
_setup group:
    poetry sync --only main,{{group}}
    poetry run pip install -q --no-deps -e ./metakernel_python/

[private]
_run-with-cluster *args="":
    bash scripts/start_cluster.sh 3
    poetry run pytest {{args}}
    poetry run ipcluster stop || true

# Run core test suite (no cluster needed)
test *args="":
    just _setup test
    poetry run pytest {{args}}

# Run full test suite with ipcluster and all optional magic dependencies
test-all *args="":
    just _setup test-all
    just _run-with-cluster {{args}}

# Alias for test-all
test-parallel *args="":
    just test-all {{args}}

# Run tests with coverage
cover *args="":
    just _setup coverage
    just _run-with-cluster --cov=metakernel --cov-report=annotate --cov-report=xml --cov-report=term-missing {{args}}

# Build MkDocs HTML docs
docs:
    poetry sync --only main,docs
    poetry run mkdocs build

# Serve MkDocs docs locally
docs-serve:
    poetry sync --only main,docs
    poetry run mkdocs serve

# Regenerate magics/README.md from magic docstrings
help:
    just _setup test
    poetry run python docs/generate_help.py

# Run type checking
typing:
    poetry sync --only main,typing
    poetry run mypy . --install-types --non-interactive

# Run linter
lint:
    just pre-commit ruff-format
    just pre-commit ruff-check
    just pre-commit validate-pyproject
    just pre-commit poetry-check

# Run example notebooks (excludes Calysto Processing and SAS)
run-notebooks:
    bash scripts/run_notebooks.sh

# Run pre-commit hook
pre-commit *args="":
    poetry sync --only main,dev
    poetry run pre-commit run --all-files {{args}}
