set dotenv-load

_default:
  @ just --list --unsorted


# -----------------------------------------------------------------------------
# Refactor Arena
# -----------------------------------------------------------------------------
# Run a scenario
[group: 'Setting']
run scenario *args:
  refactor-arena --config scenarios/{{scenario}}.yaml {{args}}

# Run a scenario in honest mode
[group: 'Setting']
run-honest scenario *args:
  refactor-arena --config scenarios/{{scenario}}.yaml --eval-mode honest {{args}}

# Run a scenario in attack mode
[group: 'Setting']
run-attack scenario *args:
  refactor-arena --config scenarios/{{scenario}}.yaml --eval-mode attack {{args}}


# -----------------------------------------------------------------------------
# Virtual Environment
# -----------------------------------------------------------------------------
# Initialize the virtual environment
[group: 'Virtual Environment']
init:
  uv venv --python 3.12 .venv

# Install the package in editable mode
[group: 'Virtual Environment']
install:
  uv sync --no-default-groups

# Install the package in editable mode with all optional dependencies
[group: 'Virtual Environment']
install-all:
  uv sync --all-groups

# Sync core dependencies from the lockfile
[group: 'Virtual Environment']
sync:
  uv sync

# Sync all dependencies from the lockfile
[group: 'Virtual Environment']
sync-all:
  uv sync --all-groups


# -----------------------------------------------------------------------------
# Dependency Management
# -----------------------------------------------------------------------------
# Add dependency
[group: 'Dependencies']
add target *args:
  uv add {{target}} {{args}}

# Update dependency within pyproject.toml constraints
[group: 'Dependencies']
update target *args:
  uv lock --upgrade-package {{target}} {{args}} && uv sync

# Upgrade dependency to latest version, updating pyproject.toml constraints
[group: 'Dependencies']
upgrade target *args:
  uv remove {{target}} {{args}} && uv add --upgrade {{target}} {{args}}

# Remove dependency
[group: 'Dependencies']
remove target *args:
  uv remove {{target}} {{args}}

# Show outdated dependencies
[group: 'Dependencies']
outdated:
  uv tree --outdated --depth=1 | grep latest || true


# -----------------------------------------------------------------------------
# Testing
# -----------------------------------------------------------------------------
# Run tests
[group: 'Testing']
test *args:
  python -m pytest tests/ -v {{args}}


# -----------------------------------------------------------------------------
# Linting & Formatting
# -----------------------------------------------------------------------------
# Run linting
[group: 'Linting & Formatting']
lint:
  ruff check
  pyright

# Format code
[group: 'Linting & Formatting']
format:
  ruff format .


# -----------------------------------------------------------------------------
# Documentation
# -----------------------------------------------------------------------------
# Build and preview the documentation locally
[group: 'Documentation']
docs:
  just docs-build-api
  quarto preview docs --port 4200

# Build the API reference pages
[group: 'Documentation']
docs-build-api:
  PYTHONPATH=src uv run python scripts/gen_quarto_api.py

# Build the full documentation, including the API reference pages
[group: 'Documentation']
docs-build:
  just docs-build-api
  quarto render docs

# View the documentation locally
[group: 'Documentation']
view-docs:
  quarto preview docs --port 4200


# -----------------------------------------------------------------------------
# Building & Publishing
# -----------------------------------------------------------------------------
# Generate a distribution package
[group: 'Building & Publishing']
build:
  python -m build

# Publish a distribution package to TestPyPI
[group: 'Building & Publishing']
publish:
  python -m twine upload --repository testpypi dist/*


# -----------------------------------------------------------------------------
# Utilities
# -----------------------------------------------------------------------------
# Clean up testing and build artifacts
[group: 'Utilities']
clean:
  find . -type f -name "*.pyc" -delete
  find . -type d -name "__pycache__" -delete
  rm -rf build/
  rm -rf dist/
  rm -rf *.egg-info/
