diff --git a/.dir-locals.el b/.dir-locals.el index 43d6fa551..419311ee7 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -32,6 +32,10 @@ ;; Jedi, flycheck & other python stuff should use the 'python-shell-interpreter' ;; from the local py3 environment. ;; +;; For pyright support you need to install:: +;; +;; M-x package-install lsp-pyright +;; ;; Other useful jedi stuff you might add to your ~/.emacs:: ;; ;; (global-set-key [f6] 'flycheck-mode) @@ -104,7 +108,10 @@ (python-mode . ((eval . (progn - + ;; use nodejs from the (local) NVM environment (see nvm-dir) + (nvm-use-for-buffer) + (if (featurep 'lsp-pyright) + (lsp)) (setq-local python-environment-virtualenv (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root) ;;"--system-site-packages" diff --git a/.gitignore b/.gitignore index efea6c872..9b3eff158 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -# to sync with .dockerignore +# to sync with .dockerignore & pyrightconfig.json *.pyc */*.pyc @@ -16,3 +16,6 @@ dist/ local/ gh-pages/ *.egg-info/ + +/package-lock.json +/node_modules/ diff --git a/.nvm_packages b/.nvm_packages deleted file mode 100644 index 13eabc5c2..000000000 --- a/.nvm_packages +++ /dev/null @@ -1,8 +0,0 @@ -# -*- coding: utf-8; mode: conf-unix -*- -# -# Developement tools pre-installed in NVM's node installation [1] -# -# [1] https://github.com/nvm-sh/nvm#default-global-packages-from-file-while-installing - -eslint - diff --git a/Makefile b/Makefile index 9d49e8d5f..0c0ec6c0a 100644 --- a/Makefile +++ b/Makefile @@ -50,8 +50,8 @@ search.checker.%: install $(Q)./manage pyenv.cmd searx-checker -v "$(subst _, ,$(patsubst search.checker.%,%,$@))" PHONY += test ci.test test.shell -ci.test: test.yamllint test.black test.pylint test.unit test.robot test.rst -test: test.yamllint test.black test.pylint test.unit test.robot test.rst test.shell +ci.test: test.yamllint test.black test.pyright test.pylint test.unit test.robot test.rst +test: test.yamllint test.black test.pyright test.pylint test.unit test.robot test.rst test.shell test.shell: $(Q)shellcheck -x -s dash \ dockerfiles/docker-entrypoint.sh @@ -86,7 +86,7 @@ MANAGE += py.build py.clean MANAGE += pyenv pyenv.install pyenv.uninstall MANAGE += pypi.upload pypi.upload.test MANAGE += format.python -MANAGE += test.yamllint test.pylint test.black test.unit test.coverage test.robot test.rst test.clean +MANAGE += test.yamllint test.pylint test.pyright test.black test.unit test.coverage test.robot test.rst test.clean MANAGE += themes.all themes.oscar themes.simple themes.simple.test pygments.less MANAGE += static.build.commit static.build.drop static.build.restore MANAGE += nvm.install nvm.clean nvm.status nvm.nodejs diff --git a/manage b/manage index 1f4ffa53b..6cc98c1be 100755 --- a/manage +++ b/manage @@ -20,6 +20,8 @@ source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_go.sh" # shellcheck source=utils/lib_redis.sh source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_redis.sh" +PATH="${REPO_ROOT}/node_modules/.bin:${PATH}" + # config PYOBJECTS="searx" @@ -103,6 +105,7 @@ format.: test.: yamllint : lint YAML files (YAMLLINT_FILES) pylint : lint PYLINT_FILES, searx/engines, searx & tests + pyright : static type check of python sources black : check black code format unit : run unit tests coverage : run unit tests with coverage @@ -558,6 +561,12 @@ node.env() { dump_return $? } +node.env.devtools() { + nodejs.ensure + build_msg INSTALL "package.json: developer and CI tools" + npm install +} + node.clean() { if ! required_commands npm 2>/dev/null; then build_msg CLEAN "npm is not installed / ignore npm dependencies" @@ -682,6 +691,16 @@ test.pylint() { dump_return $? } +test.pyright() { + build_msg TEST "[pyright] static type check of python sources" + node.env.devtools + # We run Pyright in the virtual environment because Pyright + # executes "python" to determine the Python version. + pyenv.cmd npx --no-install pyright -p pyrightconfig-ci.json + dump_return $? +} + + test.black() { build_msg TEST "[black] \$BLACK_TARGETS" pyenv.cmd black --check --diff "${BLACK_OPTIONS[@]}" "${BLACK_TARGETS[@]}" diff --git a/package.json b/package.json new file mode 100644 index 000000000..e65e0585d --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "eslint": "^8.7.0", + "pyright": "^1.1.212" + } +} diff --git a/pyrightconfig-ci.json b/pyrightconfig-ci.json new file mode 100644 index 000000000..9082b0790 --- /dev/null +++ b/pyrightconfig-ci.json @@ -0,0 +1,10 @@ +{ + "venvPath": "local", + "venv": "py3", + "include": [ + "searx", + "searxng_extra", + "tests" + ], + "typeCheckingMode": "off" +} diff --git a/pyrightconfig.json b/pyrightconfig.json new file mode 100644 index 000000000..56573c75f --- /dev/null +++ b/pyrightconfig.json @@ -0,0 +1,9 @@ +{ + "venvPath": "local", + "venv": "py3", + "include": [ + "searx", + "searxng_extra", + "tests" + ] +} diff --git a/utils/lib_nvm.sh b/utils/lib_nvm.sh index 267ba8a4a..ec0ed5c8f 100755 --- a/utils/lib_nvm.sh +++ b/utils/lib_nvm.sh @@ -117,7 +117,9 @@ nvm.install() { info_msg "checkout ${NVM_VERSION_TAG}" git checkout "${NVM_VERSION_TAG}" 2>&1 | prefix_stdout " ${_Yellow}||${_creset} " popd &> /dev/null - cp "${REPO_ROOT}/.nvm_packages" "${NVM_DIR}/default-packages" + if [ -f "${REPO_ROOT}/.nvm_packages" ]; then + cp "${REPO_ROOT}/.nvm_packages" "${NVM_DIR}/default-packages" + fi nvm.env }