From c075097acdb4e3b2391a2577403f57544e030380 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 14 Sep 2025 22:17:23 +0800 Subject: [PATCH] Allow to run CI checks locally Now the developer is able to run the checks easily and locally (by following the instructions in nova3/README.md). PR #23262. --- .github/workflows/ci_python.yaml | 43 ++++++--------------- .gitignore | 2 +- src/searchengine/.gitignore | 4 ++ src/searchengine/nova3/README.md | 46 +++++++++++++++++++++++ src/searchengine/nova3/justfile | 54 +++++++++++++++++++++++++++ src/searchengine/nova3/pyproject.toml | 25 +++++++++++++ 6 files changed, 142 insertions(+), 32 deletions(-) create mode 100644 src/searchengine/.gitignore create mode 100644 src/searchengine/nova3/README.md create mode 100644 src/searchengine/nova3/justfile create mode 100644 src/searchengine/nova3/pyproject.toml diff --git a/.github/workflows/ci_python.yaml b/.github/workflows/ci_python.yaml index 67c22f5ea..82c0c720d 100644 --- a/.github/workflows/ci_python.yaml +++ b/.github/workflows/ci_python.yaml @@ -59,44 +59,25 @@ jobs: python-version: '3.9' - name: Install tools (search engine) - run: pip install bandit isort mypy pycodestyle pyflakes pyright - - - name: Gather files (search engine) + working-directory: src/searchengine/nova3 run: | - export "PY_FILES=$(find . -type f -name '*.py' -path '*searchengine*' ! -name 'socks.py' -printf '%p ')" - echo $PY_FILES - echo "PY_FILES=$PY_FILES" >> "$GITHUB_ENV" + pip install uv + uv sync - name: Check typings (search engine) - run: | - curl \ - -L \ - -o src/searchengine/nova3/socks.pyi "https://github.com/python/typeshed/raw/refs/heads/main/stubs/PySocks/socks.pyi" - MYPYPATH="src/searchengine/nova3" \ - mypy \ - --explicit-package-bases \ - --strict \ - $PY_FILES - pyright \ - $PY_FILES + working-directory: src/searchengine/nova3 + run: uv run just check - name: Lint code (search engine) - run: | - pyflakes $PY_FILES - bandit --skip B110,B310,B314,B405 $PY_FILES + working-directory: src/searchengine/nova3 + run: uv run just lint - name: Format code (search engine) + working-directory: src/searchengine/nova3 run: | - pycodestyle \ - --ignore=E265,E402 \ - --max-line-length=1000 \ - --statistics \ - $PY_FILES - isort \ - --check \ - --diff \ - $PY_FILES + uv run just format + git diff --exit-code - name: Build code (search engine) - run: | - python -m compileall $PY_FILES + working-directory: src/searchengine/nova3 + run: uv run just build diff --git a/.gitignore b/.gitignore index 17b925842..2057b149f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode/ + src/gui/geoip/GeoIP.dat src/gui/geoip/GeoIP.dat.gz src/qbittorrent @@ -10,7 +11,6 @@ CMakeLists.txt.user* qbittorrent.pro.user* conf.pri Makefile* -*.pyc *.log # Compiled object files diff --git a/src/searchengine/.gitignore b/src/searchengine/.gitignore new file mode 100644 index 000000000..2de2f14c0 --- /dev/null +++ b/src/searchengine/.gitignore @@ -0,0 +1,4 @@ +*.egg-info +*.lock +*.pyc +*.pyi diff --git a/src/searchengine/nova3/README.md b/src/searchengine/nova3/README.md new file mode 100644 index 000000000..1fc0d82c6 --- /dev/null +++ b/src/searchengine/nova3/README.md @@ -0,0 +1,46 @@ +nova3 Engine +=== + +## Development Workflow + +0. Prerequisite + + * A Linux-like environment + * [Python](https://www.python.org/) installed + * [uv](https://docs.astral.sh/uv/) installed + +1. Setup development environment + + 1. Setup virtual environment and dependencies + ```shell + uv sync + ``` + + 2. Activate virtual environment + ```shell + source .venv/bin/activate + ``` + +2. Run type check + + ```shell + just check + ``` + +3. Run static analyzer + + ```shell + just lint + ``` + +4. Apply formatting + + ```shell + just format + ``` + +## References + +* [How to write a search plugin](https://github.com/qbittorrent/search-plugins/wiki/How-to-write-a-search-plugin) +* [just - Command runner](https://just.systems/man/en/) +* [uv - Python package and project manager](https://docs.astral.sh/uv/) diff --git a/src/searchengine/nova3/justfile b/src/searchengine/nova3/justfile new file mode 100644 index 000000000..d8323daaf --- /dev/null +++ b/src/searchengine/nova3/justfile @@ -0,0 +1,54 @@ +PY_FILES := `find . -maxdepth 1 -type f -name '*.py' ! -name 'socks.py' -printf '%P '` + +# Show available recipes to run +default: + just --list + +# Run type check +check files=PY_FILES: fetch_aux + mypy \ + {{ files }} + pyright \ + {{ files }} + +# Byte-compile files +build files=PY_FILES: + python \ + -m compileall \ + {{ files }} + +# Fetch auxiliary files +[private] +fetch_aux: + #!/usr/bin/sh + if [ ! -f 'socks.pyi' ]; then + curl -L -o socks.pyi "https://github.com/python/typeshed/raw/refs/heads/main/stubs/PySocks/socks.pyi" + fi + +# Apply formatting +format files=PY_FILES: + pycodestyle \ + --ignore=E265,E402 \ + --max-line-length=1000 \ + --statistics \ + {{ files }} + isort \ + --line-length 1000 \ + {{ files }} + just \ + --fmt \ + --unstable + +# Run static analyzer +lint files=PY_FILES: + pyflakes \ + {{ files }} + bandit \ + --skip B110,B310,B314,B405 \ + {{ files }} + +# Run tests +test files='tests/*.py': fetch_aux + pytest \ + --showlocals \ + {{ files }} diff --git a/src/searchengine/nova3/pyproject.toml b/src/searchengine/nova3/pyproject.toml new file mode 100644 index 000000000..73b61fa7f --- /dev/null +++ b/src/searchengine/nova3/pyproject.toml @@ -0,0 +1,25 @@ +[project] +name = "qBittorrent-search-engine" +description = "Search engine for qBittorrent search feature" +readme = "README.md" +requires-python = ">=3.9" +dynamic = ["version"] + +[dependency-groups] +dev = [ + "bandit", + "isort", + "mypy", + "pycodestyle", + "pyflakes", + "pyright", + "pytest", + "rust-just", +] + +[tool.mypy] +explicit_package_bases = true +strict = true + +[tool.setuptools.packages.find] +where = ["./"]