Makefile 6.9 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 ./searx_extra/update/update_languages.py
  75. $(Q)echo "updated searx/data/engines_languages.json"
  76. $(Q)echo "updated searx/languages.py"
  77. useragents.update: pyenvinstall
  78. $(Q)echo "fetch useragents .."
  79. $(Q)$(PY_ENV_ACT); python ./searx_extra/update/update_firefox_version.py
  80. $(Q)echo "updated searx/data/useragents.json with the most recent versions of Firefox."
  81. buildenv: pyenv
  82. $(Q)$(PY_ENV_ACT); SEARX_DEBUG=1 python utils/build_env.py
  83. # node / npm
  84. # ----------
  85. node.env: buildenv
  86. $(Q)./manage.sh npm_packages
  87. node.clean:
  88. $(Q)echo "CLEAN locally installed npm dependencies"
  89. $(Q)rm -rf \
  90. ./node_modules \
  91. ./package-lock.json \
  92. ./searx/static/themes/oscar/package-lock.json \
  93. ./searx/static/themes/oscar/node_modules \
  94. ./searx/static/themes/simple/package-lock.json \
  95. ./searx/static/themes/simple/node_modules
  96. # build themes
  97. # ------------
  98. PHONY += themes themes.oscar themes.simple
  99. themes: buildenv themes.oscar themes.simple
  100. quiet_cmd_lessc = LESSC $3
  101. cmd_lessc = PATH="$$(npm bin):$$PATH" \
  102. lessc --clean-css="--s1 --advanced --compatibility=ie9" "searx/static/$2" "searx/static/$3"
  103. quiet_cmd_grunt = GRUNT $2
  104. cmd_grunt = PATH="$$(npm bin):$$PATH" \
  105. grunt --gruntfile "$2"
  106. themes.oscar: node.env
  107. $(Q)echo '[!] build oscar theme'
  108. $(call cmd,grunt,searx/static/themes/oscar/gruntfile.js)
  109. themes.simple: node.env
  110. $(Q)echo '[!] build simple theme'
  111. $(call cmd,grunt,searx/static/themes/simple/gruntfile.js)
  112. # docker
  113. # ------
  114. PHONY += docker
  115. docker: buildenv
  116. $(Q)./manage.sh docker_build
  117. docker.push: buildenv
  118. $(Q)./manage.sh docker_build push
  119. # gecko
  120. # -----
  121. PHONY += gecko.driver
  122. gecko.driver:
  123. $(PY_ENV_ACT); ./manage.sh install_geckodriver
  124. # search.checker
  125. # --------------
  126. search.checker: pyenvinstall
  127. $(Q)$(PY_ENV_ACT); searx-checker -v
  128. ENGINE_TARGETS=$(patsubst searx/engines/%.py,search.checker.%,$(wildcard searx/engines/[!_]*.py))
  129. $(ENGINE_TARGETS): pyenvinstall
  130. $(Q)$(PY_ENV_ACT); searx-checker -v "$(subst _, ,$(patsubst search.checker.%,%,$@))"
  131. # test
  132. # ----
  133. PHONY += test test.sh test.pylint test.pep8 test.unit test.coverage test.robot
  134. test: buildenv test.pylint test.pep8 test.unit gecko.driver test.robot
  135. PYLINT_FILES=\
  136. searx/preferences.py \
  137. searx/testing.py \
  138. searx/engines/gigablast.py \
  139. searx/engines/deviantart.py \
  140. searx/engines/digg.py \
  141. searx/engines/google.py \
  142. searx/engines/google_news.py \
  143. searx/engines/google_videos.py \
  144. searx/engines/google_images.py \
  145. searx/engines/mediathekviewweb.py \
  146. searx/engines/solidtorrents.py \
  147. searx/engines/solr.py \
  148. searx/engines/google_scholar.py \
  149. searx/engines/yahoo_news.py \
  150. searx/engines/apkmirror.py \
  151. searx_extra/update/update_external_bangs.py
  152. test.pylint: pyenvinstall
  153. $(call cmd,pylint,$(PYLINT_FILES))
  154. $(call cmd,pylint,\
  155. --disable=$(PYLINT_SEARX_DISABLE_OPTION) \
  156. --additional-builtins=$(PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES) \
  157. searx/engines \
  158. )
  159. $(call cmd,pylint,\
  160. --disable=$(PYLINT_SEARX_DISABLE_OPTION) \
  161. --ignore=searx/engines \
  162. searx tests \
  163. )
  164. # ignored rules:
  165. # E402 module level import not at top of file
  166. # W503 line break before binary operator
  167. # ubu1604: uses shellcheck v0.3.7 (from 04/2015), no longer supported!
  168. test.sh:
  169. shellcheck -x -s bash utils/brand.env
  170. shellcheck -x utils/lib.sh
  171. shellcheck -x utils/filtron.sh
  172. shellcheck -x utils/searx.sh
  173. shellcheck -x utils/morty.sh
  174. shellcheck -x utils/lxc.sh
  175. shellcheck -x utils/lxc-searx.env
  176. shellcheck -x .config.sh
  177. test.pep8: pyenvinstall
  178. @echo "TEST pycodestyle (formerly pep8)"
  179. $(Q)$(PY_ENV_ACT); pycodestyle --exclude='searx/static, searx/languages.py, $(foreach f,$(PYLINT_FILES),$(f),)' \
  180. --max-line-length=120 --ignore "E117,E252,E402,E722,E741,W503,W504,W605" searx tests
  181. test.unit: pyenvinstall
  182. @echo "TEST tests/unit"
  183. $(Q)$(PY_ENV_ACT); python -m nose2 -s tests/unit
  184. test.coverage: pyenvinstall
  185. @echo "TEST unit test coverage"
  186. $(Q)$(PY_ENV_ACT); \
  187. python -m nose2 -C --log-capture --with-coverage --coverage searx -s tests/unit \
  188. && coverage report \
  189. && coverage html \
  190. test.robot: pyenvinstall gecko.driver
  191. @echo "TEST robot"
  192. $(Q)$(PY_ENV_ACT); PYTHONPATH=. python searx/testing.py robot
  193. test.clean:
  194. @echo "CLEAN intermediate test stuff"
  195. $(Q)rm -rf geckodriver.log .coverage coverage/
  196. # travis
  197. # ------
  198. PHONY += ci.test
  199. ci.test:
  200. $(PY_ENV_BIN)/python -c "import yaml" || make clean
  201. $(MAKE) test
  202. travis.codecov:
  203. $(Q)$(PY_ENV_BIN)/python -m pip install codecov
  204. .PHONY: $(PHONY)