# Development verbs for the zarr-metadata package. Recipes run with this
# directory as the working directory regardless of where `just` is invoked.

# List available recipes
default:
    @just --list

# Run the test suite; extra args are passed to pytest
test *args:
    uv run --group test pytest tests {{ args }}

# Lint with the same invocation CI uses
lint:
    uvx ruff check .

# Pinned to the last pyright that types PEP 661 sentinels in class attributes
# correctly; 1.1.405+ regressed (microsoft/pyright#11115). Unpin when fixed.
pyright_version := "1.1.404"

# CI runs pyright on python 3.11; the pinned pyright predates 3.14, whose
# stdlib it cannot parse, so pin the interpreter to match CI.
# Type-check the package sources
typecheck:
    uv run --python 3.11 --group test --with 'pyright=={{ pyright_version }}' pyright 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"
