makefile.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. ..
  128. ToDo: vite server is not implemented yet / will be done in a follow up PR
  129. Alternatively to ``themes.all`` you can run *live builds* of the theme you are
  130. modify (:ref:`make themes`)::
  131. $ LIVE_THEME=simple make run
  132. .. _make format:
  133. ``make format``
  134. ======================
  135. .. _Black code style:
  136. https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html
  137. .. _shfmt: https://github.com/mvdan/sh?tab=readme-ov-file#shfmt
  138. .. _EditorConfig: https://github.com/patrickvane/shfmt?tab=readme-ov-file#description
  139. - Format Python source code using `Black code style`_. See ``$BLACK_OPTIONS``
  140. and ``$BLACK_TARGETS`` in :origin:`Makefile`.
  141. - Format Shell scripts using shfmt_. The formatter ``shfmt`` reads the rules
  142. from the EditorConfig_ files.
  143. .. _make clean:
  144. ``make clean``
  145. ==============
  146. Drops all intermediate files, all builds, but keep sources untouched. Before
  147. calling ``make clean`` stop all processes using the :ref:`make install` or
  148. :ref:`make node.env`. ::
  149. $ make clean
  150. CLEAN pyenv
  151. PYENV [virtualenv] drop local/py3
  152. CLEAN docs -- build/docs dist/docs
  153. CLEAN themes -- locally installed npm dependencies
  154. ...
  155. CLEAN test stuff
  156. CLEAN common files
  157. .. _make docs:
  158. ``make docs``
  159. =============
  160. Target ``docs`` builds the documentation:
  161. .. code:: bash
  162. $ make docs
  163. HTML ./docs --> file://
  164. DOCS build build/docs/includes
  165. ...
  166. The HTML pages are in dist/docs.
  167. .. _make docs.clean:
  168. ``make docs.clean docs.live``
  169. ----------------------------------
  170. We describe the usage of the ``doc.*`` targets in the :ref:`How to contribute /
  171. Documentation <contrib docs>` section. If you want to edit the documentation
  172. read our :ref:`make docs.live` section. If you are working in your own brand,
  173. adjust your :ref:`settings brand`.
  174. .. _make docs.gh-pages:
  175. ``make docs.gh-pages``
  176. ----------------------
  177. To deploy on github.io first adjust your :ref:`settings brand`. For any
  178. further read :ref:`deploy on github.io`.
  179. .. _make test:
  180. ``make test``
  181. =============
  182. Runs a series of tests: :ref:`make test.pylint`, ``test.pep8``, ``test.unit``
  183. and ``test.robot``. You can run tests selective, e.g.::
  184. $ make test.pep8 test.unit test.shell
  185. TEST test.pep8 OK
  186. ...
  187. TEST test.unit OK
  188. ...
  189. TEST test.shell OK
  190. .. _make test.shell:
  191. ``make test.shell``
  192. -------------------
  193. :ref:`sh lint` / if you have changed some bash scripting run this test before
  194. commit.
  195. .. _make test.pylint:
  196. ``make test.pylint``
  197. --------------------
  198. .. _Pylint: https://www.pylint.org/
  199. Pylint_ is known as one of the best source-code, bug and quality checker for the
  200. Python programming language. The pylint profile used in the SearXNG project is
  201. found in project's root folder :origin:`.pylintrc`.
  202. .. _make search.checker:
  203. ``make search.checker.{engine name}``
  204. =====================================
  205. To check all engines::
  206. make search.checker
  207. To check a engine with whitespace in the name like *google news* replace space
  208. by underline::
  209. make search.checker.google_news
  210. To see HTTP requests and more use SEARXNG_DEBUG::
  211. make SEARXNG_DEBUG=1 search.checker.google_news
  212. .. _3xx: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection
  213. To filter out HTTP redirects (3xx_)::
  214. make SEARXNG_DEBUG=1 search.checker.google_news | grep -A1 "HTTP/1.1\" 3[0-9][0-9]"
  215. ...
  216. Engine google news Checking
  217. 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
  218. 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
  219. --
  220. 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
  221. 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
  222. --
  223. .. _make themes:
  224. ``make themes.*``
  225. =================
  226. .. sidebar:: further read
  227. - :ref:`devquickstart`
  228. The :origin:`Makefile` targets ``make theme.*`` cover common tasks to build the
  229. theme(s). The ``./manage themes.*`` command line can be used to convenient run
  230. common theme build tasks.
  231. .. program-output:: bash -c "cd ..; ./manage themes.help"
  232. To get live builds while modifying CSS & JS use (:ref:`make run`):
  233. .. code:: sh
  234. $ LIVE_THEME=simple make run
  235. .. _make static.build:
  236. ``make static.build.*``
  237. =======================
  238. .. sidebar:: further read
  239. - :ref:`devquickstart`
  240. The :origin:`Makefile` targets ``static.build.*`` cover common tasks to build (a
  241. commit of) the static files. The ``./manage static.build..*`` command line
  242. can be used to convenient run common build tasks of the static files.
  243. .. program-output:: bash -c "cd ..; ./manage static.help"
  244. .. _manage go.help:
  245. ``./manage go.help``
  246. ====================
  247. The ``./manage go.*`` command line can be used to convenient run common `go
  248. (wiki)`_ tasks.
  249. .. _go (wiki): https://en.wikipedia.org/wiki/Go_(programming_language)
  250. .. program-output:: bash -c "cd ..; ./manage go.help"