makefile.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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 OK
  42. PYENV [install] pip install -e 'searx[test]'
  43. ...
  44. Successfully installed argparse-1.4.0 searx
  45. BUILDENV INFO:searx:load the default settings from ./searx/settings.yml
  46. BUILDENV INFO:searx:Initialisation done
  47. BUILDENV build utils/brand.env
  48. If you release ``make install`` multiple times the installation will only
  49. rebuild if the sha256 sum of the *requirement files* fails. With other words:
  50. the check fails if you edit the requirements listed in
  51. :origin:`requirements-dev.txt` and :origin:`requirements.txt`). ::
  52. $ make install
  53. PYENV OK
  54. PYENV [virtualenv] requirements.sha256 failed
  55. [virtualenv] - 6cea6eb6def9e14a18bf32f8a3e... ./requirements-dev.txt
  56. [virtualenv] - 471efef6c73558e391c3adb35f4... ./requirements.txt
  57. ...
  58. PYENV [virtualenv] installing ./requirements*.txt into local/py3
  59. ...
  60. PYENV OK
  61. PYENV [install] pip install -e 'searx[test]'
  62. ...
  63. Successfully installed argparse-1.4.0 searx
  64. BUILDENV INFO:searx:load the default settings from ./searx/settings.yml
  65. BUILDENV INFO:searx:Initialisation done
  66. BUILDENV build utils/brand.env
  67. .. sidebar:: drop environment
  68. To get rid of the existing environment before re-build use :ref:`clean target
  69. <make clean>` first.
  70. If you think, something goes wrong with your ./local environment or you change
  71. the :origin:`setup.py` file, you have to call :ref:`make clean`.
  72. .. _make buildenv:
  73. ``make buildenv``
  74. =================
  75. Rebuild instance's environment with the modified settings from the
  76. :ref:`settings brand` and :ref:`settings server` section of your
  77. :ref:`settings.yml <settings location>`.
  78. What is the :origin:`utils/brand.env` needed for and why do you need to rebuild
  79. it if necessary?
  80. Short answer: :ref:`installation and maintenance <searxng maintenance>`
  81. scripts are running outside of instance's runtime environment and need some
  82. values defined in the runtime environment.
  83. All the SearXNG setups are centralized in the :ref:`settings.yml` file. This
  84. setup is available as long we are in a *installed instance*. E.g. the
  85. *installed instance* on the server or the *installed developer instance* at
  86. ``./local`` (the later one is created by a :ref:`make install <make install>` or
  87. :ref:`make run <make run>`).
  88. Tasks running outside of an *installed instance*, especially :ref:`installation
  89. and maintenance <searxng maintenance>` tasks running at (pre-) installation time
  90. do not have access to the SearXNG setup (from a *installed instance*). Those
  91. tasks need a *build environment*.
  92. The ``make buildenv`` target will update the *build environment* in:
  93. - :origin:`utils/brand.env`
  94. Tasks running outside of an *installed instance*, need the following settings
  95. from the YAML configuration:
  96. - ``SEARXNG_URL`` from :ref:`server.base_url <settings server>` (aka
  97. ``PUBLIC_URL``)
  98. - ``SEARXNG_BIND_ADDRESS`` from :ref:`server.bind_address <settings server>`
  99. - ``SEARXNG_PORT`` from :ref:`server.port <settings server>`
  100. The ``GIT_URL`` and ``GIT_BRANCH`` in the origin:`utils/brand.env` file, are
  101. read from the git VCS and the branch that is checked out when ``make
  102. buildenv`` command runs.
  103. .. _brand:
  104. **I would like to create my own brand, how should I proceed?**
  105. Create a remote branch (``example.org``), checkout the remote branch (on your
  106. local developer desktop) and in the :origin:`searx/settings.yml` file in the
  107. :ref:`settings server` section set ``base_url``. Run ``make buildenv`` and
  108. create a commit for your brand.
  109. On your server you clone the branch (``example.org``) into your HOME folder
  110. ``~`` from where you run the :ref:`installation <installation>` and
  111. :ref:`maintenance <searxng maintenance>` task.
  112. To upgrade you brand, rebase on SearXNG's master branch (on your local
  113. developer desktop), force push it to your remote branch. Go to your server, do
  114. a force pull and run :ref:`sudo -H ./utils/searxng.sh instance update <update
  115. searxng>`.
  116. .. _make node.env:
  117. Node.js environment (``make node.env``)
  118. =======================================
  119. .. _Node.js: https://nodejs.org/
  120. .. _nvm: https://github.com/nvm-sh
  121. .. _npm: https://www.npmjs.com/
  122. .. jinja:: searx
  123. Node.js_ version {{version.node}} or higher is required to build the themes.
  124. If the requirement is not met, the build chain uses nvm_ (Node Version
  125. Manager) to install latest LTS of Node.js_ locally: there is no need to
  126. install nvm_ or npm_ on your system.
  127. To install NVM_ and Node.js_ in once you can use :ref:`make nvm.nodejs`.
  128. .. _make nvm:
  129. NVM ``make nvm.install nvm.status``
  130. -----------------------------------
  131. Use ``make nvm.status`` to get the current status of your Node.js_ and nvm_
  132. setup.
  133. .. tabs::
  134. .. group-tab:: nvm.install
  135. .. code:: sh
  136. $ LANG=C make nvm.install
  137. INFO: install (update) NVM at ./searxng/.nvm
  138. INFO: clone: https://github.com/nvm-sh/nvm.git
  139. || Cloning into './searxng/.nvm'...
  140. INFO: checkout v0.39.4
  141. || HEAD is now at 8fbf8ab v0.39.4
  142. .. group-tab:: nvm.status (ubu2004)
  143. Here is the output you will typically get on a Ubuntu 20.04 system which
  144. serves only a `no longer active <https://nodejs.org/en/about/releases/>`_
  145. Release `Node.js v10.19.0 <https://packages.ubuntu.com/focal/nodejs>`_.
  146. .. code:: sh
  147. $ make nvm.status
  148. INFO: Node.js is installed at /usr/bin/node
  149. INFO: Node.js is version v10.19.0
  150. WARN: minimal Node.js version is 16.13.0
  151. INFO: npm is installed at /usr/bin/npm
  152. INFO: npm is version 6.14.4
  153. WARN: NVM is not installed
  154. .. _make nvm.nodejs:
  155. ``make nvm.nodejs``
  156. -------------------
  157. Install latest Node.js_ LTS locally (uses nvm_)::
  158. $ make nvm.nodejs
  159. INFO: install (update) NVM at /share/searxng/.nvm
  160. INFO: clone: https://github.com/nvm-sh/nvm.git
  161. ...
  162. Downloading and installing node v16.13.0...
  163. ...
  164. INFO: Node.js is installed at searxng/.nvm/versions/node/v16.13.0/bin/node
  165. INFO: Node.js is version v16.13.0
  166. INFO: npm is installed at searxng/.nvm/versions/node/v16.13.0/bin/npm
  167. INFO: npm is version 8.1.0
  168. INFO: NVM is installed at searxng/.nvm
  169. .. _make run:
  170. ``make run``
  171. ============
  172. To get up a running a developer instance simply call ``make run``. This enables
  173. *debug* option in :origin:`searx/settings.yml`, starts a ``./searx/webapp.py``
  174. instance and opens the URL in your favorite WEB browser (:man:`xdg-open`)::
  175. $ make run
  176. Changes to theme's HTML templates (jinja2) are instant. Changes to the CSS & JS
  177. sources of the theme need to be rebuild. You can do that by running::
  178. $ make themes.all
  179. Alternatively to ``themes.all`` you can run *live builds* of the theme you are
  180. modify (:ref:`make themes`)::
  181. $ LIVE_THEME=simple make run
  182. .. _make format.python:
  183. ``make format.python``
  184. ======================
  185. Format Python sourcee code using `Black code style`_. See ``$BLACK_OPTIONS``
  186. and ``$BLACK_TARGETS`` in :origin:`Makefile`.
  187. .. attention::
  188. We stuck at Black 22.12.0, please read comment in PR `Bump black from 22.12.0
  189. to 23.1.0`_
  190. .. _Bump black from 22.12.0 to 23.1.0:
  191. https://github.com/searxng/searxng/pull/2159#pullrequestreview-1284094735
  192. .. _Black code style:
  193. https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html
  194. .. _make clean:
  195. ``make clean``
  196. ==============
  197. Drops all intermediate files, all builds, but keep sources untouched. Before
  198. calling ``make clean`` stop all processes using the :ref:`make install` or
  199. :ref:`make node.env`. ::
  200. $ make clean
  201. CLEAN pyenv
  202. PYENV [virtualenv] drop local/py3
  203. CLEAN docs -- build/docs dist/docs
  204. CLEAN themes -- locally installed npm dependencies
  205. ...
  206. CLEAN test stuff
  207. CLEAN common files
  208. .. _make docs:
  209. ``make docs``
  210. =============
  211. Target ``docs`` builds the documentation:
  212. .. code:: bash
  213. $ make docs
  214. HTML ./docs --> file://
  215. DOCS build build/docs/includes
  216. ...
  217. The HTML pages are in dist/docs.
  218. .. _make docs.clean:
  219. ``make docs.clean docs.live``
  220. ----------------------------------
  221. We describe the usage of the ``doc.*`` targets in the :ref:`How to contribute /
  222. Documentation <contrib docs>` section. If you want to edit the documentation
  223. read our :ref:`make docs.live` section. If you are working in your own brand,
  224. adjust your :ref:`settings brand`.
  225. .. _make docs.gh-pages:
  226. ``make docs.gh-pages``
  227. ----------------------
  228. To deploy on github.io first adjust your :ref:`settings brand`. For any
  229. further read :ref:`deploy on github.io`.
  230. .. _make test:
  231. ``make test``
  232. =============
  233. Runs a series of tests: :ref:`make test.pylint`, ``test.pep8``, ``test.unit``
  234. and ``test.robot``. You can run tests selective, e.g.::
  235. $ make test.pep8 test.unit test.shell
  236. TEST test.pep8 OK
  237. ...
  238. TEST test.unit OK
  239. ...
  240. TEST test.shell OK
  241. .. _make test.shell:
  242. ``make test.shell``
  243. -------------------
  244. :ref:`sh lint` / if you have changed some bash scripting run this test before
  245. commit.
  246. .. _make test.pylint:
  247. ``make test.pylint``
  248. --------------------
  249. .. _Pylint: https://www.pylint.org/
  250. Pylint_ is known as one of the best source-code, bug and quality checker for the
  251. Python programming language. The pylint profile used in the SearXNG project is
  252. found in project's root folder :origin:`.pylintrc`.
  253. .. _make search.checker:
  254. ``make search.checker.{engine name}``
  255. =====================================
  256. To check all engines::
  257. make search.checker
  258. To check a engine with whitespace in the name like *google news* replace space
  259. by underline::
  260. make search.checker.google_news
  261. To see HTTP requests and more use SEARXNG_DEBUG::
  262. make SEARXNG_DEBUG=1 search.checker.google_news
  263. .. _3xx: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection
  264. To filter out HTTP redirects (3xx_)::
  265. make SEARXNG_DEBUG=1 search.checker.google_news | grep -A1 "HTTP/1.1\" 3[0-9][0-9]"
  266. ...
  267. Engine google news Checking
  268. 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
  269. 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
  270. --
  271. 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
  272. 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
  273. --
  274. .. _make themes:
  275. ``make themes.*``
  276. =================
  277. .. sidebar:: further read
  278. - :ref:`devquickstart`
  279. The :origin:`Makefile` targets ``make theme.*`` cover common tasks to build the
  280. theme(s). The ``./manage themes.*`` command line can be used to convenient run
  281. common theme build tasks.
  282. .. program-output:: bash -c "cd ..; ./manage themes.help"
  283. To get live builds while modifying CSS & JS use (:ref:`make run`):
  284. .. code:: sh
  285. $ LIVE_THEME=simple make run
  286. .. _make static.build:
  287. ``make static.build.*``
  288. =======================
  289. .. sidebar:: further read
  290. - :ref:`devquickstart`
  291. The :origin:`Makefile` targets ``static.build.*`` cover common tasks to build (a
  292. commit of) the static files. The ``./manage static.build..*`` command line
  293. can be used to convenient run common build tasks of the static files.
  294. .. program-output:: bash -c "cd ..; ./manage static.help"
  295. .. _manage redis.help:
  296. ``./manage redis.help``
  297. =======================
  298. The ``./manage redis.*`` command line can be used to convenient run common Redis
  299. tasks (:ref:`Redis developer notes`).
  300. .. program-output:: bash -c "cd ..; ./manage redis.help"
  301. .. _manage go.help:
  302. ``./manage go.help``
  303. ====================
  304. The ``./manage go.*`` command line can be used to convenient run common `go
  305. (wiki)`_ tasks.
  306. .. _go (wiki): https://en.wikipedia.org/wiki/Go_(programming_language)
  307. .. program-output:: bash -c "cd ..; ./manage go.help"