From 56ceff63d41341b0f5d1c43c08a70a1ea80e8ca2 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 11:52:33 +0100 Subject: [PATCH 01/16] Add Ruff configuration replacing flake8 Co-Authored-By: Claude Sonnet 5.5 --- requirements-dev.txt | 2 +- ruff.toml | 10 ++++++++++ setup.cfg | 4 ---- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 ruff.toml diff --git a/requirements-dev.txt b/requirements-dev.txt index 27b01f43..abff738d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1,7 @@ pyyaml>=6.0 pytest-cov>=6.0.0 pycryptodomex>=3.21.0 -flake8>=7.1.2 +ruff>=0.8 pytest>=8.3.5 pytest-asyncio>=1.0.0 httpx>=0.28 diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..3d0bd17e --- /dev/null +++ b/ruff.toml @@ -0,0 +1,10 @@ +# Ruff replaces flake8 (and Codacy) for linting; rules mirror the previous flake8 setup. +line-length = 120 +extend-exclude = ["scripts", "src", ".cache", ".idea", ".tox", "venv"] + +[lint] +select = ["E", "F", "W"] +ignore = [ + "E402", # module-level import not at top (was ignored in flake8 config) + "F811", # redefinition of unused name (was ignored in CI flake8 invocation) +] diff --git a/setup.cfg b/setup.cfg index c43582b6..7a066ed4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,2 @@ [tool:pytest] norecursedirs = benchmarks - -[flake8] -max-line-length = 120 -ignore=E402 \ No newline at end of file From 507115497df3ad50161a475bc9f2560624ad3fc3 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 11:52:33 +0100 Subject: [PATCH 02/16] Run Ruff lint and format checks in CI on every PR Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/run-validations.yml | 19 +++++++++++++++---- DEVELOPER.md | 7 +++++-- scripts/run-tests.py | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index 2f3b2b4e..bd6bb652 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -1,6 +1,8 @@ name: Validations -on: [push] +on: + push: + pull_request: jobs: lint: @@ -14,10 +16,19 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.11" - - name: Install Python dependencies and run acceptance tests + - name: Install Ruff + run: pip3 install --user "ruff>=0.8" + - name: Ruff lint + run: ruff check . + - name: Ruff format (files changed vs. base branch) + # The legacy codebase is not yet ruff-formatted; enforce formatting on touched files only. run: | - pip3 install --user --ignore-installed -r requirements-dev.txt - flake8 --exclude=scripts/,src/,.cache,.git,.idea,.tox,._trial_temp/,venv/ --ignore F811,E402 + base="${{ github.event.pull_request.base.sha || github.event.before }}" + if [ -z "$base" ] || [ "$base" = "0000000000000000000000000000000000000000" ] || ! git cat-file -e "$base" 2>/dev/null; then + git fetch --no-tags --depth=1 origin master && base=FETCH_HEAD + fi + files=$(git diff --name-only --diff-filter=ACMR "$base" HEAD -- '*.py' '*.pyi') + if [ -n "$files" ]; then echo "$files" | xargs ruff format --check --diff; fi - name: Cancel workflow runs for commit on error if: failure() uses: ./.github/.release/actions/actions/utils/fast-jobs-failure diff --git a/DEVELOPER.md b/DEVELOPER.md index acf205ba..ad979d68 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -24,12 +24,15 @@ This runs `py.test tests --cov=pubnub --ignore=tests/manual/`. ## Linting -CI runs flake8 in `.github/workflows/run-validations.yml`. To run the same check locally: +CI runs Ruff (config in `ruff.toml`) in `.github/workflows/run-validations.yml`. To run the same checks locally: ```sh -flake8 --exclude=scripts/,src/,.cache,.git,.idea,.tox,._trial_temp/,venv/ --ignore F811,E402 +ruff check . +ruff format --check ``` +`ruff check` is enforced on the whole repository. `ruff format --check` is enforced in CI only for Python files changed in a PR, because the legacy code is not yet formatted. + ## Pull requests - Include tests for behavioral changes and keep the test matrix green on all supported Python versions. diff --git a/scripts/run-tests.py b/scripts/run-tests.py index 80ff48a0..ccd216c2 100755 --- a/scripts/run-tests.py +++ b/scripts/run-tests.py @@ -12,7 +12,7 @@ os.chdir(os.path.join(REPO_ROOT)) tcmn = 'py.test tests --cov=pubnub --ignore=tests/manual/' -fcmn = 'flake8 --exclude=scripts/,src/,.cache,.git,.idea,.tox,._trial_temp/,venv/ --ignore F811,E402' +fcmn = 'ruff check .' def run(command): From b2ea061bf12f8fd400d28f928ba026a18044aed8 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 11:52:34 +0100 Subject: [PATCH 03/16] Remove Codacy configuration Co-Authored-By: Claude Sonnet 5.5 --- .codacy.yaml | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .codacy.yaml diff --git a/.codacy.yaml b/.codacy.yaml deleted file mode 100644 index a8feb408..00000000 --- a/.codacy.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -exclude_paths: - - "tests/**" \ No newline at end of file From 2a7f4b23c1e470cd7a1d80a5f53d951f04d52ab6 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 12:01:49 +0100 Subject: [PATCH 04/16] Unify Validations workflow triggers and concurrency Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/run-validations.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index bd6bb652..7503770f 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -3,6 +3,10 @@ name: Validations on: push: pull_request: + workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: lint: From 52ff2c38a20c96ae8e0a019f85335a22565092b7 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 12:02:34 +0100 Subject: [PATCH 05/16] Run Validations on push only Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/run-validations.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index 7503770f..21672d26 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -2,7 +2,6 @@ name: Validations on: push: - pull_request: workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} From ac08d04967644282ce430a26f6daebec0518e7c0 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 12:02:41 +0100 Subject: [PATCH 06/16] Drop unused pull_request reference from format check Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/run-validations.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index 21672d26..5f9de312 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -26,7 +26,7 @@ jobs: - name: Ruff format (files changed vs. base branch) # The legacy codebase is not yet ruff-formatted; enforce formatting on touched files only. run: | - base="${{ github.event.pull_request.base.sha || github.event.before }}" + base="${{ github.event.before }}" if [ -z "$base" ] || [ "$base" = "0000000000000000000000000000000000000000" ] || ! git cat-file -e "$base" 2>/dev/null; then git fetch --no-tags --depth=1 origin master && base=FETCH_HEAD fi From 3c37fd971a57aa92fbe2f3ce23c2f108a8e02138 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 12:15:42 +0100 Subject: [PATCH 07/16] Lint only in CI; drop ruff format check Formatting the legacy codebase should be done in a separate PR. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/run-validations.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index 5f9de312..c27e4cea 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -21,17 +21,12 @@ jobs: python-version: "3.11" - name: Install Ruff run: pip3 install --user "ruff>=0.8" + # Lint only. `ruff format` is intentionally not enforced: the legacy codebase is not ruff-formatted + # (~280 of ~360 files, ~17k changed lines), so formatting it here would bury functional changes in + # noise and break `git blame`. Do it in a separate, formatting-only PR (and add its commit to + # .git-blame-ignore-revs) before enabling a `ruff format --check .` step. - name: Ruff lint run: ruff check . - - name: Ruff format (files changed vs. base branch) - # The legacy codebase is not yet ruff-formatted; enforce formatting on touched files only. - run: | - base="${{ github.event.before }}" - if [ -z "$base" ] || [ "$base" = "0000000000000000000000000000000000000000" ] || ! git cat-file -e "$base" 2>/dev/null; then - git fetch --no-tags --depth=1 origin master && base=FETCH_HEAD - fi - files=$(git diff --name-only --diff-filter=ACMR "$base" HEAD -- '*.py' '*.pyi') - if [ -n "$files" ]; then echo "$files" | xargs ruff format --check --diff; fi - name: Cancel workflow runs for commit on error if: failure() uses: ./.github/.release/actions/actions/utils/fast-jobs-failure From a9b121e260f775aed5d26c262ea166cd32a8510a Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 12:16:49 +0100 Subject: [PATCH 08/16] Move ruff format note from workflow to PR comment Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/run-validations.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index c27e4cea..c6061247 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -21,10 +21,6 @@ jobs: python-version: "3.11" - name: Install Ruff run: pip3 install --user "ruff>=0.8" - # Lint only. `ruff format` is intentionally not enforced: the legacy codebase is not ruff-formatted - # (~280 of ~360 files, ~17k changed lines), so formatting it here would bury functional changes in - # noise and break `git blame`. Do it in a separate, formatting-only PR (and add its commit to - # .git-blame-ignore-revs) before enabling a `ruff format --check .` step. - name: Ruff lint run: ruff check . - name: Cancel workflow runs for commit on error From 8091d09a0b73aef59d0242e8fa12bff3c133774d Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 12:17:36 +0100 Subject: [PATCH 09/16] Remove header comment from ruff.toml Co-Authored-By: Claude Sonnet 5.5 --- ruff.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/ruff.toml b/ruff.toml index 3d0bd17e..93dd61c3 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,4 +1,3 @@ -# Ruff replaces flake8 (and Codacy) for linting; rules mirror the previous flake8 setup. line-length = 120 extend-exclude = ["scripts", "src", ".cache", ".idea", ".tox", "venv"] From 24987c396d1a1a3d7d025fef176b8013ecb9ae6d Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 12:51:02 +0100 Subject: [PATCH 10/16] Add Ruff preview rules for flake8 parity, exclude tests, pin Ruff, add Snyk scan Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/run-validations.yml | 2 +- .github/workflows/vulnerability-scan.yml | 28 ++++++++++++++++++++++++ examples/pubnub_asyncio_simple/main.py | 1 + requirements-dev.txt | 2 +- ruff.toml | 4 +++- 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/vulnerability-scan.yml diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index c6061247..0d256e28 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -20,7 +20,7 @@ jobs: with: python-version: "3.11" - name: Install Ruff - run: pip3 install --user "ruff>=0.8" + run: pip3 install --user "ruff==0.17.*" - name: Ruff lint run: ruff check . - name: Cancel workflow runs for commit on error diff --git a/.github/workflows/vulnerability-scan.yml b/.github/workflows/vulnerability-scan.yml new file mode 100644 index 00000000..ef09fc20 --- /dev/null +++ b/.github/workflows/vulnerability-scan.yml @@ -0,0 +1,28 @@ +name: Vulnerability scan +on: + push: + branches: + - master + - main + workflow_dispatch: + +jobs: + security: + name: Snyk dependency scan + runs-on: + group: organization/Default + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: "3.11" + - name: Install SDK dependencies + run: pip3 install --user . + - name: Setup Snyk CLI + uses: snyk/actions/setup@master + - name: Run Snyk monitor for vulnerabilities + run: snyk monitor --org=sdk --file=setup.py + env: + SNYK_TOKEN: ${{ secrets.SNYK_SDK_TOKEN }} diff --git a/examples/pubnub_asyncio_simple/main.py b/examples/pubnub_asyncio_simple/main.py index b7fb893d..5914b10c 100644 --- a/examples/pubnub_asyncio_simple/main.py +++ b/examples/pubnub_asyncio_simple/main.py @@ -30,6 +30,7 @@ async def main(pubnub): while True: await asyncio.sleep(1) + if __name__ == "__main__": loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) diff --git a/requirements-dev.txt b/requirements-dev.txt index abff738d..6d601b1e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1,7 @@ pyyaml>=6.0 pytest-cov>=6.0.0 pycryptodomex>=3.21.0 -ruff>=0.8 +ruff==0.17.* pytest>=8.3.5 pytest-asyncio>=1.0.0 httpx>=0.28 diff --git a/ruff.toml b/ruff.toml index 93dd61c3..5cc1cbb0 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,7 +1,9 @@ line-length = 120 -extend-exclude = ["scripts", "src", ".cache", ".idea", ".tox", "venv"] +extend-exclude = ["scripts", "src", "tests", ".cache", ".idea", ".tox", "venv"] [lint] +# preview enables pycodestyle E1/E2/E3 (indentation, whitespace, blank lines), which flake8 checked +preview = true select = ["E", "F", "W"] ignore = [ "E402", # module-level import not at top (was ignored in flake8 config) From afffae8c6b7c9f1cfe97646265151d6a90843a2e Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 12:54:09 +0100 Subject: [PATCH 11/16] Update DEVELOPER.md for Ruff setup and vulnerability scan Co-Authored-By: Claude Sonnet 5.5 --- DEVELOPER.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index ad979d68..3ee5bc89 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -28,10 +28,13 @@ CI runs Ruff (config in `ruff.toml`) in `.github/workflows/run-validations.yml`. ```sh ruff check . -ruff format --check ``` -`ruff check` is enforced on the whole repository. `ruff format --check` is enforced in CI only for Python files changed in a PR, because the legacy code is not yet formatted. +`ruff check` is enforced on the whole repository, except `tests`, `scripts` and `src`. Ruff is pinned to `0.17.*` and runs in preview mode so the pycodestyle indentation, whitespace and blank-line rules stay enabled. Formatting is not checked in CI. + +## Vulnerability scan + +`.github/workflows/vulnerability-scan.yml` runs Snyk on pushes to `master` and `main` to monitor the dependencies declared in `setup.py`. ## Pull requests From 4eb6a5ddaf33d6ed14aa4ec5b699accb71995567 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 13:02:54 +0100 Subject: [PATCH 12/16] Enable Ruff security rules (S) to replace Codacy Bandit checks Co-Authored-By: Claude Sonnet 5.5 --- DEVELOPER.md | 2 +- bandit.yml | 1 - pubnub/endpoints/access/grant_token.py | 2 +- pubnub/endpoints/access/revoke_token.py | 2 +- pubnub/errors.py | 4 ++-- pubnub/managers.py | 4 ++-- pubnub/pubnub.py | 2 +- pubnub/request_handlers/httpx.py | 2 +- ruff.toml | 6 +++++- 9 files changed, 14 insertions(+), 11 deletions(-) delete mode 100644 bandit.yml diff --git a/DEVELOPER.md b/DEVELOPER.md index 3ee5bc89..1b610d0e 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -30,7 +30,7 @@ CI runs Ruff (config in `ruff.toml`) in `.github/workflows/run-validations.yml`. ruff check . ``` -`ruff check` is enforced on the whole repository, except `tests`, `scripts` and `src`. Ruff is pinned to `0.17.*` and runs in preview mode so the pycodestyle indentation, whitespace and blank-line rules stay enabled. Formatting is not checked in CI. +`ruff check` is enforced on the whole repository, except `tests`, `scripts` and `src`. Ruff is pinned to `0.17.*` and runs in preview mode so the pycodestyle indentation, whitespace and blank-line rules stay enabled. Security rules (`S`, the flake8-bandit port) are enabled, with `assert` allowed. Formatting is not checked in CI. ## Vulnerability scan diff --git a/bandit.yml b/bandit.yml deleted file mode 100644 index 75d550c3..00000000 --- a/bandit.yml +++ /dev/null @@ -1 +0,0 @@ -skips: ['B101'] diff --git a/pubnub/endpoints/access/grant_token.py b/pubnub/endpoints/access/grant_token.py index 35d9ec9b..7fb6ff52 100644 --- a/pubnub/endpoints/access/grant_token.py +++ b/pubnub/endpoints/access/grant_token.py @@ -22,7 +22,7 @@ class PNGrantTokenResultEnvelope(Envelope): class GrantToken(Endpoint): - GRANT_TOKEN_PATH = "/v3/pam/%s/grant" + GRANT_TOKEN_PATH = "/v3/pam/%s/grant" # noqa: S105 def __init__(self, pubnub, channels: Union[str, List[str]] = None, channel_groups: Union[str, List[str]] = None, users: Union[str, List[str]] = None, spaces: Union[str, List[str]] = None, diff --git a/pubnub/endpoints/access/revoke_token.py b/pubnub/endpoints/access/revoke_token.py index 38cede49..a6940bb7 100644 --- a/pubnub/endpoints/access/revoke_token.py +++ b/pubnub/endpoints/access/revoke_token.py @@ -12,7 +12,7 @@ class PNRevokeTokenResultEnvelope(Envelope): class RevokeToken(Endpoint): - REVOKE_TOKEN_PATH = "/v3/pam/%s/grant/%s" + REVOKE_TOKEN_PATH = "/v3/pam/%s/grant/%s" # noqa: S105 def __init__(self, pubnub, token: str): Endpoint.__init__(self, pubnub) diff --git a/pubnub/errors.py b/pubnub/errors.py index 6f6c8491..606e61f8 100644 --- a/pubnub/errors.py +++ b/pubnub/errors.py @@ -15,7 +15,7 @@ PNERR_GROUP_MISSING = "Channel group missing" PNERR_MESSAGE_MISSING = "Message missing" PNERR_SUBSCRIBE_KEY_MISSING = "Subscribe key not configured" -PNERR_SECRET_KEY_MISSING = "Secret key is not configured" +PNERR_SECRET_KEY_MISSING = "Secret key is not configured" # noqa: S105 PNERR_PUBLISH_KEY_MISSING = "Publish key not configured" PNERR_PUBLISH_META_WRONG_TYPE = "Publish meta should be dict" PNERR_DEFERRED_NOT_IMPLEMENTED = "Deferred endpoint call is not implemented by this platform" @@ -32,7 +32,7 @@ PNERR_RESOURCES_MISSING = "Resources missing" PNERR_TTL_MISSING = "TTL missing" PNERR_INVALID_META = "Invalid meta parameter" -PNERR_INVALID_ACCESS_TOKEN = "Invalid access token" +PNERR_INVALID_ACCESS_TOKEN = "Invalid access token" # noqa: S105 PNERR_MESSAGE_ACTION_MISSING = "Message action is missing" PNERR_MESSAGE_ACTION_TYPE_MISSING = "Message action type is missing" PNERR_MESSAGE_ACTION_VALUE_MISSING = "Message action value is missing" diff --git a/pubnub/managers.py b/pubnub/managers.py index 08e86877..6af3f0f6 100644 --- a/pubnub/managers.py +++ b/pubnub/managers.py @@ -91,7 +91,7 @@ class LinearDelay: @classmethod def calculate(cls, attempt: int, delay=None): base = delay if delay is not None else cls.INTERVAL - return base + round(random.random(), 3) + return base + round(random.random(), 3) # noqa: S311 retry jitter, not security class ExponentialDelay: @@ -104,7 +104,7 @@ class ExponentialDelay: def calculate(cls, attempt: int, minimum_delay=None, maximum_delay=None) -> float: min_delay = minimum_delay if minimum_delay is not None else cls.MIN_DELAY max_backoff = maximum_delay if maximum_delay is not None else cls.MAX_BACKOFF - return min(max_backoff, min_delay * (2 ** attempt)) + round(random.random(), 3) + return min(max_backoff, min_delay * (2 ** attempt)) + round(random.random(), 3) # noqa: S311 class StateManager: diff --git a/pubnub/pubnub.py b/pubnub/pubnub.py index 495a6872..33dd77fb 100644 --- a/pubnub/pubnub.py +++ b/pubnub/pubnub.py @@ -513,7 +513,7 @@ def _run(self): return try: self._callback() - except Exception: + except Exception: # noqa: S110 # TODO: handle the exception pass finally: diff --git a/pubnub/request_handlers/httpx.py b/pubnub/request_handlers/httpx.py index 7a1fe872..21c3dc4c 100644 --- a/pubnub/request_handlers/httpx.py +++ b/pubnub/request_handlers/httpx.py @@ -111,7 +111,7 @@ def _force_shutdown_connections(session): if sock is None: continue sock.shutdown(socket.SHUT_RDWR) - except (OSError, Exception): + except (OSError, Exception): # noqa: S110 best-effort socket shutdown pass except Exception as e: logger.debug(f"Error iterating connection pool: {e}") diff --git a/ruff.toml b/ruff.toml index 5cc1cbb0..4a7411cb 100644 --- a/ruff.toml +++ b/ruff.toml @@ -4,8 +4,12 @@ extend-exclude = ["scripts", "src", "tests", ".cache", ".idea", ".tox", "venv"] [lint] # preview enables pycodestyle E1/E2/E3 (indentation, whitespace, blank lines), which flake8 checked preview = true -select = ["E", "F", "W"] +select = ["E", "F", "W", "S"] ignore = [ "E402", # module-level import not at top (was ignored in flake8 config) "F811", # redefinition of unused name (was ignored in CI flake8 invocation) + "S101", # assert (was skipped as B101 in bandit.yml) ] + +[lint.per-file-ignores] +"examples/**" = ["S104", "S108", "S110"] # demo code: bind-all, temp file, try/except/pass From 1d82d717a9ff23dcc631303a96af05aca06b7c00 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Wed, 18 Nov 2026 13:05:12 +0100 Subject: [PATCH 13/16] ruff.toml --- ruff.toml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ruff.toml b/ruff.toml index 4a7411cb..5a4472ca 100644 --- a/ruff.toml +++ b/ruff.toml @@ -2,13 +2,12 @@ line-length = 120 extend-exclude = ["scripts", "src", "tests", ".cache", ".idea", ".tox", "venv"] [lint] -# preview enables pycodestyle E1/E2/E3 (indentation, whitespace, blank lines), which flake8 checked preview = true select = ["E", "F", "W", "S"] ignore = [ - "E402", # module-level import not at top (was ignored in flake8 config) - "F811", # redefinition of unused name (was ignored in CI flake8 invocation) - "S101", # assert (was skipped as B101 in bandit.yml) + "E402", # module-level import not at top + "F811", # redefinition of unused name + "S101", # assert ] [lint.per-file-ignores] From 3bdf538cf25c3e53ced5ad20c00a7adfe28a8bf7 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Thu, 19 Nov 2026 17:21:04 +0100 Subject: [PATCH 14/16] DEVELOPER.md + ruff.toml --- DEVELOPER.md | 2 +- ruff.toml | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index 1b610d0e..4eeac5b9 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -30,7 +30,7 @@ CI runs Ruff (config in `ruff.toml`) in `.github/workflows/run-validations.yml`. ruff check . ``` -`ruff check` is enforced on the whole repository, except `tests`, `scripts` and `src`. Ruff is pinned to `0.17.*` and runs in preview mode so the pycodestyle indentation, whitespace and blank-line rules stay enabled. Security rules (`S`, the flake8-bandit port) are enabled, with `assert` allowed. Formatting is not checked in CI. +`ruff check` covers the whole repository except `tests`, `scripts` and `src`. Ruff is pinned to `0.17.*` and runs in preview mode. Enabled rule sets: `E`, `F`, `W` (pycodestyle, Pyflakes), `S` (security, `assert` allowed), `B` (bugbear), `PL` (Pylint), `SIM` (simplify) and `C90` (complexity). Disabled rules are commented in `ruff.toml`; remove baseline entries as they are fixed. Formatting is not checked in CI. ## Vulnerability scan diff --git a/ruff.toml b/ruff.toml index 5a4472ca..a0ae14aa 100644 --- a/ruff.toml +++ b/ruff.toml @@ -3,12 +3,54 @@ extend-exclude = ["scripts", "src", "tests", ".cache", ".idea", ".tox", "venv"] [lint] preview = true -select = ["E", "F", "W", "S"] +select = ["E", "F", "W", "S", "B", "PL", "SIM", "C90"] ignore = [ - "E402", # module-level import not at top - "F811", # redefinition of unused name - "S101", # assert + "E402", # module-level import not at top + "F811", # redefinition of unused name + "S101", # assert + "PLR0904", # too many public methods + "PLR0911", # too many return statements + "PLR0912", # too many branches + "PLR0913", # too many arguments + "PLR0914", # too many local variables + "PLR0915", # too many statements + "PLR0916", # too many boolean expressions + "PLR0917", # too many positional arguments + "PLR2004", # magic value in comparison + "PLR6301", # method could be a function (no self use) + "PLW0717", # too many statements in try clause + "B006", # mutable argument default + "B018", # useless expression + "B028", # warnings.warn without explicit stacklevel + "B903", # class that could be a dataclass/namedtuple + "B904", # raise inside except without `from` + "B909", # mutating a collection while iterating over it + "SIM102", # nested ifs that can be collapsed + "SIM105", # try/except/pass that can use contextlib.suppress + "SIM108", # if/else block that can be a ternary + "SIM113", # manual loop counter instead of enumerate + "SIM114", # if branches with identical bodies + "SIM115", # open() without a context manager + "SIM118", # `key in dict.keys()` + "SIM211", # `False if x else True` instead of `not x` + "SIM300", # Yoda condition + "SIM401", # if/else that can be dict.get + "PLC0414", # useless import alias + "PLC0415", # import outside top level + "PLC1901", # comparison to empty string + "PLE0307", # __str__ returning non-str + "PLR1722", # exit() instead of sys.exit() + "PLR5501", # else + if that can be elif + "PLR6201", # list/tuple literal in membership test (use set) + "PLW0108", # unnecessary lambda + "PLW0127", # self-assigning variable + "PLW0128", # redeclared assigned name + "PLW1508", # non-string default for os.getenv + "PLW1514", # open() without explicit encoding ] +[lint.mccabe] +max-complexity = 25 # baseline: highest existing is 25, lower as functions are refactored + [lint.per-file-ignores] "examples/**" = ["S104", "S108", "S110"] # demo code: bind-all, temp file, try/except/pass From c569a816bfee70a6ea9fc8f6d68ca6d5b0fe2aef Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Thu, 19 Nov 2026 17:38:38 +0100 Subject: [PATCH 15/16] Add Ruff B, PL, SIM and C90 rules and lint tests with E, F, W Enable bugbear, Pylint, simplify and McCabe rule sets with a baseline ignore list for existing violations and noisy Pylint design metrics. Stop excluding tests to match the previous flake8 setup, limiting them to E, F and W, and remove a redundant urllib import. Co-Authored-By: Claude Sonnet 5.5 --- DEVELOPER.md | 2 +- ruff.toml | 3 ++- tests/integrational/native_sync/test_publish.py | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index 4eeac5b9..21e1ed9b 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -30,7 +30,7 @@ CI runs Ruff (config in `ruff.toml`) in `.github/workflows/run-validations.yml`. ruff check . ``` -`ruff check` covers the whole repository except `tests`, `scripts` and `src`. Ruff is pinned to `0.17.*` and runs in preview mode. Enabled rule sets: `E`, `F`, `W` (pycodestyle, Pyflakes), `S` (security, `assert` allowed), `B` (bugbear), `PL` (Pylint), `SIM` (simplify) and `C90` (complexity). Disabled rules are commented in `ruff.toml`; remove baseline entries as they are fixed. Formatting is not checked in CI. +`ruff check` covers the whole repository except `scripts` and `src`. In `tests`, only `E`, `F` and `W` apply. Ruff is pinned to `0.17.*` and runs in preview mode. Enabled rule sets: `E`, `F`, `W` (pycodestyle, Pyflakes), `S` (security, `assert` allowed), `B` (bugbear), `PL` (Pylint), `SIM` (simplify) and `C90` (complexity). Disabled rules are commented in `ruff.toml`; remove baseline entries as they are fixed. Formatting is not checked in CI. ## Vulnerability scan diff --git a/ruff.toml b/ruff.toml index a0ae14aa..5aecb5a4 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,5 +1,5 @@ line-length = 120 -extend-exclude = ["scripts", "src", "tests", ".cache", ".idea", ".tox", "venv"] +extend-exclude = ["scripts", "src", ".cache", ".idea", ".tox", "venv"] [lint] preview = true @@ -53,4 +53,5 @@ ignore = [ max-complexity = 25 # baseline: highest existing is 25, lower as functions are refactored [lint.per-file-ignores] +"tests/**" = ["S", "B", "PL", "SIM", "C90"] "examples/**" = ["S104", "S108", "S110"] # demo code: bind-all, temp file, try/except/pass diff --git a/tests/integrational/native_sync/test_publish.py b/tests/integrational/native_sync/test_publish.py index 7a81f244..d3c70c35 100644 --- a/tests/integrational/native_sync/test_publish.py +++ b/tests/integrational/native_sync/test_publish.py @@ -1,6 +1,5 @@ import logging import unittest -import urllib import urllib.parse import pubnub From de33cd301eec2a19beb2cd0ee72a90d6005400d8 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Thu, 19 Nov 2026 17:45:01 +0100 Subject: [PATCH 16/16] ruff.toml --- ruff.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruff.toml b/ruff.toml index 5aecb5a4..68026041 100644 --- a/ruff.toml +++ b/ruff.toml @@ -50,8 +50,8 @@ ignore = [ ] [lint.mccabe] -max-complexity = 25 # baseline: highest existing is 25, lower as functions are refactored +max-complexity = 25 [lint.per-file-ignores] "tests/**" = ["S", "B", "PL", "SIM", "C90"] -"examples/**" = ["S104", "S108", "S110"] # demo code: bind-all, temp file, try/except/pass +"examples/**" = ["S104", "S108", "S110"]