# Development verbs for the zarr-http-server package. Recipes run with this
# directory as the working directory regardless of where `just` is invoked.
#
# CI calls these recipes rather than repeating their commands, so a green run
# in .github/workflows/zarr-http-server.yml means the same thing as a green
# `just check` here.

# Pinned to the ruff that .pre-commit-config.yaml uses, so this and the
# pre-commit gate enforce one standard. An unpinned `uvx ruff` floats to the
# newest release: when ruff 0.16 began selecting BLE001 under the root
# config's `B` prefix, this job failed on rules the pinned ruff never enforced,
# with no code change to blame. Bump alongside the pre-commit rev.
ruff_version := "0.16.0"

# List available recipes
default:
    @just --list

# The `examples` group carries the deps the README examples need, so the test
# that reads a served array back with a zarr client runs here instead of
# silently skipping.
# Run the test suite; extra args are passed to pytest
test *args:
    uv run --group test --group examples pytest tests {{ args }}

# Lint the package sources and tests
lint:
    uvx ruff@{{ ruff_version }} check .

# This package type-checks with mypy (see [tool.mypy] in pyproject.toml)
# rather than the pyright used by the other packages under packages/.
# Type-check the package sources
typecheck:
    uv run --group test --with mypy mypy src

# Run everything CI runs for this package
check: lint typecheck test docs-check

# Preview the changelog that the next release would generate
changelog-draft:
    uvx towncrier build --draft --version Unreleased

# Build this package's documentation site, warnings as errors
docs-check:
    env DISABLE_MKDOCS_2_WARNING=true uv run --group docs mkdocs build --strict

# With no argument, uses port 8000 if free, otherwise an ephemeral free port;
# an explicitly requested port is used as-is so a conflict fails loudly.
# Serve this package's documentation site
docs-serve port="":
    #!/usr/bin/env bash
    set -euo pipefail
    port="{{ port }}"
    if [ -z "$port" ]; then
        port=$(uv run --group docs python -c '
    import socket
    s = socket.socket()
    try:
        s.bind(("127.0.0.1", 8000))
    except OSError:
        s.close()
        s = socket.socket()
        s.bind(("127.0.0.1", 0))
    print(s.getsockname()[1])
    s.close()
    ')
    fi
    exec env DISABLE_MKDOCS_2_WARNING=true uv run --group docs mkdocs serve -a "localhost:$port"
