Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .codacy.yaml

This file was deleted.

15 changes: 10 additions & 5 deletions .github/workflows/run-validations.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Validations

on: [push]
on:
push:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
Expand All @@ -14,10 +19,10 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Python dependencies and run acceptance tests
run: |
pip3 install --user --ignore-installed -r requirements-dev.txt
flake8 --exclude=scripts/,src/,.cache,.git,.idea,.tox,._trial_temp/,venv/ --ignore F811,E402
- name: Install Ruff
run: pip3 install --user "ruff==0.17.*"
- name: Ruff lint

@jguz-pubnub jguz-pubnub Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruff replaces flake8 (and Codacy) for linting; the rules mirror the previous flake8 setup. Also, ruff format is intentionally not enforced because the legacy codebase is not ruff-formatted. The estimated scope is ~280 of ~360 files, ~17k changed lines. Therefore, formatting it here would bury functional changes and break git blame. This should be done in a separate, formatting-only PR.

run: ruff check .
- name: Cancel workflow runs for commit on error
if: failure()
uses: ./.github/.release/actions/actions/utils/fast-jobs-failure
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/vulnerability-scan.yml
Original file line number Diff line number Diff line change
@@ -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 }}
10 changes: 8 additions & 2 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ 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 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

`.github/workflows/vulnerability-scan.yml` runs Snyk on pushes to `master` and `main` to monitor the dependencies declared in `setup.py`.

## Pull requests

- Include tests for behavioral changes and keep the test matrix green on all supported Python versions.
Expand Down
1 change: 0 additions & 1 deletion bandit.yml

This file was deleted.

1 change: 1 addition & 0 deletions examples/pubnub_asyncio_simple/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pubnub/endpoints/access/grant_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pubnub/endpoints/access/revoke_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pubnub/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions pubnub/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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:
Expand All @@ -105,7 +105,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:
Expand Down
2 changes: 1 addition & 1 deletion pubnub/pubnub.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def _run(self):
return
try:
self._callback()
except Exception:
except Exception: # noqa: S110
# TODO: handle the exception
pass
finally:
Expand Down
2 changes: 1 addition & 1 deletion pubnub/request_handlers/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pyyaml>=6.0
pytest-cov>=6.0.0
pycryptodomex>=3.21.0
flake8>=7.1.2
ruff==0.17.*
pytest>=8.3.5
pytest-asyncio>=1.0.0
httpx>=0.28
Expand Down
57 changes: 57 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
line-length = 120
extend-exclude = ["scripts", "src", ".cache", ".idea", ".tox", "venv"]

[lint]
preview = true
select = ["E", "F", "W", "S", "B", "PL", "SIM", "C90"]
ignore = [
"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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the highest value is 25. This should be lowered over time as an SDK is refactored or improved.


[lint.per-file-ignores]
"tests/**" = ["S", "B", "PL", "SIM", "C90"]
"examples/**" = ["S104", "S108", "S110"]
2 changes: 1 addition & 1 deletion scripts/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
[tool:pytest]
norecursedirs = benchmarks

[flake8]
max-line-length = 120
ignore=E402
1 change: 0 additions & 1 deletion tests/integrational/native_sync/test_publish.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import unittest
import urllib
import urllib.parse

import pubnub
Expand Down
Loading