manage 22 KB

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