From 25647c20d1904840d089892bb118390f46c66984 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Thu, 31 Jul 2025 13:45:16 +0200 Subject: [mod] switching from pyright to basedpyright (plus first rules) pyrightconfig.json : for the paths searx, searxng_extra and tests, individual rules were defined (for example, in test fewer / different rules are needed than in the searx package searx/engines/__builtins__.pyi : The builtin types that are added to the global namespace of a module by the intended monkey patching of the engine modules / replaces the previous filtering of the stdout using grep. test.pyright_modified (utils/lib_sxng_test.sh) : static type check of local modified files not yet commited make test : prerequisite 'test.pyright' has been replaced by 'test.pyright_modified' searx/engines/__init__.py, searx/enginelib/__init__.py : First, minimal typifications that were considered necessary. --- utils/lib_sxng_test.sh | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'utils') diff --git a/utils/lib_sxng_test.sh b/utils/lib_sxng_test.sh index 0248c3125..22a655722 100755 --- a/utils/lib_sxng_test.sh +++ b/utils/lib_sxng_test.sh @@ -51,25 +51,32 @@ test.pylint() { } test.pyright() { - # use this pyright test for local tests in development / it suppress - # warnings related to intentional monkey patching but gives good hints where - # we need to work on SearXNG's typification. - - build_msg TEST "[pyright/types] static type check of python sources" - node.env.dev - - build_msg TEST "[pyright/types] suppress warnings related to intentional monkey patching" - # We run Pyright in the virtual environment because pyright executes - # "python" to determine the Python version. - pyenv.cmd npx --no-install pyright -p pyrightconfig.json | - grep -E '\.py:[0-9]+:[0-9]+' | - grep -v '/engines/.*.py.* - warning: "logger" is not defined' | - grep -v '/plugins/.*.py.* - error: "logger" is not defined' | - grep -v '/engines/.*.py.* - warning: "supported_languages" is not defined' | - grep -v '/engines/.*.py.* - warning: "language_aliases" is not defined' | - grep -v '/engines/.*.py.* - warning: "categories" is not defined' - # ignore exit value from pyright - # dump_return ${PIPESTATUS[0]} + # For integration into your IDE (editor) use the basedpyright-langserver + # (LSP) installed by 'pipx basedpyright' and read: + # + # - https://docs.basedpyright.com/latest/installation/ides/ + # + # The $REPO_ROOT/pyrightconfig.json uses the virtualenv found in + # $REPO_ROOT/local/py3 and create by a 'make pyenv' + + build_msg TEST "[basedpyright] static type check of python sources" + LANG=C pyenv.cmd basedpyright + # ignore exit value from basedpyright + # dump_return $? + return 0 +} + +test.pyright_modified() { + build_msg TEST "[basedpyright] static type check of local modified files" + local pyrigth_files=() + readarray -t pyrigth_files < <(git status --porcelain | awk 'match($2,".py[i]*$") {print $2}') + if [ ${#pyrigth_files[@]} -eq 0 ]; then + echo "there are no locally modified python files that could be checked" + else + pyenv.cmd basedpyright "${pyrigth_files[@]}" + fi + # ignore exit value from basedpyright + # dump_return $? return 0 } -- cgit v1.2.3