2024-09-10 20:34:37 +02:00
# Define the targets
2026-11-08 18:44:28 +00:00
.PHONY : help install dist test test -system test -ci test -browser test -profile \
2026-02-23 20:59:03 +01:00
docker -run docker -build docs read -docs clean format gitlint mypy \
run run -dev run -dash run -dash -dev prepare -version test -version uv -update
# Use uv for all program actions
UV := uv
2026-09-10 23:20:35 +02:00
UV_PYTHON := python3
PYTHON := $( UV) run --python $( UV_PYTHON) python
2026-02-23 20:59:03 +01:00
PYTEST := $( UV) run pytest
2026-09-10 23:20:35 +02:00
MYPY := $( UV) run --locked --exact --extra dev python -m mypy --config-file pyproject.toml
PRECOMMIT := $( UV) run --locked --extra dev pre-commit
2026-02-23 20:59:03 +01:00
COMMITIZEN := $( UV) run cz
2025-11-20 00:10:19 +01:00
# - Take VERSION from version.py
2026-09-10 23:20:35 +02:00
# Evaluate only for targets that need it, so typing never runs an unlocked uv command.
VERSION = $( shell $( PYTHON) scripts/get_version.py)
2024-09-10 20:34:37 +02:00
# Default target
all : help
# Target to display help information
help :
@echo "Available targets:"
2025-12-30 22:08:21 +01:00
@echo " format - Format source code."
@echo " gitlint - Lint last commit message."
@echo " mypy - Run mypy."
@echo " install - Install EOS in editable form (development mode) into virtual environment."
2026-02-23 20:59:03 +01:00
@echo " update-env - Update virtual environmenr to match pyproject.toml."
2025-12-30 22:08:21 +01:00
@echo " docker-run - Run entire setup on docker"
@echo " docker-build - Rebuild docker image"
@echo " docs - Generate HTML documentation (in build/docs/html/)."
@echo " read-docs - Read HTML documentation in your browser."
@echo " gen-docs - Generate openapi.json and docs/_generated/*."
@echo " clean-docs - Remove generated documentation."
@echo " run - Run EOS production server in virtual environment."
@echo " run-dev - Run EOS development server in virtual environment (automatically reloads)."
@echo " run-dash - Run EOSdash production server in virtual environment."
@echo " run-dash-dev - Run EOSdash development server in virtual environment (automatically reloads)."
@echo " test - Run tests."
@echo " test-finalize - Run all tests (e.g. to finalize a commit)."
@echo " test-system - Run tests with system tests enabled."
2026-11-18 14:11:29 +01:00
@echo " test-ci - Run tests as CI does (server tests, other tests in parallel, docs, Docker)."
@echo " No user config file allowed."
2026-11-08 18:44:28 +00:00
@echo " test-browser - Run the EOSdash browser tests in headless Chromium (installs Chromium)."
2025-12-30 22:08:21 +01:00
@echo " test-profile - Run single test optimization with profiling."
@echo " dist - Create distribution (in dist/)."
@echo " clean - Remove generated documentation, distribution and virtual environment."
2025-11-20 00:10:19 +01:00
@echo " prepare-version - Prepare a version defined in setup.py."
2024-09-10 20:34:37 +02:00
2025-11-20 00:10:19 +01:00
# Target to create a version.txt
2026-08-16 13:56:25 +02:00
# Uses pure python write to version.txt to circumvent Windows specific echo handling (which fails).
.PHONY : version -txt
2025-11-20 00:10:19 +01:00
version-txt :
2026-08-16 13:56:25 +02:00
@$( PYTHON) -c "from pathlib import Path; Path('version.txt').write_text(' $( VERSION) ', encoding='utf-8')"
2026-02-23 20:59:03 +01:00
@echo "version.txt set to ' $( VERSION) '."
2025-11-20 00:10:19 +01:00
2024-10-06 13:47:16 +02:00
# Target to install EOS in editable form (development mode) into virtual environment.
2026-08-16 13:56:25 +02:00
# Upgrades installation and dependencies
2026-02-23 20:59:03 +01:00
install : version -txt
$( UV) sync --extra dev
@echo "EOS version $( VERSION) installed in editable form (development mode)."
# Target to rebuild the virtual environment.
update-env :
@echo "Rebuilding virtual environment to match pyproject.toml..."
2026-07-15 16:38:53 +02:00
$( UV) sync --upgrade --extra dev
2026-02-23 20:59:03 +01:00
@echo "Environment rebuilt."
2024-10-06 13:47:16 +02:00
# Target to create a distribution.
2026-02-23 20:59:03 +01:00
dist : version -txt
$( PIP) install build
$( PYTHON) -m build --wheel
2024-10-06 13:47:16 +02:00
@echo "Distribution created (see dist/)."
2025-01-06 16:27:57 +01:00
# Target to generate documentation
2026-02-23 20:59:03 +01:00
gen-docs : version -txt
$( PYTHON) ./scripts/generate_config_md.py --output-file docs/_generated/config.md
$( PYTHON) ./scripts/generate_openapi_md.py --output-file docs/_generated/openapi.md
$( PYTHON) ./scripts/generate_openapi.py --output-file openapi.json
2025-01-06 16:27:57 +01:00
@echo "Documentation generated to openapi.json and docs/_generated."
# Target to build HTML documentation
2026-02-23 20:59:03 +01:00
docs : install
$( PYTEST) --finalize tests/test_docsphinx.py
2025-01-06 16:27:57 +01:00
@echo "Documentation build to build/docs/html/."
2024-09-10 20:34:37 +02:00
2024-11-10 23:27:52 +01:00
# Target to read the HTML documentation
2025-11-13 22:53:46 +01:00
read-docs :
2024-11-10 23:27:52 +01:00
@echo "Read the documentation in your browser"
2026-02-23 20:59:03 +01:00
$( PYTEST) --finalize tests/test_docsphinx.py
$( PYTHON) -m webbrowser build/docs/html/index.html
2024-11-10 23:27:52 +01:00
2025-06-10 22:00:28 +02:00
# Clean Python bytecode
clean-bytecode :
find . -type d -name "__pycache__" -exec rm -r {} +
find . -type f -name "*.pyc" -delete
2025-01-03 00:31:20 +01:00
# Clean target to remove generated documentation and documentation artefacts
clean-docs :
2024-11-10 23:27:52 +01:00
@echo "Searching and deleting all '_autosum' directories in docs..."
@find docs -type d -name '_autosummary' -exec rm -rf {} +;
2025-01-03 00:31:20 +01:00
@echo "Cleaning docs build directories"
rm -rf build/docs
# Clean target to remove generated documentation, distribution and virtual environment
clean : clean -docs
@echo "Cleaning virtual env, distribution and build directories"
rm -rf build .venv
2026-02-23 20:59:03 +01:00
@echo "Cleaning uv environment"
$( UV) clean
2024-11-10 23:27:52 +01:00
@echo "Deletion complete."
2024-09-10 20:34:37 +02:00
run :
2025-01-21 19:20:50 +01:00
@echo "Starting EOS production server, please wait..."
2026-02-23 20:59:03 +01:00
$( PYTHON) -m akkudoktoreos.server.eos --startup_eosdash true
2024-11-15 22:27:25 +01:00
run-dev :
2025-01-09 16:54:49 +01:00
@echo "Starting EOS development server, please wait..."
2026-02-23 20:59:03 +01:00
$( PYTHON) -m akkudoktoreos.server.eos --host localhost --port 8503 --log_level DEBUG --startup_eosdash false --reload true
2025-01-22 23:47:28 +01:00
run-dash :
@echo "Starting EOSdash production server, please wait..."
2026-02-23 20:59:03 +01:00
$( PYTHON) -m akkudoktoreos.server.eosdash
2025-01-22 23:47:28 +01:00
run-dash-dev :
@echo "Starting EOSdash development server, please wait..."
2026-03-11 17:18:45 +01:00
$( PYTHON) -m akkudoktoreos.server.eosdash --host localhost --port 8504 --eos-host localhost --eos-port 8503 --log_level DEBUG --reload true
2024-09-16 11:48:20 +02:00
2024-10-08 14:29:45 +02:00
# Target to setup tests.
2026-02-23 20:59:03 +01:00
test-setup : install
2024-10-08 14:29:45 +02:00
@echo "Setup tests"
2024-10-06 12:33:18 +02:00
# Target to run tests.
test :
@echo "Running tests..."
2026-02-23 20:59:03 +01:00
$( PYTEST) -vs --cov src --cov-report term-missing
2024-10-06 12:33:18 +02:00
2026-11-18 14:11:29 +01:00
# Target to run tests as done by CI on Github (.github/workflows/pytest.yml), one part after
2026-11-20 02:01:01 +01:00
# the other: the server tests (test-server), the other tests in parallel (test-shard, without
2026-11-18 14:11:29 +01:00
# splitting them into shards), the Sphinx build (docs-test) and the Docker checks (docker-test).
# Every test runs once. The coverage report covers the first two parts, like the test job.
# The browser tests (browser-test) have their own target test-browser.
2026-11-20 02:01:01 +01:00
# The parallel part starts one pytest-xdist worker per core, but at most TEST_CI_MAX_WORKERS:
# one worker per core runs out of memory or threads on machines with many cores.
TEST_CI_MAX_WORKERS ?= 8
2026-11-18 14:11:29 +01:00
test-ci : export COVERAGE_CORE := sysmon
2025-04-05 13:08:12 +02:00
test-ci :
@echo "Running tests as CI..."
2026-11-18 14:11:29 +01:00
$( PYTEST) --finalize --check-config-side-effect -m "eos_server and not docs and not docker" -vs --durations= 25 --cov src --cov-report=
2026-11-20 02:01:01 +01:00
$( PYTEST) --finalize --check-config-side-effect -m "not eos_server and not docs and not docker" -n auto --maxprocesses= $( TEST_CI_MAX_WORKERS) -v --durations= 25 --cov src --cov-append --cov-report term-missing
2026-11-18 14:11:29 +01:00
$( PYTEST) --finalize --check-config-side-effect -m docs -vs
$( PYTEST) --finalize --check-config-side-effect -m docker -vs
2025-04-05 13:08:12 +02:00
2026-11-08 18:44:28 +00:00
# Target to run the EOSdash browser tests in headless Chromium.
# The browser is installed for the user (~/.cache/ms-playwright), not in the virtual environment.
# --extra dev installs playwright even if the environment was synced without it.
test-browser :
@echo "Running EOSdash browser tests..."
$( UV) run --extra dev playwright install chromium
$( UV) run --extra dev pytest --browser-test -m browser -vs
2025-10-28 02:50:31 +01:00
# Target to run tests including the system tests.
test-system :
@echo "Running tests incl. system tests..."
2026-02-23 20:59:03 +01:00
$( PYTEST) --system-test -vs --cov src --cov-report term-missing
2025-10-28 02:50:31 +01:00
2024-11-10 23:22:30 +01:00
# Target to run all tests.
2025-12-30 22:08:21 +01:00
test-finalize :
2024-11-10 23:22:30 +01:00
@echo "Running all tests..."
2026-02-23 20:59:03 +01:00
$( PYTEST) --finalize
2024-11-10 23:22:30 +01:00
2025-11-03 17:40:25 +01:00
# Target to run tests including the single test optimization with profiling.
test-profile :
@echo "Running single test optimization with profiling..."
2026-02-23 20:59:03 +01:00
$( PYTHON) tests/single_test_optimization.py --profile
2025-11-03 17:40:25 +01:00
2024-11-15 22:27:25 +01:00
# Target to format code.
format :
2026-02-23 20:59:03 +01:00
$( PRECOMMIT) run --all-files
2024-11-15 22:27:25 +01:00
2026-02-23 20:59:03 +01:00
# Target to trigger git linting using commitizen for the latest commit messages
2025-04-07 22:23:35 +02:00
gitlint :
2026-02-23 20:59:03 +01:00
$( COMMITIZEN) check --rev-range main..HEAD
2025-04-07 22:23:35 +02:00
2026-09-10 23:20:35 +02:00
# Check the complete typing policy in the locked development environment.
2024-11-26 22:28:05 +01:00
mypy :
2026-02-23 20:59:03 +01:00
$( MYPY)
2024-11-26 22:28:05 +01:00
2024-09-16 11:48:20 +02:00
# Run entire setup on docker
docker-run :
2025-12-30 22:08:21 +01:00
@echo "Build and run EOS docker container locally."
@echo "Persistent data (and config) in ${ HOME } /.local/share/net.akkudoktor.eos"
2026-08-21 07:07:34 +02:00
@docker pull python:3.13.15-slim
2024-10-07 20:56:10 +02:00
@docker compose up --remove-orphans
docker-build :
2025-12-30 22:08:21 +01:00
@echo "Build EOS docker container locally."
@echo "Persistent data (and config) in ${ HOME } /.local/share/net.akkudoktor.eos"
2026-08-21 07:07:34 +02:00
@docker pull python:3.13.15-slim
2025-11-16 13:25:45 +01:00
@docker compose build
2025-10-28 02:50:31 +01:00
2025-11-20 00:10:19 +01:00
# Propagete version info to all version files
2026-02-23 20:59:03 +01:00
prepare-version : install
2026-03-18 08:41:28 +01:00
$( PYTHON) ./scripts/update_version.py $( VERSION)
2026-02-23 20:59:03 +01:00
$( PYTHON) ./scripts/convert_lightweight_tags.py
$( PYTHON) ./scripts/generate_config_md.py --output-file docs/_generated/config.md
$( PYTHON) ./scripts/generate_openapi_md.py --output-file docs/_generated/openapi.md
$( PYTHON) ./scripts/generate_openapi.py --output-file openapi.json
2026-02-24 18:56:11 +01:00
$( PYTEST) -vv --finalize tests/test_doc.py
2026-03-11 17:18:45 +01:00
$( PRECOMMIT) run --all-files
2026-03-18 08:41:28 +01:00
@echo "Updated version to $( VERSION) from version.py in config files and doc"
2025-11-09 09:07:04 +01:00
2025-11-20 00:10:19 +01:00
test-version :
echo "Test version information to be correctly set in all version files"
2026-02-23 20:59:03 +01:00
$( PYTEST) -vv tests/test_version.py