]> git.openstreetmap.org Git - nominatim.git/blob - docs/develop/Development-Environment.md
Merge pull request #2139 from lonvia/add-pytest
[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 developement
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.5
33 * [phpunit](https://phpunit.de) >= 7.3
34 * [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
35 * [Pylint](https://pylint.org/) (2.6.0 is used for the CI)
36 * [pytest](https://pytest.org)
37
38 The documentation is built with mkdocs:
39
40 * [mkdocs](https://www.mkdocs.org/) >= 1.1.2
41
42 ### Installing prerequisites on Ubuntu/Debian
43
44 Some of the Python packages require the newest version which is not yet
45 available with the current distributions. Therefore it is recommended to
46 install pip to get the newest versions.
47
48 To install all necessary packages run:
49
50 ```sh
51 sudo apt install php-cgi phpunit php-codesniffer \
52                  python3-pip python3-setuptools python3-dev pylint
53
54 pip3 install --user behave mkdocs pytest
55 ```
56
57 The `mkdocs` executable will be located in `.local/bin`. You may have to add
58 this directory to your path, for example by running:
59
60 ```
61 echo 'export PATH=~/.local/bin:$PATH' > ~/.profile
62 ```
63
64 If your distribution does not have PHPUnit 7.3+, you can install it (as well
65 as CodeSniffer) via composer:
66
67 ```
68 sudo apt-get install composer
69 composer global require "squizlabs/php_codesniffer=*"
70 composer global require "phpunit/phpunit=8.*"
71 ```
72
73 The binaries are found in `.config/composer/vendor/bin`. You need to add this
74 to your PATH as well:
75
76 ```
77 echo 'export PATH=~/.config/composer/vendor/bin:$PATH' > ~/.profile
78 ```
79
80
81 ## Executing Tests
82
83 All tests are located in the `/test` directory.
84
85 To run all tests just go to the build directory and run make:
86
87 ```sh
88 cd build
89 make test
90 ```
91
92 For more information about the structure of the tests and how to change and
93 extend the test suite, see the [Testing chapter](Testing.md).
94
95 ## Documentation Pages
96
97 The [Nominatim documentation](https://nominatim.org/release-docs/develop/) is
98 built using the [MkDocs](https://www.mkdocs.org/) static site generation
99 framework. The master branch is automatically deployed every night on
100 [https://nominatim.org/release-docs/develop/](https://nominatim.org/release-docs/develop/)
101
102 To build the documentation, go to the build directory and run
103
104 ```
105 make doc
106 INFO - Cleaning site directory
107 INFO - Building documentation to directory: /home/vagrant/build/site-html
108 ```
109
110 This runs `mkdocs build` plus extra transformation of some files and adds
111 symlinks (see `CMakeLists.txt` for the exact steps).
112
113 Now you can start webserver for local testing
114
115 ```
116 build> mkdocs serve
117 [server:296] Serving on http://127.0.0.1:8000
118 [handlers:62] Start watching changes
119 ```
120
121 If you develop inside a Vagrant virtual machine, use a port that is forwarded
122 to your host:
123
124 ```
125 build> mkdocs serve --dev-addr 0.0.0.0:8088
126 [server:296] Serving on http://0.0.0.0:8088
127 [handlers:62] Start watching changes
128 ```