]> git.openstreetmap.org Git - nominatim.git/blob - docs/develop/Development-Environment.md
work around strange query planning behaviour
[nominatim.git] / docs / develop / Development-Environment.md
1 # Setting up Nominatim for Development
2
3 This chapter gives an overview how to set up Nominatim for development
4 and how to run tests.
5
6 !!! Important
7     This guide assumes that you develop under the latest version of Ubuntu. You
8     can of course also use your favourite distribution. You just might have to
9     adapt the commands below slightly, in particular the commands for installing
10     additional software.
11
12 ## Installing Nominatim
13
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 is included with PHP
17 is sufficient.
18
19 If you want to run Nominatim in a VM via Vagrant, use the default `ubuntu` 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:
23
24     sudo apt install vagrant vagrant-libvirt libvirt-daemon nfs-kernel-server
25
26 ## Prerequisites for testing and documentation
27
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:
31
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)
40
41 For testing the Python search frontend, you need to install extra dependencies
42 depending on your choice of webserver framework:
43
44 * [httpx](https://www.python-httpx.org/) (starlette only)
45 * [asgi-lifespan](https://github.com/florimondmanca/asgi-lifespan) (starlette only)
46
47 The documentation is built with mkdocs:
48
49 * [mkdocs](https://www.mkdocs.org/) >= 1.1.2
50 * [mkdocstrings](https://mkdocstrings.github.io/) >= 0.18
51 * [mkdocstrings-python](https://mkdocstrings.github.io/python/)
52
53 ### Installing prerequisites on Ubuntu/Debian
54
55 Some of the Python packages require the newest version which is not yet
56 available with the current distributions. Therefore it is recommended to
57 install pip to get the newest versions.
58
59 To install all necessary packages run:
60
61 ```sh
62 sudo apt install php-cgi phpunit php-codesniffer \
63                  python3-pip python3-setuptools python3-dev
64
65 pip3 install --user behave mkdocs mkdocstrings pytest pytest-asyncio pylint \
66                     mypy types-PyYAML types-jinja2 types-psycopg2 types-psutil \
67                     types-ujson types-requests types-Pygments typing-extensions\
68                     httpx asgi-lifespan
69 ```
70
71 The `mkdocs` executable will be located in `.local/bin`. You may have to add
72 this directory to your path, for example by running:
73
74 ```
75 echo 'export PATH=~/.local/bin:$PATH' > ~/.profile
76 ```
77
78 If your distribution does not have PHPUnit 7.3+, you can install it (as well
79 as CodeSniffer) via composer:
80
81 ```
82 sudo apt-get install composer
83 composer global require "squizlabs/php_codesniffer=*"
84 composer global require "phpunit/phpunit=8.*"
85 ```
86
87 The binaries are found in `.config/composer/vendor/bin`. You need to add this
88 to your PATH as well:
89
90 ```
91 echo 'export PATH=~/.config/composer/vendor/bin:$PATH' > ~/.profile
92 ```
93
94
95 ## Executing Tests
96
97 All tests are located in the `/test` directory.
98
99 To run all tests just go to the build directory and run make:
100
101 ```sh
102 cd build
103 make test
104 ```
105
106 For more information about the structure of the tests and how to change and
107 extend the test suite, see the [Testing chapter](Testing.md).
108
109 ## Documentation Pages
110
111 The [Nominatim documentation](https://nominatim.org/release-docs/develop/) is
112 built using the [MkDocs](https://www.mkdocs.org/) static site generation
113 framework. The master branch is automatically deployed every night on
114 [https://nominatim.org/release-docs/develop/](https://nominatim.org/release-docs/develop/)
115
116 To build the documentation, go to the build directory and run
117
118 ```
119 make doc
120 INFO - Cleaning site directory
121 INFO - Building documentation to directory: /home/vagrant/build/site-html
122 ```
123
124 This runs `mkdocs build` plus extra transformation of some files and adds
125 symlinks (see `CMakeLists.txt` for the exact steps).
126
127 Now you can start webserver for local testing
128
129 ```
130 build> make serve-doc
131 [server:296] Serving on http://127.0.0.1:8000
132 [handlers:62] Start watching changes
133 ```
134
135 If you develop inside a Vagrant virtual machine, use a port that is forwarded
136 to your host:
137
138 ```
139 build> PYTHONPATH=$SRCDIR mkdocs serve --dev-addr 0.0.0.0:8088
140 [server:296] Serving on http://0.0.0.0:8088
141 [handlers:62] Start watching changes
142 ```