set dotenv-load
set export
HERE := env_var_or_default("HERE", invocation_directory())
IMAGE := env_var_or_default("IMAGE", "registry.gitlab.com/ratio-case-os/docker/python-ci")
TAG := env_var_or_default("TAG", "latest")
JUSTFILE := justfile()
DOCS_SOURCE := HERE / "docs" / "source"
DOCS_BUILD := HERE + "docs" / "build"

# Show the recipe list.
default:
  @just --list --justfile {{JUSTFILE}}

# Pull the tools image from the registry.
pull-container *args:
  podman pull {{args}} {{IMAGE}}:{{TAG}}

# Run the Docker tools image with the project directory mounted.
run-container args="" cmd="":
  podman run --userns=keep-id --rm -it -v {{HERE}}:/home/ratio/work:z {{args}} {{IMAGE}}:{{TAG}} {{cmd}}

# Run a recipe in the Docker tools image.
in-container recipe="":
  podman run --userns=keep-id --rm -it -v {{HERE}}:/home/ratio/work:z {{IMAGE}}:{{TAG}} just {{recipe}}

# Install the Python package in development mode.
install *args:
  uv sync --all-extras {{args}}

# Update the dependencies.
update *args:
  uv lock {{args}} && just install

# Run tests using pytest.
test *args:
  uv run pytest {{args}}

# Run the tests in watch mode.
watch *args:
  uv run ptw --ignore-patterns "tests/.temp/**/*" --now . --no-header {{args}}

# Build the Python wheel.
build *args:
  uv build {{args}}

# Publish the Python package with a token.
publish token *args:
  uv publish --token {{token}} {{args}}

# Install MkDocs and all dependencies using pipx.
install-mkdocs:
  pipx install mkdocs
  pipx inject mkdocs \
    cairosvg \
    mkdocs-autorefs \
    mkdocs-bibtex \
    mkdocs-glightbox \
    mkdocs-literate-nav \
    "mkdocs-material[recommended,git,imaging]" \
    "mkdocstrings[python]" \
    pydoc-markdown

# Build the Python package's documentation.
docs *args:
  mkdocs build {{args}}

# Lint the Python package.
lint *args:
  uv run ruff check .
  uv run black . --check {{args}}

# Fix fixable linting errors.
fix *args:
  uv run ruff check --fix .
  uv run black . {{args}}

# Check version increment.
version *args:
  uv run raver {{args}}

# Clean generated files.
clean:
  rm -rf {{DOCS_BUILD}}
  rm -rf {{HERE}}/dist
