# The pip of the `python` that runs the tests (CI), otherwise uv pip (uv venvs are seedless)
PIP := `python -m pip --version > /dev/null 2>&1 && echo "python -m pip" || echo "uv pip"`

# List all available commands
default:
    just --list

# install dev requirements
install_requirements_dev:
    {{PIP}} install -r requirements-dev.txt

# install litgen in editable mode
install_litgen_editable:
    {{PIP}} install --verbose  -e .

# run black formatter
black:
    black .

# Builds the integration tests for pybind
build_integration_tests_pybind:
    python src/litgen/integration_tests/autogenerate_mylib.py pybind
    export LITGEN_USE_NANOBIND=OFF && cd src/litgen/integration_tests &&  {{PIP}} install -v -e . && cd -
    python -m lg_mylib.use pybind
    python -c "import lg_mylib._lg_mylib_pybind"

# Builds the integration tests for nanobind
build_integration_tests_nanobind:
    python src/litgen/integration_tests/autogenerate_mylib.py nanobind
    export LITGEN_USE_NANOBIND=ON && cd src/litgen/integration_tests &&  {{PIP}} install -v -e . && cd -
    python -m lg_mylib.use nanobind
    python -c "import lg_mylib._lg_mylib_nanobind"

# Runs all tests for pybind, after building the integration tests
integration_tests_pybind: build_integration_tests_pybind
    just pytest pybind

# Runs all tests for nanobind, after building the integration tests
integration_tests_nanobind: build_integration_tests_nanobind
    just pytest nanobind

# Runs all tests for pybind and nanobind (after building the integration tests)
integration_tests: integration_tests_nanobind integration_tests_pybind

# Just runs pytest (requires that the integration tests have been built)
pytest binding_type:
    python -m lg_mylib.use {{binding_type}}
    pytest

# Runs mypy on the top level folder (see mypy.ini)
mypy:
    mypy .

# Build the doc in interactive mode (for dev)
[group('docs')]
doc_serve_interactive:
    cd docs/book && jupyter-book start

# Serve the static built doc
[group('docs')]
doc_serve_static:
    cd docs/book/_build/html && python -m http.server 7005

# Build the doc in static html
[group('docs')]
doc_build_static:
    cd docs/book && jupyter-book build --html
    echo "Doc built in docs/book/_build/html"
    echo "You can serve it with:\n  just doc_serve_static"

# Build doc in pdf
[group('docs')]
doc_build_pdf:
    cd docs/book && jupyter-book build --pdf
