manage 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. #!/usr/bin/env bash
  2. # -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. # shellcheck disable=SC2031
  5. # shellcheck source=utils/lib.sh
  6. source "$(dirname "${BASH_SOURCE[0]}")/utils/lib.sh"
  7. # shellcheck source=utils/lib_static.sh
  8. source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_static.sh"
  9. # config
  10. PYOBJECTS="searx"
  11. PY_SETUP_EXTRAS='[test]'
  12. GECKODRIVER_VERSION="v0.28.0"
  13. # SPHINXOPTS=
  14. pylint.FILES() {
  15. # List files tagged by comment:
  16. #
  17. # # lint: pylint
  18. #
  19. # These py files are linted by test.pylint(), all other files are linted by
  20. # test.pep8()
  21. grep -l -r --include \*.py '^#[[:blank:]]*lint:[[:blank:]]*pylint' searx searx_extra tests
  22. }
  23. YAMLLINT_FILES=()
  24. while IFS= read -r line; do
  25. YAMLLINT_FILES+=("$line")
  26. done <<< "$(git ls-files './tests/*.yml' './searx/*.yml' './utils/templates/etc/searx/*.yml')"
  27. PYLINT_SEARX_DISABLE_OPTION="\
  28. I,C,R,\
  29. W0105,W0212,W0511,W0603,W0613,W0621,W0702,W0703,W1401,\
  30. E1136"
  31. PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES="supported_languages,language_aliases,logger,categories"
  32. PYLINT_OPTIONS="-m pylint -j 0 --rcfile .pylintrc"
  33. help() {
  34. cat <<EOF
  35. buildenv:
  36. rebuild ./utils/brand.env
  37. babel.:
  38. master.to.translations: update the translations branch from the messages of the master branch.
  39. translations.to.master: copy change from the translations branch to the master branch.
  40. data.:
  41. all : update searx/languages.py and ./data/*
  42. languages : update searx/data/engines_languages.json & searx/languages.py
  43. useragents: update searx/data/useragents.json with the most recent versions of Firefox.
  44. docs.:
  45. html : build HTML documentation
  46. live : autobuild HTML documentation while editing
  47. gh-pages : deploy on gh-pages branch
  48. prebuild : build reST include files (./${DOCS_BUILD}/includes)
  49. clean : clean documentation build
  50. docker.:
  51. build : build docker image
  52. push : build and push docker image
  53. gecko.driver:
  54. download & install geckodriver if not already installed (required for
  55. robot_tests)
  56. node.:
  57. env : download & install npm dependencies locally
  58. clean : drop npm installations
  59. py.:
  60. build : Build python packages at ./${PYDIST}
  61. clean : delete virtualenv and intermediate py files
  62. pyenv.:
  63. install : developer install of searx into virtualenv
  64. uninstall : uninstall developer installation
  65. cmd ... : run command ... in virtualenv
  66. OK : test if virtualenv is OK
  67. pypi.upload:
  68. Upload python packages to PyPi (to test use pypi.upload.test)
  69. test.:
  70. pylint : lint PYLINT_FILES, searx/engines, searx & tests
  71. pep8 : pycodestyle (pep8) for all files except PYLINT_FILES
  72. unit : run unit tests
  73. coverage : run unit tests with coverage
  74. robot : run robot test
  75. clean : clean intermediate test stuff
  76. themes.:
  77. all : build all themes
  78. oscar : build oscar theme
  79. simple : build simple theme
  80. pygments.:
  81. less : build LESS files for pygments
  82. EOF
  83. static_help
  84. }
  85. if [ "$VERBOSE" = "1" ]; then
  86. SPHINX_VERBOSE="-v"
  87. PYLINT_VERBOSE="-v"
  88. fi
  89. # needed by sphinx-docs
  90. export DOCS_BUILD
  91. buildenv() {
  92. # settings file from repository's working tree are used by default
  93. SEARX_SETTINGS_PATH="${REPO_ROOT}/searx/settings.yml"
  94. if [ -r '/etc/searx/settings.yml' ]; then
  95. if ask_yn "should settings read from: /etc/searx/settings.yml"; then
  96. SEARX_SETTINGS_PATH='/etc/searx/settings.yml'
  97. fi
  98. fi
  99. export SEARX_SETTINGS_PATH
  100. (
  101. set -e
  102. SEARX_DEBUG=1 pyenv.cmd python utils/build_env.py 2>&1 \
  103. | prefix_stdout "${_Blue}BUILDENV${_creset} "
  104. )
  105. return "${PIPESTATUS[0]}"
  106. }
  107. TRANSLATIONS_WORKTREE="$CACHE/translations"
  108. weblate.translations.worktree() {
  109. # Create git worktree ${TRANSLATIONS_WORKTREE} and checkout branch
  110. # 'translations' from Weblate's counterpart (weblate) of the SearXNG
  111. # (origin).
  112. #
  113. # remote weblate https://weblate.bubu1.eu/git/searxng/searxng/
  114. ( set -e
  115. if ! git remote get-url weblate 2> /dev/null; then
  116. git remote add weblate https://weblate.bubu1.eu/git/searxng/searxng/
  117. fi
  118. if [ -d "${TRANSLATIONS_WORKTREE}" ]; then
  119. pushd .
  120. cd "${TRANSLATIONS_WORKTREE}"
  121. git reset --hard HEAD
  122. git pull origin translations
  123. popd
  124. else
  125. mkdir -p "${TRANSLATIONS_WORKTREE}"
  126. git worktree add "${TRANSLATIONS_WORKTREE}" translations
  127. fi
  128. )
  129. }
  130. weblate.to.translations() {
  131. # Update 'translations' branch of SearXNG (origin) with last additions from
  132. # Weblate.
  133. # 1. Check if Weblate is locked, if not die with error message
  134. # 2. On Weblate's counterpart (weblate), pull master and translations branch
  135. # from SearXNG (origin).
  136. # 3. Commit changes made in a Weblate object on Weblate's counterpart
  137. # (weblate).
  138. # 4. In translations worktree, merge changes of branch 'translations' from
  139. # remote 'weblate' and push it on branch 'translations' of 'origin'
  140. ( set -e
  141. if [ "$(pyenv.cmd wlc lock-status)" != "locked: True" ]; then
  142. die 1 "weblate must be locked, currently: $(pyenv.cmd wlc lock-status)"
  143. fi
  144. # weblate: commit pending changes
  145. pyenv.cmd wlc pull
  146. pyenv.cmd wlc commit
  147. # get the translations in a worktree
  148. weblate.translations.worktree
  149. pushd "${TRANSLATIONS_WORKTREE}"
  150. git remote update weblate
  151. git merge weblate/translations
  152. git push
  153. popd
  154. )
  155. dump_return $?
  156. }
  157. weblate.translations.commit() {
  158. # Update 'translations' branch of SearXNG (origin) with last additions from
  159. # Weblate. Copy the changes to the master branch, compile translations and
  160. # create a commit in the local branch (master)
  161. local existing_commit_hash commit_body commit_message exitcode
  162. ( set -e
  163. # lock change on weblate
  164. pyenv.cmd wlc lock
  165. # get translations branch in git worktree (TRANSLATIONS_WORKTREE)
  166. weblate.translations.worktree
  167. existing_commit_hash=$(cd "${TRANSLATIONS_WORKTREE}"; git log -n1 --pretty=format:'%h')
  168. # pull weblate commits
  169. weblate.to.translations
  170. # copy the changes to the master branch
  171. cp -rv --preserve=mode,timestamps "${TRANSLATIONS_WORKTREE}/searx/translations" "searx"
  172. # compile translations
  173. build_msg BABEL 'compile translation catalogs into binary MO files'
  174. pyenv.cmd pybabel compile --statistics \
  175. -d "searx/translations"
  176. # git add/commit (no push)
  177. commit_body=$(cd "${TRANSLATIONS_WORKTREE}"; git log --pretty=format:'%h - %as - %aN <%ae>' "${existing_commit_hash}..HEAD")
  178. commit_message=$(echo -e "[translations] update\n${commit_body}")
  179. git add searx/translations
  180. git commit -m "${commit_message}"
  181. )
  182. exitcode=$?
  183. ( # make sure to always unlock weblate
  184. set -e
  185. pyenv.cmd wlc unlock
  186. )
  187. dump_return $exitcode
  188. }
  189. weblate.push.translations() {
  190. # Push *translation changes* from SearXNG (origin) to Weblate's counterpart
  191. # (weblate).
  192. # In branch master of SearXNG (origin) check for meaningful changes in
  193. # folder 'searx/translations', commit changes on branch 'translations' and
  194. # at least, pull updated branches on Weblate's counterpart (weblate).
  195. # 1. Create git worktree ${TRANSLATIONS_WORKTREE} and checkout branch
  196. # 'translations' from remote 'weblate'.
  197. # 2. Stop if there is no meaningful change in the 'master' branch (origin),
  198. # compared to the 'translations' branch (weblate), otherwise ...
  199. # 3. Update 'translations' branch of SearXNG (origin) with last additions
  200. # from Weblate.
  201. # 5. Notify Weblate to pull updated 'master' & 'translations' branch.
  202. local messages_pot diff_messages_pot last_commit_hash last_commit_detail \
  203. last_commit_message exitcode
  204. messages_pot="${TRANSLATIONS_WORKTREE}/searx/translations/messages.pot"
  205. ( set -e
  206. # get translations branch in git worktree (TRANSLATIONS_WORKTREE)
  207. weblate.translations.worktree
  208. # update messages.pot in the master branch
  209. build_msg BABEL 'extract messages from source files and generate POT file'
  210. pyenv.cmd pybabel extract -F babel.cfg \
  211. -o "${messages_pot}" \
  212. "searx/"
  213. # stop if there is no meaningful change in the master branch
  214. diff_messages_pot=$(cd "${TRANSLATIONS_WORKTREE}";\
  215. git diff -- "searx/translations/messages.pot")
  216. if ! echo "$diff_messages_pot" | grep -qE "[\+\-](msgid|msgstr)"; then
  217. build_msg BABEL 'no changes detected, exiting'
  218. return 42
  219. fi
  220. return 0
  221. )
  222. exitcode=$?
  223. if [ "$exitcode" -eq 42 ]; then
  224. return 0
  225. fi
  226. if [ "$exitcode" ]; then
  227. return $exitcode
  228. fi
  229. (
  230. set -e
  231. # lock change on weblate
  232. # weblate may add commit(s) since the call to "weblate.translations.worktree".
  233. # this is not a problem because after this line, "weblate.to.translations"
  234. # calls again "weblate.translations.worktree" which calls "git pull"
  235. pyenv.cmd wlc lock
  236. # save messages.pot in the translations branch for later
  237. pushd "${TRANSLATIONS_WORKTREE}"
  238. git stash push
  239. popd
  240. # merge weblate commits into the translations branch
  241. weblate.to.translations
  242. # restore messages.pot in the translations branch
  243. pushd "${TRANSLATIONS_WORKTREE}"
  244. git stash pop
  245. popd
  246. # update messages.po files in the master branch
  247. build_msg BABEL 'update existing message catalogs from POT file'
  248. pyenv.cmd pybabel update -N \
  249. -i "${messages_pot}" \
  250. -d "${TRANSLATIONS_WORKTREE}/searx/translations"
  251. # git add/commit/push
  252. last_commit_hash=$(git log -n1 --pretty=format:'%h')
  253. last_commit_detail=$(git log -n1 --pretty=format:'%h - %as - %aN <%ae>' "${last_commit_hash}")
  254. last_commit_message="[translations] update messages.pot and messages.po files\nFrom ${last_commit_detail}"
  255. pushd "${TRANSLATIONS_WORKTREE}"
  256. git add searx/translations
  257. git commit -m "${last_commit_message}"
  258. git push
  259. popd
  260. # notify weblate to pull updated master & translations branch
  261. pyenv.cmd wlc pull
  262. )
  263. exitcode=$?
  264. ( # make sure to always unlock weblate
  265. set -e
  266. pyenv.cmd wlc unlock
  267. )
  268. dump_return $exitcode
  269. }
  270. data.all() {
  271. data.languages
  272. data.useragents
  273. data.osm_keys_tags
  274. build_msg DATA "update searx/data/ahmia_blacklist.txt"
  275. pyenv.cmd python searx_extra/update/update_ahmia_blacklist.py
  276. build_msg DATA "update searx/data/wikidata_units.json"
  277. pyenv.cmd python searx_extra/update/update_wikidata_units.py
  278. build_msg DATA "update searx/data/currencies.json"
  279. pyenv.cmd python searx_extra/update/update_currencies.py
  280. }
  281. data.languages() {
  282. ( set -e
  283. build_msg ENGINES "fetch languages .."
  284. pyenv.cmd python searx_extra/update/update_languages.py
  285. build_msg ENGINES "update update searx/languages.py"
  286. build_msg DATA "update searx/data/engines_languages.json"
  287. )
  288. dump_return $?
  289. }
  290. data.useragents() {
  291. build_msg DATA "update searx/data/useragents.json"
  292. pyenv.cmd python searx_extra/update/update_firefox_version.py
  293. dump_return $?
  294. }
  295. data.osm_keys_tags() {
  296. build_msg DATA "update searx/data/osm_keys_tags.json"
  297. pyenv.cmd python searx_extra/update/update_osm_keys_tags.py
  298. dump_return $?
  299. }
  300. docs.prebuild() {
  301. build_msg DOCS "build ${DOCS_BUILD}/includes"
  302. (
  303. set -e
  304. [ "$VERBOSE" = "1" ] && set -x
  305. mkdir -p "${DOCS_BUILD}/includes"
  306. ./utils/searx.sh doc | cat > "${DOCS_BUILD}/includes/searx.rst"
  307. ./utils/filtron.sh doc | cat > "${DOCS_BUILD}/includes/filtron.rst"
  308. ./utils/morty.sh doc | cat > "${DOCS_BUILD}/includes/morty.rst"
  309. )
  310. dump_return $?
  311. }
  312. docker.push() {
  313. docker.build push
  314. }
  315. docker.buildx() {
  316. docker.build buildx
  317. }
  318. # shellcheck disable=SC2119
  319. docker.build() {
  320. pyenv.install
  321. local SEARX_GIT_VERSION
  322. local VERSION_GITCOMMIT
  323. local GITHUB_USER
  324. local SEARX_IMAGE_NAME
  325. local BUILD
  326. build_msg DOCKER build
  327. # run installation in a subprocess and activate pyenv
  328. # See https://www.shellcheck.net/wiki/SC1001 and others ..
  329. # shellcheck disable=SC2031,SC2230,SC2002,SC2236,SC2143,SC1001
  330. ( set -e
  331. # shellcheck source=/dev/null
  332. source "${PY_ENV_BIN}/activate"
  333. # Check if it is a git repository
  334. if [ ! -d .git ]; then
  335. die 1 "This is not Git repository"
  336. fi
  337. if [ ! -x "$(which git)" ]; then
  338. die 1 "git is not installed"
  339. fi
  340. if ! git remote get-url origin 2> /dev/null; then
  341. die 1 "there is no remote origin"
  342. fi
  343. # This is a git repository
  344. git update-index -q --refresh
  345. pyenv.cmd python -m searx.version freeze
  346. eval "$(pyenv.cmd python -m searx.version)"
  347. # Get the last git commit id
  348. VERSION_GITCOMMIT=$(echo "$VERSION_STRING" | cut -d- -f3)
  349. build_msg DOCKER "Last commit : $VERSION_GITCOMMIT"
  350. # define the docker image name
  351. GITHUB_USER=$(echo "${GIT_URL}" | sed 's/.*github\.com\/\([^\/]*\).*/\1/')
  352. SEARX_IMAGE_NAME="${SEARX_IMAGE_NAME:-${GITHUB_USER:-searxng}/searxng}"
  353. BUILD="build"
  354. if [ "$1" = "buildx" ]; then
  355. # buildx includes the push option
  356. CACHE_TAG="${SEARX_IMAGE_NAME}:latest-build-cache"
  357. BUILD="buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --push --cache-from=type=registry,ref=$CACHE_TAG --cache-to=type=registry,ref=$CACHE_TAG,mode=max"
  358. shift
  359. fi
  360. build_msg DOCKER "Build command: ${BUILD}"
  361. # build Docker image
  362. build_msg DOCKER "Building image ${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}"
  363. # shellcheck disable=SC2086
  364. docker $BUILD \
  365. --build-arg BASE_IMAGE="${DEPENDENCIES_IMAGE_NAME}" \
  366. --build-arg GIT_URL="${GIT_URL}" \
  367. --build-arg SEARX_GIT_VERSION="${VERSION_STRING}" \
  368. --build-arg VERSION_GITCOMMIT="${VERSION_GITCOMMIT}" \
  369. --build-arg LABEL_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
  370. --build-arg LABEL_VCS_REF="$(git rev-parse HEAD)" \
  371. --build-arg LABEL_VCS_URL="${GIT_URL}" \
  372. --build-arg TIMESTAMP_SETTINGS="$(git log -1 --format="%cd" --date=unix -- searx/settings.yml)" \
  373. --build-arg TIMESTAMP_UWSGI="$(git log -1 --format="%cd" --date=unix -- dockerfiles/uwsgi.ini)" \
  374. -t "${SEARX_IMAGE_NAME}:latest" -t "${SEARX_IMAGE_NAME}:${VERSION_STRING}" .
  375. if [ "$1" = "push" ]; then
  376. docker push "${SEARX_IMAGE_NAME}:latest"
  377. docker push "${SEARX_IMAGE_NAME}:${SEARX_GIT_VERSION}"
  378. fi
  379. )
  380. dump_return $?
  381. }
  382. # shellcheck disable=SC2119
  383. gecko.driver() {
  384. pyenv.install
  385. build_msg INSTALL "gecko.driver"
  386. # run installation in a subprocess and activate pyenv
  387. ( set -e
  388. # shellcheck source=/dev/null
  389. source "${PY_ENV_BIN}/activate"
  390. # TODO : check the current geckodriver version
  391. geckodriver -V > /dev/null 2>&1 || NOTFOUND=1
  392. set +e
  393. if [ -z "$NOTFOUND" ]; then
  394. build_msg INSTALL "geckodriver already installed"
  395. return
  396. fi
  397. PLATFORM="$(python3 -c 'import platform; print(platform.system().lower(), platform.architecture()[0])')"
  398. case "$PLATFORM" in
  399. "linux 32bit" | "linux2 32bit") ARCH="linux32";;
  400. "linux 64bit" | "linux2 64bit") ARCH="linux64";;
  401. "windows 32 bit") ARCH="win32";;
  402. "windows 64 bit") ARCH="win64";;
  403. "mac 64bit") ARCH="macos";;
  404. esac
  405. GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-$ARCH.tar.gz";
  406. build_msg GECKO "Installing ${PY_ENV_BIN}/geckodriver from $GECKODRIVER_URL"
  407. FILE="$(mktemp)"
  408. wget -qO "$FILE" -- "$GECKODRIVER_URL" && tar xz -C "${PY_ENV_BIN}" -f "$FILE" geckodriver
  409. rm -- "$FILE"
  410. chmod 755 -- "${PY_ENV_BIN}/geckodriver"
  411. )
  412. dump_return $?
  413. }
  414. node.env() {
  415. if ! required_commands npm; then
  416. info_msg "to install build tools use::"
  417. info_msg " sudo -H ./utils/searx.sh install buildhost"
  418. die 1 "install needed build tools first"
  419. fi
  420. ( set -e
  421. build_msg INSTALL "searx/static/themes/oscar/package.json"
  422. npm --prefix searx/static/themes/oscar install
  423. build_msg INSTALL "searx/static/themes/simple/package.json"
  424. npm --prefix searx/static/themes/simple install
  425. )
  426. dump_return $?
  427. }
  428. node.clean() {
  429. if ! required_commands npm 2>/dev/null; then
  430. build_msg CLEAN "npm is not installed / ignore npm dependencies"
  431. return 0
  432. fi
  433. build_msg CLEAN "locally installed npm dependencies"
  434. ( set -e
  435. npm --prefix searx/static/themes/oscar run clean
  436. npm --prefix searx/static/themes/simple run clean
  437. )
  438. dump_return $?
  439. }
  440. pygments.less() {
  441. build_msg PYGMENTS "searx_extra/update/update_pygments.py"
  442. if ! pyenv.cmd python searx_extra/update/update_pygments.py; then
  443. build_msg PYGMENTS "building LESS files for pygments failed"
  444. return 1
  445. fi
  446. return 0
  447. }
  448. py.build() {
  449. build_msg BUILD "python package ${PYDIST}"
  450. pyenv.cmd python setup.py \
  451. sdist -d "${PYDIST}" \
  452. bdist_wheel --bdist-dir "${PYBUILD}" -d "${PYDIST}"
  453. }
  454. py.clean() {
  455. build_msg CLEAN pyenv
  456. ( set -e
  457. pyenv.drop
  458. [ "$VERBOSE" = "1" ] && set -x
  459. rm -rf "${PYDIST}" "${PYBUILD}" "${PY_ENV}" ./.tox ./*.egg-info
  460. find . -name '*.pyc' -exec rm -f {} +
  461. find . -name '*.pyo' -exec rm -f {} +
  462. find . -name __pycache__ -exec rm -rf {} +
  463. )
  464. }
  465. pyenv.check() {
  466. cat <<EOF
  467. import yaml
  468. print('import yaml --> OK')
  469. EOF
  470. }
  471. pyenv.install() {
  472. if ! pyenv.OK; then
  473. py.clean > /dev/null
  474. fi
  475. if pyenv.install.OK > /dev/null; then
  476. return 0
  477. fi
  478. ( set -e
  479. pyenv
  480. build_msg PYENV "[install] pip install -e 'searx${PY_SETUP_EXTRAS}'"
  481. "${PY_ENV_BIN}/python" -m pip install -e ".${PY_SETUP_EXTRAS}"
  482. buildenv
  483. )
  484. local exit_val=$?
  485. if [ ! $exit_val -eq 0 ]; then
  486. die 42 "error while pip install (${PY_ENV_BIN})"
  487. fi
  488. }
  489. pyenv.uninstall() {
  490. build_msg PYENV "[pyenv.uninstall] uninstall packages: ${PYOBJECTS}"
  491. pyenv.cmd python setup.py develop --uninstall 2>&1 \
  492. | prefix_stdout "${_Blue}PYENV ${_creset}[pyenv.uninstall] "
  493. }
  494. pypi.upload() {
  495. py.clean
  496. py.build
  497. # https://github.com/pypa/twine
  498. pyenv.cmd twine upload "${PYDIST}"/*
  499. }
  500. pypi.upload.test() {
  501. py.clean
  502. py.build
  503. pyenv.cmd twine upload -r testpypi "${PYDIST}"/*
  504. }
  505. test.yamllint() {
  506. build_msg TEST "[yamllint] \$YAMLLINT_FILES"
  507. pyenv.cmd yamllint --format parsable "${YAMLLINT_FILES[@]}"
  508. }
  509. test.pylint() {
  510. # shellcheck disable=SC2086
  511. ( set -e
  512. build_msg TEST "[pylint] \$PYLINT_FILES"
  513. pyenv.cmd python ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
  514. --additional-builtins="${PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES}" \
  515. "${PYLINT_FILES[@]}"
  516. build_msg TEST "[pylint] searx/engines"
  517. pyenv.cmd python ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
  518. --disable="${PYLINT_SEARX_DISABLE_OPTION}" \
  519. --additional-builtins="${PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES}" \
  520. searx/engines
  521. build_msg TEST "[pylint] searx tests"
  522. pyenv.cmd python ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
  523. --disable="${PYLINT_SEARX_DISABLE_OPTION}" \
  524. --ignore=searx/engines \
  525. searx tests
  526. )
  527. dump_return $?
  528. }
  529. test.pep8() {
  530. build_msg TEST 'pycodestyle (formerly pep8)'
  531. local _exclude=""
  532. printf -v _exclude '%s, ' "${PYLINT_FILES[@]}"
  533. pyenv.cmd pycodestyle \
  534. --exclude="searx/static, searx/languages.py, $_exclude " \
  535. --max-line-length=120 \
  536. --ignore "E117,E252,E402,E722,E741,W503,W504,W605" \
  537. searx tests
  538. dump_return $?
  539. }
  540. test.unit() {
  541. build_msg TEST 'tests/unit'
  542. pyenv.cmd python -m nose2 -s tests/unit
  543. dump_return $?
  544. }
  545. test.coverage() {
  546. build_msg TEST 'unit test coverage'
  547. ( set -e
  548. pyenv.cmd python -m nose2 -C --log-capture --with-coverage --coverage searx -s tests/unit
  549. pyenv.cmd coverage report
  550. pyenv.cmd coverage html
  551. )
  552. dump_return $?
  553. }
  554. test.robot() {
  555. build_msg TEST 'robot'
  556. gecko.driver
  557. PYTHONPATH=. pyenv.cmd python -m tests.robot
  558. dump_return $?
  559. }
  560. test.clean() {
  561. build_msg CLEAN "test stuff"
  562. rm -rf geckodriver.log .coverage coverage/
  563. dump_return $?
  564. }
  565. themes.all() {
  566. ( set -e
  567. pygments.less
  568. node.env
  569. themes.oscar
  570. themes.simple
  571. )
  572. dump_return $?
  573. }
  574. themes.oscar() {
  575. build_msg GRUNT "theme: oscar"
  576. npm --prefix searx/static/themes/oscar run build
  577. dump_return $?
  578. }
  579. themes.simple() {
  580. build_msg GRUNT "theme: simple"
  581. npm --prefix searx/static/themes/simple run build
  582. dump_return $?
  583. }
  584. PYLINT_FILES=()
  585. while IFS= read -r line; do
  586. PYLINT_FILES+=("$line")
  587. done <<< "$(pylint.FILES)"
  588. # shellcheck disable=SC2119
  589. main() {
  590. local _type
  591. local cmd="$1"; shift
  592. if [ "$cmd" == "" ]; then
  593. help
  594. err_msg "missing command"
  595. return 42
  596. fi
  597. case "$cmd" in
  598. --getenv) var="$1"; echo "${!var}";;
  599. --help) help;;
  600. --*)
  601. help
  602. err_msg "unknown option $cmd"
  603. return 42
  604. ;;
  605. *)
  606. _type="$(type -t "$cmd")"
  607. if [ "$_type" != 'function' ]; then
  608. err_msg "unknown command: $cmd / use --help"
  609. return 42
  610. else
  611. "$cmd" "$@"
  612. fi
  613. ;;
  614. esac
  615. }
  616. main "$@"