Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

 

History

History
102 lines (70 loc) · 2.83 KB

File metadata and controls

102 lines (70 loc) · 2.83 KB

Development details

All useful information about development that is too detailed for README.md

UV

Nethack has its own dependency group, just for transparency.

All non-production deps must be in the dev group to keep the docker image small.

Ruff

Ruff is used for linting and formatting. There are two separate rules until astral-sh/ruff#8232 is solved.

uv run poe format-code

runs them both, but they can be run separately like this:

Run formatting:

uv run ruff format

Check the formatting

uv run ruff check

Poe is used, because uv doesn't natively allow running two commands in one command by user.

Pytest

During tests, ruff and optionally mypy are run using the pytest-* plugins.

Running pytest on individual files:

# Main bot functionality
uv run pytest tests/simek/test_main.py

# NetHack module tests
uv run pytest tests/grossmann/test_nethack.py

# Integration scenarios
uv run pytest tests/grossmann/test_integration.py

Running pytest without ruff: Uncomment the

addopts = ["--import-mode=importlib", "-v", "--tb=short"]

in pyproject.toml

Mypy

We don't enforce mypy, you can run it locally by uncommenting the mypy section in pyproject.toml

addopts = ["--import-mode=importlib", "-v", "--tb=short", "--ruff", "--ruff-format", "--mypy"]

or by running

mypy .

Šimek jokes

Mom jokes, dad jokes and help requests are implemented using ufal/morphodita, system description is here and complete documentation here.

Morphodita

Loading morphodita takes ~3s, but because it doesn't release the GIL, loading it in separate thread doesn't speed up the total start time. I did experiment with it and got nowhere, 2thread version took same time as single thread.

Šimek grok feature

It's implemented using markov chain 3grams.

Pip

Running pip freeze inside the container doesn't do anything, because system pip doesn't see into env made by UV.

ENV VIRTUAL_ENV=/app/.venv

didn't help and I didn't want to install pip to the uv env, wasn't worth it.

Asyncio optimizations

I ran šimek with PYTHONASYNCIODEBUG=1 and it didn't print anything when processing some messages, meaning no function is blocking the main event loop for over 100ms.

Docker

The dockerfile is highly optimized to produce small layers, the main logic is using UV to build and then copy only what is needed to slim image. Morphodita is copied first as it doesn't change. Then venv is copied without source code, and source code is copied last, so for just source code changes, there is minimal traffic related to docker image.