1 # Setting up Nominatim for Development
3 This chapter gives an overview how to set up Nominatim for development
7 This guide assumes you develop under the latest version of Debian/Ubuntu.
8 You can of course also use your favourite distribution. You just might have
9 to adapt the commands below slightly, in particular the commands for
10 installing additional software.
12 ## Installing Nominatim
14 The first step is to install Nominatim itself. Please follow the installation
15 instructions in the [Admin section](../admin/Installation.md). You don't need
16 to set up a webserver for development, the webserver that can be started
17 via `nominatim serve` is sufficient.
19 If you want to run Nominatim in a VM via Vagrant, use the default `ubuntu24` setup.
20 Vagrant's libvirt provider runs out-of-the-box under Ubuntu. You also need to
21 install an NFS daemon to enable directory sharing between host and guest. The
22 following packages should get you started:
24 sudo apt install vagrant vagrant-libvirt libvirt-daemon nfs-kernel-server
26 ## Prerequisites for testing and documentation
28 The Nominatim test suite consists of behavioural tests (using behave) and
29 unit tests (using PHPUnit for PHP code and pytest for Python code).
30 It has the following additional requirements:
32 * [behave test framework](https://behave.readthedocs.io) >= 1.2.6
33 * [phpunit](https://phpunit.de) (9.5 is known to work)
34 * [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
35 * [Pylint](https://pylint.org/) (CI always runs the latest version from pip)
36 * [mypy](http://mypy-lang.org/) (plus typing information for external libs)
37 * [Python Typing Extensions](https://github.com/python/typing_extensions) (for Python < 3.9)
38 * [pytest](https://pytest.org)
39 * [pytest-asyncio](https://pytest-asyncio.readthedocs.io)
41 For testing the Python search frontend, you need to install extra dependencies
42 depending on your choice of webserver framework:
44 * [httpx](https://www.python-httpx.org/) (Starlette only)
45 * [asgi-lifespan](https://github.com/florimondmanca/asgi-lifespan) (Starlette only)
47 The documentation is built with mkdocs:
49 * [mkdocs](https://www.mkdocs.org/) >= 1.1.2
50 * [mkdocstrings](https://mkdocstrings.github.io/) >= 0.25
51 * [mkdocs-material](https://squidfunk.github.io/mkdocs-material/)
53 Please be aware that tests always run against the globally installed
54 osm2pgsql, so you need to have this set up. If you want to test against
55 the vendored version of osm2pgsql, you need to set the PATH accordingly.
57 ### Installing prerequisites on Ubuntu/Debian
59 The Python tools should always be run with the most recent version.
60 In particular, pylint tends to have a lot of breaking changes between versions.
61 The easiest way, to handle these Python dependencies is to run your
62 development from within a virtual environment.
64 To set up the virtual environment with all necessary packages run:
67 virtualenv ~/nominatim-dev-venv
68 ~/nominatim-dev-venv/bin/pip install\
69 psycopg2-binary psutil psycopg[binary] PyICU SQLAlchemy \
70 python-dotenv jinja2 pyYAML datrie \
71 behave mkdocs mkdocstrings pytest pytest-asyncio pylint \
72 types-jinja2 types-markupsafe types-psutil types-psycopg2 \
73 types-pygments types-pyyaml types-requests types-ujson \
74 types-urllib3 typing-extensions unicorn falcon
77 Now enter the virtual environment whenever you want to develop:
80 . ~/nominatim-dev-venv/bin/activate
83 For installing the PHP development tools, run:
86 sudo apt install php-cgi phpunit php-codesniffer
89 If your distribution does not have PHPUnit 7.3+, you can install it (as well
90 as CodeSniffer) via composer:
93 sudo apt-get install composer
94 composer global require "squizlabs/php_codesniffer=*"
95 composer global require "phpunit/phpunit=8.*"
98 The binaries are found in `.config/composer/vendor/bin`. You need to add this
102 echo 'export PATH=~/.config/composer/vendor/bin:$PATH' > ~/.profile
105 ### Running Nominatim during development
107 The source code for Nominatim can be found in the `src` directory and can
108 be run in-place. The source directory features a special script
109 `nominatim-cli.py` which does the same as the installed 'nominatim' binary
110 but executes against the code in the source tree. For example:
113 me@machine:~$ cd Nominatim
114 me@machine:~Nominatim$ ./nominatim-cli.py --version
115 Nominatim version 4.4.99-1
118 Make sure you have activated the virtual environment holding all
119 necessary dependencies.
123 All tests are located in the `/test` directory.
125 To run all tests, run make from the source root:
131 There are also make targets for executing only parts of the test suite.
132 For example to run linting only use:
138 The possible testing targets are: mypy, lint, pytest, bdd.
140 For more information about the structure of the tests and how to change and
141 extend the test suite, see the [Testing chapter](Testing.md).
143 ## Documentation Pages
145 The [Nominatim documentation](https://nominatim.org/release-docs/develop/) is
146 built using the [MkDocs](https://www.mkdocs.org/) static site generation
147 framework. The master branch is automatically deployed every night on
148 [https://nominatim.org/release-docs/develop/](https://nominatim.org/release-docs/develop/)
150 To build the documentation, go to the build directory and run
154 INFO - Cleaning site directory
155 INFO - Building documentation to directory: /home/vagrant/build/site-html
158 This runs `mkdocs build` plus extra transformation of some files and adds
159 symlinks (see `CMakeLists.txt` for the exact steps).
161 Now you can start webserver for local testing
164 build> make serve-doc
165 [server:296] Serving on http://127.0.0.1:8000
166 [handlers:62] Start watching changes
169 If you develop inside a Vagrant virtual machine, use a port that is forwarded
173 build> PYTHONPATH=$SRCDIR mkdocs serve --dev-addr 0.0.0.0:8088
174 [server:296] Serving on http://0.0.0.0:8088
175 [handlers:62] Start watching changes