makefile.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. .. _makefile:
  2. =======================
  3. Makefile & ``./manage``
  4. =======================
  5. .. _gnu-make: https://www.gnu.org/software/make/manual/make.html#Introduction
  6. All relevant build and development tasks are implemented in the
  7. :origin:`./manage <manage>` script and for CI or IDE integration a small
  8. :origin:`Makefile` wrapper is available. If you are not familiar with
  9. Makefiles, we recommend to read gnu-make_ introduction.
  10. .. sidebar:: build environment
  11. Before looking deeper at the targets, first read about :ref:`make
  12. install`.
  13. To install developer requirements follow :ref:`buildhosts`.
  14. .. contents::
  15. :depth: 2
  16. :local:
  17. :backlinks: entry
  18. The usage is simple, just type ``make {target-name}`` to *build* a target.
  19. Calling the ``help`` target gives a first overview (``make help``):
  20. .. tabs::
  21. .. group-tab:: ``make``
  22. .. program-output:: bash -c "cd ..; make --no-print-directory help"
  23. .. group-tab:: ``./manage``
  24. The Makefile targets are implemented for comfort, if you can do without
  25. tab-completion and need to have a more granular control, use
  26. :origin:`manage` without the Makefile wrappers.
  27. .. code:: sh
  28. $ ./manage help
  29. .. _make install:
  30. Python environment (``make install``)
  31. =====================================
  32. .. sidebar:: activate environment
  33. ``source ./local/py3/bin/activate``
  34. We do no longer need to build up the virtualenv manually. Jump into your git
  35. working tree and release a ``make install`` to get a virtualenv with a
  36. *developer install* of SearXNG (:origin:`setup.py`). ::
  37. $ cd ~/searxng-clone
  38. $ make install
  39. PYENV [virtualenv] installing ./requirements*.txt into local/py3
  40. ...
  41. PYENV [install] pip install --use-pep517 --no-build-isolation -e 'searx[test]'
  42. ...
  43. Successfully installed searxng-2023.7.19+a446dea1b
  44. If you release ``make install`` multiple times the installation will only
  45. rebuild if the sha256 sum of the *requirement files* fails. With other words:
  46. the check fails if you edit the requirements listed in
  47. :origin:`requirements-dev.txt` and :origin:`requirements.txt`). ::
  48. $ make install
  49. PYENV OK
  50. PYENV [virtualenv] requirements.sha256 failed
  51. [virtualenv] - 6cea6eb6def9e14a18bf32f8a3e... ./requirements-dev.txt
  52. [virtualenv] - 471efef6c73558e391c3adb35f4... ./requirements.txt
  53. ...
  54. PYENV [virtualenv] installing ./requirements*.txt into local/py3
  55. ...
  56. PYENV [install] pip install --use-pep517 --no-build-isolation -e 'searx[test]'
  57. ...
  58. Successfully installed searxng-2023.7.19+a446dea1b
  59. .. sidebar:: drop environment
  60. To get rid of the existing environment before re-build use :ref:`clean target
  61. <make clean>` first.
  62. If you think, something goes wrong with your ./local environment or you change
  63. the :origin:`setup.py` file, you have to call :ref:`make clean`.
  64. .. _make node.env:
  65. Node.js environment (``make node.env``)
  66. =======================================
  67. .. _Node.js: https://nodejs.org/
  68. .. _nvm: https://github.com/nvm-sh
  69. .. _npm: https://www.npmjs.com/
  70. .. jinja:: searx
  71. Node.js_ version {{version.node}} or higher is required to build the themes.
  72. If the requirement is not met, the build chain uses nvm_ (Node Version
  73. Manager) to install latest LTS of Node.js_ locally: there is no need to
  74. install nvm_ or npm_ on your system.
  75. To install NVM_ and Node.js_ in once you can use :ref:`make nvm.nodejs`.
  76. .. _make nvm:
  77. NVM ``make nvm.install nvm.status``
  78. -----------------------------------
  79. Use ``make nvm.status`` to get the current status of your Node.js_ and nvm_
  80. setup.
  81. .. tabs::
  82. .. group-tab:: nvm.install
  83. .. code:: sh
  84. $ LANG=C make nvm.install
  85. INFO: install (update) NVM at ./searxng/.nvm
  86. INFO: clone: https://github.com/nvm-sh/nvm.git
  87. || Cloning into './searxng/.nvm'...
  88. INFO: checkout v0.39.4
  89. || HEAD is now at 8fbf8ab v0.39.4
  90. .. group-tab:: nvm.status (ubu2004)
  91. Here is the output you will typically get on a Ubuntu 20.04 system which
  92. serves only a `no longer active <https://nodejs.org/en/about/releases/>`_
  93. Release `Node.js v10.19.0 <https://packages.ubuntu.com/focal/nodejs>`_.
  94. .. code:: sh
  95. $ make nvm.status
  96. INFO: Node.js is installed at /usr/bin/node
  97. INFO: Node.js is version v10.19.0
  98. WARN: minimal Node.js version is 16.13.0
  99. INFO: npm is installed at /usr/bin/npm
  100. INFO: npm is version 6.14.4
  101. WARN: NVM is not installed
  102. .. _make nvm.nodejs:
  103. ``make nvm.nodejs``
  104. -------------------
  105. Install latest Node.js_ LTS locally (uses nvm_)::
  106. $ make nvm.nodejs
  107. INFO: install (update) NVM at /share/searxng/.nvm
  108. INFO: clone: https://github.com/nvm-sh/nvm.git
  109. ...
  110. Downloading and installing node v16.13.0...
  111. ...
  112. INFO: Node.js is installed at searxng/.nvm/versions/node/v16.13.0/bin/node
  113. INFO: Node.js is version v16.13.0
  114. INFO: npm is installed at searxng/.nvm/versions/node/v16.13.0/bin/npm
  115. INFO: npm is version 8.1.0
  116. INFO: NVM is installed at searxng/.nvm
  117. .. _make run:
  118. ``make run``
  119. ============
  120. To get up a running a developer instance simply call ``make run``. This enables
  121. *debug* option in :origin:`searx/settings.yml`, starts a ``./searx/webapp.py``
  122. instance and opens the URL in your favorite WEB browser (:man:`xdg-open`)::
  123. $ make run
  124. Changes to theme's HTML templates (jinja2) are instant. Changes to the CSS & JS
  125. sources of the theme need to be rebuild. You can do that by running::
  126. $ make themes.all
  127. Alternatively to ``themes.all`` you can run *live builds* of the theme you are
  128. modify (:ref:`make themes`)::
  129. $ LIVE_THEME=simple make run
  130. .. _make format.python:
  131. ``make format.python``
  132. ======================
  133. Format Python source code using `Black code style`_. See ``$BLACK_OPTIONS``
  134. and ``$BLACK_TARGETS`` in :origin:`Makefile`.
  135. .. attention::
  136. We stuck at Black 22.12.0, please read comment in PR `Bump black from 22.12.0
  137. to 23.1.0`_
  138. .. _Bump black from 22.12.0 to 23.1.0:
  139. https://github.com/searxng/searxng/pull/2159#pullrequestreview-1284094735
  140. .. _Black code style:
  141. https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html
  142. .. _make clean:
  143. ``make clean``
  144. ==============
  145. Drops all intermediate files, all builds, but keep sources untouched. Before
  146. calling ``make clean`` stop all processes using the :ref:`make install` or
  147. :ref:`make node.env`. ::
  148. $ make clean
  149. CLEAN pyenv
  150. PYENV [virtualenv] drop local/py3
  151. CLEAN docs -- build/docs dist/docs
  152. CLEAN themes -- locally installed npm dependencies
  153. ...
  154. CLEAN test stuff
  155. CLEAN common files
  156. .. _make docs:
  157. ``make docs``
  158. =============
  159. Target ``docs`` builds the documentation:
  160. .. code:: bash
  161. $ make docs
  162. HTML ./docs --> file://
  163. DOCS build build/docs/includes
  164. ...
  165. The HTML pages are in dist/docs.
  166. .. _make docs.clean:
  167. ``make docs.clean docs.live``
  168. ----------------------------------
  169. We describe the usage of the ``doc.*`` targets in the :ref:`How to contribute /
  170. Documentation <contrib docs>` section. If you want to edit the documentation
  171. read our :ref:`make docs.live` section. If you are working in your own brand,
  172. adjust your :ref:`settings brand`.
  173. .. _make docs.gh-pages:
  174. ``make docs.gh-pages``
  175. ----------------------
  176. To deploy on github.io first adjust your :ref:`settings brand`. For any
  177. further read :ref:`deploy on github.io`.
  178. .. _make test:
  179. ``make test``
  180. =============
  181. Runs a series of tests: :ref:`make test.pylint`, ``test.pep8``, ``test.unit``
  182. and ``test.robot``. You can run tests selective, e.g.::
  183. $ make test.pep8 test.unit test.shell
  184. TEST test.pep8 OK
  185. ...
  186. TEST test.unit OK
  187. ...
  188. TEST test.shell OK
  189. .. _make test.shell:
  190. ``make test.shell``
  191. -------------------
  192. :ref:`sh lint` / if you have changed some bash scripting run this test before
  193. commit.
  194. .. _make test.pylint:
  195. ``make test.pylint``
  196. --------------------
  197. .. _Pylint: https://www.pylint.org/
  198. Pylint_ is known as one of the best source-code, bug and quality checker for the
  199. Python programming language. The pylint profile used in the SearXNG project is
  200. found in project's root folder :origin:`.pylintrc`.
  201. .. _make search.checker:
  202. ``make search.checker.{engine name}``
  203. =====================================
  204. To check all engines::
  205. make search.checker
  206. To check a engine with whitespace in the name like *google news* replace space
  207. by underline::
  208. make search.checker.google_news
  209. To see HTTP requests and more use SEARXNG_DEBUG::
  210. make SEARXNG_DEBUG=1 search.checker.google_news
  211. .. _3xx: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection
  212. To filter out HTTP redirects (3xx_)::
  213. make SEARXNG_DEBUG=1 search.checker.google_news | grep -A1 "HTTP/1.1\" 3[0-9][0-9]"
  214. ...
  215. Engine google news Checking
  216. https://news.google.com:443 "GET /search?q=life&hl=en&lr=lang_en&ie=utf8&oe=utf8&ceid=US%3Aen&gl=US HTTP/1.1" 302 0
  217. https://news.google.com:443 "GET /search?q=life&hl=en-US&lr=lang_en&ie=utf8&oe=utf8&ceid=US:en&gl=US HTTP/1.1" 200 None
  218. --
  219. https://news.google.com:443 "GET /search?q=computer&hl=en&lr=lang_en&ie=utf8&oe=utf8&ceid=US%3Aen&gl=US HTTP/1.1" 302 0
  220. https://news.google.com:443 "GET /search?q=computer&hl=en-US&lr=lang_en&ie=utf8&oe=utf8&ceid=US:en&gl=US HTTP/1.1" 200 None
  221. --
  222. .. _make themes:
  223. ``make themes.*``
  224. =================
  225. .. sidebar:: further read
  226. - :ref:`devquickstart`
  227. The :origin:`Makefile` targets ``make theme.*`` cover common tasks to build the
  228. theme(s). The ``./manage themes.*`` command line can be used to convenient run
  229. common theme build tasks.
  230. .. program-output:: bash -c "cd ..; ./manage themes.help"
  231. To get live builds while modifying CSS & JS use (:ref:`make run`):
  232. .. code:: sh
  233. $ LIVE_THEME=simple make run
  234. .. _make static.build:
  235. ``make static.build.*``
  236. =======================
  237. .. sidebar:: further read
  238. - :ref:`devquickstart`
  239. The :origin:`Makefile` targets ``static.build.*`` cover common tasks to build (a
  240. commit of) the static files. The ``./manage static.build..*`` command line
  241. can be used to convenient run common build tasks of the static files.
  242. .. program-output:: bash -c "cd ..; ./manage static.help"
  243. .. _manage redis.help:
  244. ``./manage redis.help``
  245. =======================
  246. The ``./manage redis.*`` command line can be used to convenient run common Redis
  247. tasks (:ref:`Redis developer notes`).
  248. .. program-output:: bash -c "cd ..; ./manage redis.help"
  249. .. _manage go.help:
  250. ``./manage go.help``
  251. ====================
  252. The ``./manage go.*`` command line can be used to convenient run common `go
  253. (wiki)`_ tasks.
  254. .. _go (wiki): https://en.wikipedia.org/wiki/Go_(programming_language)
  255. .. program-output:: bash -c "cd ..; ./manage go.help"