Makefile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. # -*- coding: utf-8; mode: makefile-gmake -*-
  2. .DEFAULT_GOAL=help
  3. include utils/makefile.include
  4. PYOBJECTS = searx
  5. DOC = docs
  6. PY_SETUP_EXTRAS ?= \[test\]
  7. PYLINT_SEARX_DISABLE_OPTION := I,C,R,W0105,W0212,W0511,W0603,W0613,W0621,W0702,W0703,W1401,E1136
  8. PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES := supported_languages,language_aliases
  9. include utils/makefile.python
  10. include utils/makefile.sphinx
  11. all: clean install
  12. PHONY += help-min help-all help
  13. help: help-min
  14. @echo ''
  15. @echo 'to get more help: make help-all'
  16. help-min:
  17. @echo ' test - run developer tests'
  18. @echo ' docs - build documentation'
  19. @echo ' docs-live - autobuild HTML documentation while editing'
  20. @echo ' run - run developer instance'
  21. @echo ' install - developer install (./local)'
  22. @echo ' uninstall - uninstall (./local)'
  23. @echo ' gh-pages - build docs & deploy on gh-pages branch'
  24. @echo ' clean - drop builds and environments'
  25. @echo ' project - re-build generic files of the searx project'
  26. @echo ' buildenv - re-build environment files (aka brand)'
  27. @echo ' themes - re-build build the source of the themes'
  28. @echo ' docker - build Docker image'
  29. @echo ' node.env - download & install npm dependencies locally'
  30. @echo ''
  31. @$(MAKE) -e -s make-help
  32. help-all: help-min
  33. @echo ''
  34. @$(MAKE) -e -s python-help
  35. @echo ''
  36. @$(MAKE) -e -s docs-help
  37. PHONY += install
  38. install: buildenv pyenvinstall
  39. PHONY += uninstall
  40. uninstall: pyenvuninstall
  41. PHONY += clean
  42. clean: pyclean docs-clean node.clean test.clean
  43. $(call cmd,common_clean)
  44. PHONY += run
  45. run: buildenv pyenvinstall
  46. $(Q) ( \
  47. sleep 2 ; \
  48. xdg-open http://127.0.0.1:8888/ ; \
  49. ) &
  50. SEARX_DEBUG=1 $(PY_ENV)/bin/python ./searx/webapp.py
  51. # docs
  52. # ----
  53. sphinx-doc-prebuilds:: buildenv pyenvinstall prebuild-includes
  54. PHONY += docs
  55. docs: sphinx-doc-prebuilds
  56. $(call cmd,sphinx,html,docs,docs)
  57. PHONY += docs-live
  58. docs-live: sphinx-doc-prebuilds
  59. $(call cmd,sphinx_autobuild,html,docs,docs)
  60. PHONY += prebuild-includes
  61. prebuild-includes:
  62. $(Q)mkdir -p $(DOCS_BUILD)/includes
  63. $(Q)./utils/searx.sh doc | cat > $(DOCS_BUILD)/includes/searx.rst
  64. $(Q)./utils/filtron.sh doc | cat > $(DOCS_BUILD)/includes/filtron.rst
  65. $(Q)./utils/morty.sh doc | cat > $(DOCS_BUILD)/includes/morty.rst
  66. $(GH_PAGES)::
  67. @echo "doc available at --> $(DOCS_URL)"
  68. # update project files
  69. # --------------------
  70. PHONY += project engines.languages useragents.update buildenv
  71. project: buildenv useragents.update engines.languages
  72. engines.languages: pyenvinstall
  73. $(Q)echo "fetch languages .."
  74. $(Q)$(PY_ENV_ACT); python utils/fetch_languages.py
  75. $(Q)echo "update searx/data/engines_languages.json"
  76. $(Q)mv engines_languages.json searx/data/engines_languages.json
  77. $(Q)echo "update searx/languages.py"
  78. $(Q)mv languages.py searx/languages.py
  79. useragents.update: pyenvinstall
  80. $(Q)echo "Update searx/data/useragents.json with the most recent versions of Firefox."
  81. $(Q)$(PY_ENV_ACT); python utils/fetch_firefox_version.py
  82. buildenv: pyenv
  83. $(Q)$(PY_ENV_ACT); SEARX_DEBUG=1 python utils/build_env.py
  84. # node / npm
  85. # ----------
  86. node.env: buildenv
  87. $(Q)./manage.sh npm_packages
  88. node.clean:
  89. $(Q)echo "CLEAN locally installed npm dependencies"
  90. $(Q)rm -rf \
  91. ./node_modules \
  92. ./package-lock.json \
  93. ./searx/static/themes/oscar/package-lock.json \
  94. ./searx/static/themes/oscar/node_modules \
  95. ./searx/static/themes/simple/package-lock.json \
  96. ./searx/static/themes/simple/node_modules
  97. # build themes
  98. # ------------
  99. PHONY += themes.bootstrap themes themes.oscar themes.simple
  100. themes: buildenv themes.bootstrap themes.oscar themes.simple
  101. quiet_cmd_lessc = LESSC $3
  102. cmd_lessc = PATH="$$(npm bin):$$PATH" \
  103. lessc --clean-css="--s1 --advanced --compatibility=ie9" "searx/static/$2" "searx/static/$3"
  104. quiet_cmd_grunt = GRUNT $2
  105. cmd_grunt = PATH="$$(npm bin):$$PATH" \
  106. grunt --gruntfile "$2"
  107. themes.oscar: node.env
  108. $(Q)echo '[!] build oscar theme'
  109. $(call cmd,grunt,searx/static/themes/oscar/gruntfile.js)
  110. themes.simple: node.env
  111. $(Q)echo '[!] build simple theme'
  112. $(call cmd,grunt,searx/static/themes/simple/gruntfile.js)
  113. themes.bootstrap: node.env
  114. $(call cmd,lessc,less/bootstrap/bootstrap.less,css/bootstrap.min.css)
  115. # docker
  116. # ------
  117. PHONY += docker
  118. docker: buildenv
  119. $(Q)./manage.sh docker_build
  120. docker.push: buildenv
  121. $(Q)./manage.sh docker_build push
  122. # gecko
  123. # -----
  124. PHONY += gecko.driver
  125. gecko.driver:
  126. $(PY_ENV_ACT); ./manage.sh install_geckodriver
  127. # search.checker
  128. # --------------
  129. search.checker: pyenvinstall
  130. $(Q)$(PY_ENV_ACT); searx-checker -v
  131. ENGINE_TARGETS=$(patsubst searx/engines/%.py,search.checker.%,$(wildcard searx/engines/[!_]*.py))
  132. $(ENGINE_TARGETS): pyenvinstall
  133. $(Q)$(PY_ENV_ACT); searx-checker -v "$(subst _, ,$(patsubst search.checker.%,%,$@))"
  134. # test
  135. # ----
  136. PHONY += test test.sh test.pylint test.pep8 test.unit test.coverage test.robot
  137. test: buildenv test.pylint test.pep8 test.unit gecko.driver test.robot
  138. PYLINT_FILES=\
  139. searx/preferences.py \
  140. searx/testing.py \
  141. searx/engines/gigablast.py \
  142. searx/engines/deviantart.py \
  143. searx/engines/digg.py \
  144. searx/engines/google.py \
  145. searx/engines/google_news.py \
  146. searx/engines/google_videos.py \
  147. searx/engines/google_images.py \
  148. searx/engines/mediathekviewweb.py \
  149. searx/engines/google_scholar.py \
  150. searx_extra/update/update_external_bangs.py
  151. test.pylint: pyenvinstall
  152. $(call cmd,pylint,$(PYLINT_FILES))
  153. $(call cmd,pylint,\
  154. --disable=$(PYLINT_SEARX_DISABLE_OPTION) \
  155. --additional-builtins=$(PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES) \
  156. searx/engines \
  157. )
  158. $(call cmd,pylint,\
  159. --disable=$(PYLINT_SEARX_DISABLE_OPTION) \
  160. --ignore=searx/engines \
  161. searx tests \
  162. )
  163. # ignored rules:
  164. # E402 module level import not at top of file
  165. # W503 line break before binary operator
  166. # ubu1604: uses shellcheck v0.3.7 (from 04/2015), no longer supported!
  167. test.sh:
  168. shellcheck -x -s bash utils/brand.env
  169. shellcheck -x utils/lib.sh
  170. shellcheck -x utils/filtron.sh
  171. shellcheck -x utils/searx.sh
  172. shellcheck -x utils/morty.sh
  173. shellcheck -x utils/lxc.sh
  174. shellcheck -x utils/lxc-searx.env
  175. shellcheck -x .config.sh
  176. test.pep8: pyenvinstall
  177. @echo "TEST pycodestyle (formerly pep8)"
  178. $(Q)$(PY_ENV_ACT); pycodestyle --exclude='searx/static, searx/languages.py, $(foreach f,$(PYLINT_FILES),$(f),)' \
  179. --max-line-length=120 --ignore "E117,E252,E402,E722,E741,W503,W504,W605" searx tests
  180. test.unit: pyenvinstall
  181. @echo "TEST tests/unit"
  182. $(Q)$(PY_ENV_ACT); python -m nose2 -s tests/unit
  183. test.coverage: pyenvinstall
  184. @echo "TEST unit test coverage"
  185. $(Q)$(PY_ENV_ACT); \
  186. python -m nose2 -C --log-capture --with-coverage --coverage searx -s tests/unit \
  187. && coverage report \
  188. && coverage html \
  189. test.robot: pyenvinstall gecko.driver
  190. @echo "TEST robot"
  191. $(Q)$(PY_ENV_ACT); PYTHONPATH=. python searx/testing.py robot
  192. test.clean:
  193. @echo "CLEAN intermediate test stuff"
  194. $(Q)rm -rf geckodriver.log .coverage coverage/
  195. # travis
  196. # ------
  197. PHONY += ci.test
  198. ci.test:
  199. $(PY_ENV_BIN)/python -c "import yaml" || make clean
  200. $(MAKE) test
  201. travis.codecov:
  202. $(Q)$(PY_ENV_BIN)/python -m pip install codecov
  203. .PHONY: $(PHONY)