makefile.rst 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. .. _makefile:
  2. ========
  3. Makefile
  4. ========
  5. .. _gnu-make: https://www.gnu.org/software/make/manual/make.html#Introduction
  6. .. sidebar:: build environment
  7. Before looking deeper at the targets, first read about :ref:`make
  8. install`.
  9. To install system requirements follow :ref:`buildhosts`.
  10. All relevant build tasks are implemented in :origin:`manage` and for CI or
  11. IDE integration a small ``Makefile`` wrapper is available. If you are not
  12. familiar with Makefiles, we recommend to read gnu-make_ introduction.
  13. The usage is simple, just type ``make {target-name}`` to *build* a target.
  14. Calling the ``help`` target gives a first overview (``make help``):
  15. .. program-output:: bash -c "cd ..; make --no-print-directory help"
  16. .. contents:: Contents
  17. :depth: 2
  18. :local:
  19. :backlinks: entry
  20. .. _make install:
  21. Python environment (``make install``)
  22. =====================================
  23. .. sidebar:: activate environment
  24. ``source ./local/py3/bin/activate``
  25. We do no longer need to build up the virtualenv manually. Jump into your git
  26. working tree and release a ``make install`` to get a virtualenv with a
  27. *developer install* of SearXNG (:origin:`setup.py`). ::
  28. $ cd ~/searx-clone
  29. $ make install
  30. PYENV [virtualenv] installing ./requirements*.txt into local/py3
  31. ...
  32. PYENV OK
  33. PYENV [install] pip install -e 'searx[test]'
  34. ...
  35. Successfully installed argparse-1.4.0 searx
  36. BUILDENV INFO:searx:load the default settings from ./searx/settings.yml
  37. BUILDENV INFO:searx:Initialisation done
  38. BUILDENV build utils/brand.env
  39. If you release ``make install`` multiple times the installation will only
  40. rebuild if the sha256 sum of the *requirement files* fails. With other words:
  41. the check fails if you edit the requirements listed in
  42. :origin:`requirements-dev.txt` and :origin:`requirements.txt`). ::
  43. $ make install
  44. PYENV OK
  45. PYENV [virtualenv] requirements.sha256 failed
  46. [virtualenv] - 6cea6eb6def9e14a18bf32f8a3e... ./requirements-dev.txt
  47. [virtualenv] - 471efef6c73558e391c3adb35f4... ./requirements.txt
  48. ...
  49. PYENV [virtualenv] installing ./requirements*.txt into local/py3
  50. ...
  51. PYENV OK
  52. PYENV [install] pip install -e 'searx[test]'
  53. ...
  54. Successfully installed argparse-1.4.0 searx
  55. BUILDENV INFO:searx:load the default settings from ./searx/settings.yml
  56. BUILDENV INFO:searx:Initialisation done
  57. BUILDENV build utils/brand.env
  58. .. sidebar:: drop environment
  59. To get rid of the existing environment before re-build use :ref:`clean target
  60. <make clean>` first.
  61. If you think, something goes wrong with your ./local environment or you change
  62. the :origin:`setup.py` file, you have to call :ref:`make clean`.
  63. .. _make buildenv:
  64. ``make buildenv``
  65. =================
  66. Rebuild instance's environment with the modified settings from the
  67. :ref:`settings global brand` and :ref:`settings global server` section of your
  68. :ref:`settings.yml <settings location>`.
  69. We have all SearXNG setups are centralized in the :ref:`settings.yml` file.
  70. This setup is available as long we are in a *installed instance*. E.g. the
  71. *installed instance* on the server or the *installed developer instance* at
  72. ``./local`` (the later one is created by a :ref:`make install <make
  73. install>` or :ref:`make run <make run>`).
  74. Tasks running outside of an *installed instance*, especially those tasks and
  75. scripts running at (pre-) installation time do not have access to the SearXNG
  76. setup (from a *installed instance*). Those tasks need a *build environment*.
  77. The ``make buildenv`` target will update the *build environment* in:
  78. - :origin:`utils/brand.env`
  79. Tasks running outside of an *installed instance*, need the following settings
  80. from the YAML configuration:
  81. - ``SEARXNG_URL`` from :ref:`server.base_url <settings global server>` (aka
  82. ``PUBLIC_URL``)
  83. - ``SEARXNG_BIND_ADDRESS`` from :ref:`server.bind_address <settings global server>`
  84. - ``SEARXNG_PORT`` from :ref:`server.port <settings global server>`
  85. .. _make node.env:
  86. Node.js environment (``make node.env``)
  87. =======================================
  88. .. _Node.js: https://nodejs.org/
  89. .. _nvm: https://github.com/nvm-sh
  90. .. _npm: https://www.npmjs.com/
  91. .. jinja:: searx
  92. Node.js_ version {{version.node}} or higher is required to build the themes.
  93. If the requirement is not met, the build chain uses nvm_ (Node Version
  94. Manager) to install latest LTS of Node.js_ locally: there is no need to
  95. install nvm_ or npm_ on your system.
  96. Use ``make nvm.status`` to get the current status of you Node.js_ and nvm_ setup.
  97. Here is the output you will typically get on a Ubuntu 20.04 system which serves
  98. only a `no longer active <https://nodejs.org/en/about/releases/>`_ Release
  99. `Node.js v10.19.0 <https://packages.ubuntu.com/focal/nodejs>`_.
  100. ::
  101. $ make nvm.status
  102. INFO: Node.js is installed at /usr/bin/node
  103. INFO: Node.js is version v10.19.0
  104. WARN: minimal Node.js version is 16.13.0
  105. INFO: npm is installed at /usr/bin/npm
  106. INFO: npm is version 6.14.4
  107. WARN: NVM is not installed
  108. INFO: to install NVM and Node.js (LTS) use: manage nvm install --lts
  109. To install you can also use :ref:`make nvm.nodejs`
  110. .. _make nvm.nodejs:
  111. ``make nvm.nodejs``
  112. ===================
  113. Install latest Node.js_ LTS locally (uses nvm_)::
  114. $ make nvm.nodejs
  115. INFO: install (update) NVM at /share/searxng/.nvm
  116. INFO: clone: https://github.com/nvm-sh/nvm.git
  117. ...
  118. Downloading and installing node v16.13.0...
  119. ...
  120. INFO: Node.js is installed at searxng/.nvm/versions/node/v16.13.0/bin/node
  121. INFO: Node.js is version v16.13.0
  122. INFO: npm is installed at searxng/.nvm/versions/node/v16.13.0/bin/npm
  123. INFO: npm is version 8.1.0
  124. INFO: NVM is installed at searxng/.nvm
  125. .. _make run:
  126. ``make run``
  127. ============
  128. To get up a running a developer instance simply call ``make run``. This enables
  129. *debug* option in :origin:`searx/settings.yml`, starts a ``./searx/webapp.py``
  130. instance and opens the URL in your favorite WEB browser (:man:`xdg-open`)::
  131. $ make run
  132. Changes to theme's HTML templates (jinja2) are instant. Changes to the CSS & JS
  133. sources of the theme need to be rebuild. You can do that by running::
  134. $ make themes.all
  135. Alternatively to ``themes.all`` you can run *live builds* of the theme you are
  136. modify::
  137. $ LIVE_THEME=simple make run
  138. .. _make clean:
  139. ``make clean``
  140. ==============
  141. Drops all intermediate files, all builds, but keep sources untouched. Before
  142. calling ``make clean`` stop all processes using the :ref:`make install` or
  143. :ref:`make node.env`. ::
  144. $ make clean
  145. CLEAN pyenv
  146. PYENV [virtualenv] drop local/py3
  147. CLEAN docs -- build/docs dist/docs
  148. CLEAN themes -- locally installed npm dependencies
  149. ...
  150. CLEAN test stuff
  151. CLEAN common files
  152. .. _make docs:
  153. ``make docs docs.autobuild docs.clean``
  154. =======================================
  155. We describe the usage of the ``doc.*`` targets in the :ref:`How to contribute /
  156. Documentation <contrib docs>` section. If you want to edit the documentation
  157. read our :ref:`make docs.live` section. If you are working in your own brand,
  158. adjust your :ref:`settings global`.
  159. .. _make docs.gh-pages:
  160. ``make docs.gh-pages``
  161. ======================
  162. To deploy on github.io first adjust your :ref:`settings global`. For any
  163. further read :ref:`deploy on github.io`.
  164. .. _make test:
  165. ``make test``
  166. =============
  167. Runs a series of tests: :ref:`make test.pylint`, ``test.pep8``, ``test.unit``
  168. and ``test.robot``. You can run tests selective, e.g.::
  169. $ make test.pep8 test.unit test.sh
  170. TEST test.pep8 OK
  171. ...
  172. TEST test.unit OK
  173. ...
  174. TEST test.sh OK
  175. .. _make test.shell:
  176. ``make test.shell``
  177. ===================
  178. :ref:`sh lint` / if you have changed some bash scripting run this test before
  179. commit.
  180. .. _make test.pylint:
  181. ``make test.pylint``
  182. ====================
  183. .. _Pylint: https://www.pylint.org/
  184. Pylint_ is known as one of the best source-code, bug and quality checker for the
  185. Python programming language. The pylint profile used in the SearXNG project is
  186. found in project's root folder :origin:`.pylintrc`.
  187. .. _make search.checker:
  188. ``search.checker.{engine name}``
  189. ================================
  190. To check all engines::
  191. make search.checker
  192. To check a engine with whitespace in the name like *google news* replace space
  193. by underline::
  194. make search.checker.google_news
  195. To see HTTP requests and more use SEARXNG_DEBUG::
  196. make SEARXNG_DEBUG=1 search.checker.google_news
  197. .. _3xx: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection
  198. To filter out HTTP redirects (3xx_)::
  199. make SEARXNG_DEBUG=1 search.checker.google_news | grep -A1 "HTTP/1.1\" 3[0-9][0-9]"
  200. ...
  201. Engine google news Checking
  202. 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
  203. 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
  204. --
  205. 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
  206. 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
  207. --
  208. ``make pybuild``
  209. ================
  210. .. _PyPi: https://pypi.org/
  211. .. _twine: https://twine.readthedocs.io/en/latest/
  212. Build Python packages in ``./dist/py``::
  213. $ make pybuild
  214. ...
  215. BUILD pybuild
  216. running sdist
  217. running egg_info
  218. ...
  219. running bdist_wheel
  220. $ ls ./dist
  221. searx-0.18.0-py3-none-any.whl searx-0.18.0.tar.gz
  222. To upload packages to PyPi_, there is also a ``pypi.upload`` target (to test use
  223. ``pypi.upload.test``). Since you are not the owner of :pypi:`searx` you will
  224. never need to upload.