Follow PEP8 with a hard-limit of 79 characters for line-length and of 79 lines for function-length (not counting the docstring). When refactoring, prefer middle-size functions (i.e. dozen of lines, not too short). Do not strip comments away. Prefer the use of numpy when possible. Do not use black code style, in particular no closing parenthesis on their own line; try to save vertical space. Private functions should have comments, not docstrings.
In order to run Python code you must make sure that the venv (~/openquake or .pixi/envs/default) is activated; also make sure ruff, pytest-xdist and pytest-django are installed. It is also useful to install pyqt5, qtawesome, PyOpenGL and silx to view HDF5 files.
Contributors wanting to develop with the engine should read doc/contributing/developing-with-the-engine.rst
The openquake/calculators tests are meant to be run with OQ_DISTRIBUTE=no and pytest -n auto, while the tests outside openquake/calculators should be run normally. Expected files can be regenerated by setting OQ_OVERWRITE=1.
Calculations should be run without OQ_DISTRIBUTE (unless we want to profile
then) and killed with oq abort <calc_id>.
The server tests in openquake/server/tests must be run with the right OQ_APPLICATION_MODE, which is set in the comment at the top of each file: IMPACT for test_impact_mode*.py, AELO for test_aelo_mode*.py, RESTRICTED for test_restricted_mode*.py, and unset for test_public_mode.py. They use a scratch database, never the engine database in ~/oqdata.
After a refactoring run ruff check and openquake/baselib/tests/flake8_test.py;
make sure they do not fail.
The performance of a machine can be assessed with the command
oq engine --run https://downloads.openquake.org/jobs/performance.zip.
On a laptop with an Intel Ultra/Ryzen 7 (or a modern Mac)
it should take less than 10 minutes.