The single test job ran all tests one after the other on one runner,
including the Sphinx build and the Docker checks (11-19 min). It is now
split so that every test still runs exactly once:
- docs-test, docker-test: the Sphinx build (new marker "docs") and the
Docker / Home Assistant add-on checks ("docker") in jobs of their own.
- test-server: the tests that start EOS or EOSdash on the fixed ports.
The collection hook marks every test that uses the xprocess fixture
with "eos_server" and puts them into one xdist group, so
"pytest -n auto --dist loadgroup" also works locally. A test that
binds the ports without a fixture carries the marker itself.
- test-shard: all other tests in four shards of about equal runtime
(scripts/shard_test_files.py, runtimes in scripts/test_durations.json),
each with pytest-xdist.
- test-count: fails if these parts do not add up to the tests of one
plain run.
- test: keeps the name of the required check. It prints the combined
coverage report and fails if any of the jobs above failed.
COVERAGE_CORE=sysmon measures line coverage through sys.monitoring:
the report is the same, the test time drops by about a third. The
combined report misses 1-3 statements more than a single run, in lines
that only run when a test finds state left by an earlier test.
The Sphinx build spent 74 % of its time in one search of
PythonDomain.find_obj (sphinx-doc/sphinx#11282). The local extension
docs/_ext/pyxrefindex.py answers it from an index of name endings with
the same matches in the same order; a build has a byte-identical
objects.inv. It copies the logic of Sphinx 9.0.4 and is only active for
that version; TestPyXrefIndex compares it with the installed Sphinx and
fails after a Sphinx update until the version is raised. The
documentation test builds with -j (up to four jobs); its pages can
differ from a serial build in the target of ambiguous cross-references.
Read the Docs builds without -j. Sphinx build on GitHub runners:
427-480 s -> 180-233 s.
make test-ci runs the commands of these jobs one after the other.
On GitHub runners the tests are done after about 2 minutes; the
required check ends with docs-test after about 4-5 minutes.
Additional changes
Add pytest-xdist to the development dependencies
List the 25 slowest tests in each test job (--durations=25)
Test version() directly; it was covered only through the Sphinx test
Add a "Keep Tests Fast" tip, the server marker rule, the extension and
test-ci to the development guide and the testing skill
Refs #1553
Co-authored-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Assisted-by: Claude Code (claude-opus-5-5)
Assisted-by: Claude Code (claude-fable-5-2)
19 KiB
% SPDX-License-Identifier: Apache-2.0 (develop-page)=
Development Guide
Development Prerequisites
Have or create a GitHub account.
Make shure all the source installation prequistes are installed. See the installation guideline for a detailed list of tools.
Under Linux the make tool should be installed as we have a lot of pre-fabricated commands for it.
Install your favorite editor or integrated development environment (IDE):
-
Full-Featured IDEs
-
Code Editors with Python Support
-
Python-Focused or Beginner-Friendly IDEs
Step 1 – Fork the Repository
Fork the EOS repository to your GitHub account.
Clone your fork locally and add the EOS upstream remote to track updates.
.. tabs::
.. tab:: Windows
.. code-block:: powershell
git clone https://github.com/<YOURUSERNAME>/EOS.git
cd EOS
git remote add eos https://github.com/Akkudoktor-EOS/EOS.git
git config --global core.autocrlf false
.. tab:: Linux
.. code-block:: bash
git clone https://github.com/<YOURUSERNAME>/EOS.git
cd EOS
git remote add eos https://github.com/Akkudoktor-EOS/EOS.git
Replace <YOURUSERNAME> with your GitHub username.
Step 2 – Development Setup
This is recommended for developers who want to modify the source code and test changes locally.
Step 2.1 – Create a Virtual Environment
.. tabs::
.. tab:: Windows
.. code-block:: powershell
uv run python scripts/get_version.py > version.txt
uv sync --extra dev
.. tab:: Linux
.. code-block:: bash
uv run python scripts/get_version.py > version.txt
uv sync --extra dev
.. tab:: Linux Make
.. code-block:: bash
make install
Step 2.2 - Install pre-commit
Our code style and commit message checks use pre-commit.
.. tabs::
.. tab:: Windows
.. code-block:: powershell
pre-commit install
pre-commit install --hook-type commit-msg --hook-type pre-push
.. tab:: Linux
.. code-block:: bash
pre-commit install
pre-commit install --hook-type commit-msg --hook-type pre-push
Step 3 - Run EOS
Make EOS accessible at http://localhost:8503/docs and EOSdash at http://localhost:8504.
Option 1 – Using Python Virtual Environment
.. tabs::
.. tab:: Windows
.. code-block:: powershell
uv run python -m akkudoktoreos.server.eos
.. tab:: Linux
.. code-block:: bash
uv run python -m akkudoktoreos.server.eos
.. tab:: Linux Make
.. code-block:: bash
make run
To have full control of the servers during development you may start the servers independently - e.g. in different terminal windows. Don't forget to activate the virtual environment in your terminal window.
:::{admonition} Note :class: note If you killed or stopped the servers shortly before, the ports may still be occupied by the last processes. It may take more than 60 seconds until the ports are released. :::
You may add the --reload true parameter to have the servers automatically restarted on source code
changes. It is best to also add --startup_eosdash false to EOS to prevent the automatic restart
interfere with the EOS server trying to start EOSdash.
.. tabs::
.. tab:: Windows
.. code-block:: powershell
uv run python -m akkudoktoreos.server.eosdash --host localhost --port 8504 --log_level DEBUG --reload true
.. tab:: Linux
.. code-block:: bash
uv run python -m akkudoktoreos.server.eosdash --host localhost --port 8504 --log_level DEBUG --reload true
.. tab:: Linux Make
.. code-block:: bash
make run-dash-dev
.. tabs::
.. tab:: Windows
.. code-block:: powershell
uv run python -m akkudoktoreos.server.eos --host localhost --port 8503 --log_level DEBUG --startup_eosdash false --reload true
.. tab:: Linux
.. code-block:: bash
uv run python -m akkudoktoreos.server.eos --host localhost --port 8503 --log_level DEBUG --startup_eosdash false --reload true
.. tab:: Linux Make
.. code-block:: bash
make run-dev
Option 2 – Using Docker
Step 3.1 – Build the Docker Image
.. tabs::
.. tab:: Windows
.. code-block:: powershell
docker build -t akkudoktoreos .
.. tab:: Linux
.. code-block:: bash
docker build -t akkudoktoreos .
Step 3.2 – Run the Container
.. tabs::
.. tab:: Windows
.. code-block:: powershell
docker run -d `
--name akkudoktoreos `
-p 8503:8503 `
-p 8504:8504 `
-e OPENBLAS_NUM_THREADS=1 `
-e OMP_NUM_THREADS=1 `
-e MKL_NUM_THREADS=1 `
-e EOS_SERVER__HOST=0.0.0.0 `
-e EOS_SERVER__PORT=8503 `
-e EOS_SERVER__EOSDASH_HOST=0.0.0.0 `
-e EOS_SERVER__EOSDASH_PORT=8504 `
--ulimit nproc=65535:65535 `
--ulimit nofile=65535:65535 `
--security-opt seccomp=unconfined `
akkudoktor-eos:latest
.. tab:: Linux
.. code-block:: bash
docker run -d \
--name akkudoktoreos \
-p 8503:8503 \
-p 8504:8504 \
-e OPENBLAS_NUM_THREADS=1 \
-e OMP_NUM_THREADS=1 \
-e MKL_NUM_THREADS=1 \
-e EOS_SERVER__HOST=0.0.0.0 \
-e EOS_SERVER__PORT=8503 \
-e EOS_SERVER__EOSDASH_HOST=0.0.0.0 \
-e EOS_SERVER__EOSDASH_PORT=8504 \
--ulimit nproc=65535:65535 \
--ulimit nofile=65535:65535 \
--security-opt seccomp=unconfined \
akkudoktor-eos:latest
Step 3.3 – Manage the Container
.. tabs::
.. tab:: Windows
.. code-block:: powershell
docker logs -f akkudoktoreos
docker stop akkudoktoreos
docker start akkudoktoreos
docker rm -f akkudoktoreos
.. tab:: Linux
.. code-block:: bash
docker logs -f akkudoktoreos
docker stop akkudoktoreos
docker start akkudoktoreos
docker rm -f akkudoktoreos
For detailed Docker instructions, refer to Installation Guideline
Step 4 - Create the changes
Step 4.1 - Create a development branch
Create a local development branch and make it know on your GitHub repo.
git checkout -b <MY_DEVELOPMENT_BRANCH>
git push --set-upstream origin <MY_DEVELOPMENT_BRANCH>
Replace <MY_DEVELOPMENT_BRANCH> with the development branch name. The branch name shall be of the
format (feat|fix|chore|docs|refactor|test)/[a-z0-9._-]+, e.g:
- feat/my_cool_new_feature
- fix/this_annoying_bug
- ...
Step 4.2 – Edit the sources
Use your fovourite editor or IDE to edit the sources.
Step 4.3 - Check the source code for correct format
.. tabs::
.. tab:: Windows
.. code-block:: powershell
pre-commit run --all-files
.. tab:: Linux
.. code-block:: bash
pre-commit run --all-files
.. tab:: Linux Make
.. code-block:: bash
make format
Step 4.4 - Test the changes
At a minimum, you should run the module tests:
.. tabs::
.. tab:: Windows
.. code-block:: powershell
uv run pytest -vs --cov src --cov-report term-missing
.. tab:: Linux
.. code-block:: bash
uv run pytest -vs --cov src --cov-report term-missing
.. tab:: Linux Make
.. code-block:: bash
make test
:::{admonition} Note :class: Note Depending on your changes you may also have to change the version.py and documentation files. Do as suggested by the tests. You may ignore the version.py and documentation changes up until you finalize your change. :::
You should also run the system tests. These include additional tests that interact with real resources:
.. tabs::
.. tab:: Windows
.. code-block:: powershell
uv run pytest --system-test -vs --cov src --cov-report term-missing
.. tab:: Linux
.. code-block:: bash
uv run pytest --system-test -vs --cov src --cov-report term-missing
.. tab:: Linux Make
.. code-block:: bash
make test-system
If you change EOSdash, also run the browser tests. They start EOS and EOSdash and check the pages in a headless Chromium browser, e.g. that every page renders in light and dark mode without JavaScript errors. The browser has to be installed once:
.. tabs::
.. tab:: Windows
.. code-block:: powershell
uv run --extra dev playwright install chromium
uv run --extra dev pytest --browser-test -m browser -vs
.. tab:: Linux
.. code-block:: bash
uv run --extra dev playwright install --with-deps chromium
uv run --extra dev pytest --browser-test -m browser -vs
.. tab:: Linux Make
.. code-block:: bash
sudo $(which uv) run --extra dev playwright install-deps chromium
make test-browser
On Linux the browser needs system libraries. Install them once with --with-deps or
install-deps (requires root). On Windows no system libraries are needed. Without
--browser-test the browser tests are skipped.
To do profiling use:
.. tabs::
.. tab:: Windows
.. code-block:: powershell
uv run python tests/single_test_optimization.py --profile
.. tab:: Linux
.. code-block:: bash
uv run python tests/single_test_optimization.py --profile
.. tab:: Linux Make
.. code-block:: bash
make test-profile
Step 4.5 - Commit the changes
Add the changed and new files to the commit.
Create a commit.
Step 5 - Pull request
Before creating a pull request assure the changes are based on the latest EOS upstream.
Update your local main branch:
git checkout main
git pull eos main
Switch back to your local development branch and rebase to main.
git checkout <MY_DEVELOPMENT_BRANCH>
git rebase -i main
During rebase you can also squash your changes into one (preferred) or a set of commits that have proper commit messages and can easily be reviewed.
After rebase run the tests once again.
If everything is ok push the commit(s) to your fork on Github.
git push -f origin
If your push by intention does not comply to the rules you can skip the verification by:
git push -f --no-verify origin
Once ready, submit a pull request with your fork to the Akkudoktor-EOS/EOS@master repository.
Developer Tips
Keep Your Fork Updated
Regularly pull changes from the eos repository to avoid merge conflicts:
.. tabs::
.. tab:: Windows
.. code-block:: powershell
git checkout main
git pull eos main
git push origin
.. tab:: Linux
.. code-block:: bash
git checkout main
git pull eos main
git push origin
Rebase your development branch to the latest eos main branch.
.. tabs::
.. tab:: Windows
.. code-block:: powershell
git checkout <MY_DEVELOPMENT_BRANCH>
git rebase -i main
.. tab:: Linux
.. code-block:: bash
git checkout <MY_DEVELOPMENT_BRANCH>
git rebase -i main
Create Feature Branches
Work in separate branches for each feature or bug fix:
.. tabs::
.. tab:: Windows
.. code-block:: powershell
git checkout -b feat/my-feature
.. tab:: Linux
.. code-block:: bash
git checkout -b feat/my-feature
Run Tests Frequently
Ensure your changes do not break existing functionality:
.. tabs::
.. tab:: Windows
.. code-block:: powershell
uv run pytest -vs --cov src --cov-report term-missing
.. tab:: Linux
.. code-block:: bash
uv run pytest -vs --cov src --cov-report term-missing
.. tab:: Linux Make
.. code-block:: bash
make test
Keep Tests Fast
Keep each test case well under a second:
- Do not wait in real time (no
sleepor wait loops); use synthetic timestamps instead. - Do not
parametrizethe full cartesian product of independent axes. - Extend an existing parametrized test before writing a new one.
The CI logs of the test-shard and test-server jobs list their 25 slowest tests
(--durations=25). The Sphinx documentation build and the Docker checks run in their own CI
jobs. Run them locally with uv run pytest --finalize -m docs and
uv run pytest --finalize -m docker (the Docker checks need a running Docker engine).
The Sphinx build resolves Python cross-references through the local extension
docs/_ext/pyxrefindex.py. It answers a search that Sphinx runs over all documented objects from
an index; the generated pages stay the same (see
sphinx-doc/sphinx#11282). The extension is
only active for the Sphinx version it was verified with. After a Sphinx update, TestPyXrefIndex
in tests/test_docsphinx.py fails until the version in the extension is raised.
The documentation test builds with up to four parallel jobs (sphinx-build -j), and so do
make docs and make read-docs, which run this test. A parallel build can link a cross-reference
with an ambiguous name to another object of the same name than a build with one process.
CI runs every test exactly once, spread over several jobs:
test-shard: the tests that do not start a server, in four shards of about equal runtime, each with pytest-xdist on all cores of its runner.test-server: the tests with theeos_servermarker, one after the other.test-count: fails if these parts do not add up to the tests of one plain run, or if the marker of the server tests is no longer derived from the fixture.test: prints the coverage report of all parts. It is the required check and fails if one of these jobs,docs-testordocker-testfailed.
make test-ci runs the tests of the jobs test-server, test-shard, docs-test and
docker-test locally, with the markers and options of these jobs and one part after the other:
the server tests, the other tests with pytest-xdist on all cores (not split into shards), the
Sphinx build and the Docker checks. It prints the coverage report of the first two parts and stops
at the first part that fails. The browser tests of the browser-test job have their own target,
make test-browser.
The coverage report of the test job is combined from the parts. It differs from the report of
one plain run in a few lines, and not in exactly the same ones in every run: lines that are only
executed when a test finds state left by an earlier test of the same process. With pytest-xdist
the order of the tests in a worker changes from run to run. When the layout was introduced, three
runs missed 4523 to 4525 statements out of 26154, one plain run 4522.
scripts/shard_test_files.py distributes the test modules to the shards by the runtimes in
scripts/test_durations.json. Outdated runtimes only cost balance; a module without an entry
counts one second. To rebalance, download the junit-shard-* artifacts of a CI run and call
uv run python scripts/shard_test_files.py --update junit-shard-*.xml.
CI measures coverage with the sys.monitoring core of coverage.py (COVERAGE_CORE=sysmon).
The report is the same as with the default tracer, but a coverage run takes about a third less
time. Set the variable for local coverage runs as well. On Python 3.13 this core does not measure
branch coverage: with --cov-branch, coverage.py falls back to the default tracer.
Run the tests in parallel with uv run pytest -n auto --dist loadgroup (pytest-xdist). The tests
that start a real EOS or EOSdash server listen on fixed ports and must not run next to each
other. They carry the eos_server marker, set automatically for every test that uses the
xprocess fixture, and share one xdist group, which --dist loadgroup keeps on one worker.
Without --dist loadgroup these tests collide. Give a test that binds the ports without the
fixture the marker itself (@pytest.mark.eos_server).
Follow Coding Standards
Keep your code consistent with existing style and conventions.
Keep Python Docstrings RST Compatible
The docstrings will be parsed by Sphinx in automatic documentation generation.
Use Issues for Discussion
Before making major changes, open an issue or discuss with maintainers.
Document Changes
Update docstrings, comments, and any relevant documentation.
Start or Reopen the Home Assistant Dev Container in VS Code
1. Open Visual Studio Code
Start Visual Studio Code.
2. Open the Command Palette
Open the Command Palette:
- Windows / Linux:
Ctrl + Shift + P - macOS:
Cmd + Shift + P
3. Reopen the Workspace in the Dev Container
In the Command Palette, select:
Dev Containers: Reopen in Container
VS Code will:
- Build the dev container (if required)
- Start the container
- Reopen the workspace inside the container
4. Start Home Assistant
Open the Command Palette again and select:
Dev Terminal: Run Task... → Start Home Assistant
:::{admonition} Note :class: note Startup may take several minutes while the Home Assistant Supervisor initializes. :::
If startup fails you may retry with container rebuild before:
Dev Containers: Rebuild Container without Cache
5. Open Home Assistant
Once startup is complete, open your browser and navigate to:
http://localhost:7123/
If this is your first start, complete the standard Home Assistant onboarding process.
6. Install the Local Akkudoktor-EOS Add-on
6.1 Open the Add-on Store
In Home Assistant, navigate to:
Settings → Add-ons → Add-on Store
Open the top-right menu (⋮), then select:
Repositories → Local add-ons
Choose Akkudoktor-EOS.
6.2 Install the Add-on
The Akkudoktor-EOS add-on is automatically available. Click Install to begin installation.
6.3 Start the Add-on
After installation completes, click Start in the add-on panel.
6.4 Open the EOS Web Interface
In the add-on panel, click Open Web UI to access the EOS dashboard.
6.5 Configure EOS (Optional)
In the EOS dashboard, navigate to:
Config
to adjust configuration settings as needed.