diff --git a/.github/workflows/_build.yaml b/.github/workflows/_build.yaml index f518ef8..db6c312 100644 --- a/.github/workflows/_build.yaml +++ b/.github/workflows/_build.yaml @@ -37,6 +37,7 @@ jobs: github.com:443 objects.githubusercontent.com:443 pypi.org:443 + raw.githubusercontent.com:443 release-assets.githubusercontent.com:443 - name: Checkout repository diff --git a/.github/workflows/_test_futures_private.yaml b/.github/workflows/_test_futures_private.yaml index 61915cd..5dba5cd 100644 --- a/.github/workflows/_test_futures_private.yaml +++ b/.github/workflows/_test_futures_private.yaml @@ -56,6 +56,7 @@ jobs: github.com:443 objects.githubusercontent.com:443 pypi.org:443 + raw.githubusercontent.com:443 release-assets.githubusercontent.com:443 - name: Checkout repository diff --git a/.github/workflows/_test_futures_public.yaml b/.github/workflows/_test_futures_public.yaml index b202354..7c828d9 100644 --- a/.github/workflows/_test_futures_public.yaml +++ b/.github/workflows/_test_futures_public.yaml @@ -41,6 +41,7 @@ jobs: futures.kraken.com:443 github.com:443 objects.githubusercontent.com:443 + raw.githubusercontent.com:443 release-assets.githubusercontent.com:443 pypi.org:443 diff --git a/.github/workflows/_test_spot_private.yaml b/.github/workflows/_test_spot_private.yaml index 84b6467..7bce0e2 100644 --- a/.github/workflows/_test_spot_private.yaml +++ b/.github/workflows/_test_spot_private.yaml @@ -56,6 +56,7 @@ jobs: github.com:443 objects.githubusercontent.com:443 pypi.org:443 + raw.githubusercontent.com:443 release-assets.githubusercontent.com:443 ws-auth.kraken.com:443 ws.kraken.com:443 diff --git a/.github/workflows/_test_spot_public.yaml b/.github/workflows/_test_spot_public.yaml index c4ddafd..8c7b863 100644 --- a/.github/workflows/_test_spot_public.yaml +++ b/.github/workflows/_test_spot_public.yaml @@ -42,6 +42,7 @@ jobs: github.com:443 objects.githubusercontent.com:443 pypi.org:443 + raw.githubusercontent.com:443 release-assets.githubusercontent.com:443 ws.kraken.com:443 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1cfe250..74c7bb7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.14.6 + rev: v0.15.7 hooks: - id: ruff-check args: @@ -20,7 +20,7 @@ repos: # - --preview # - --exit-non-zero-on-fix - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.18.2 + rev: v1.19.1 hooks: - id: mypy name: mypy @@ -31,11 +31,11 @@ repos: - --install-types - --non-interactive - repo: https://github.com/gitleaks/gitleaks - rev: v8.29.1 + rev: v8.30.1 hooks: - id: gitleaks - repo: https://github.com/codespell-project/codespell - rev: v2.4.1 + rev: v2.4.2 hooks: - id: codespell additional_dependencies: [tomli] @@ -72,21 +72,21 @@ repos: - id: rst-inline-touching-normal - id: text-unicode-replacement-char - repo: https://github.com/psf/black - rev: 25.11.0 + rev: 26.3.1 hooks: - id: black - repo: https://github.com/rbubley/mirrors-prettier - rev: v3.6.2 + rev: v3.8.1 hooks: - id: prettier - repo: https://github.com/PyCQA/isort # TODO: remove as soon as ruff is stable - rev: 7.0.0 + rev: 8.0.1 hooks: - id: isort args: - --profile=black - repo: https://github.com/PyCQA/bandit - rev: 1.9.1 + rev: 1.9.4 hooks: - id: bandit exclude: "^tests/.*|examples/.*" diff --git a/Makefile b/Makefile index 5927a71..95ff591 100644 --- a/Makefile +++ b/Makefile @@ -7,11 +7,11 @@ # UV ?= uv -PYTHON := python -PYTEST := $(UV) run pytest -PYTEST_OPTS := -vv --junit-xml=pytest.xml -PYTEST_COV_OPTS := $(PYTEST_OPTS) --cov=kraken --cov-report=xml:coverage.xml --cov-report=term-missing --cov-report=html -TEST_DIR := tests +PYTHON ?= python +PYTEST ?= $(UV) run pytest +PYTEST_OPTS ?= -vv --junit-xml=pytest.xml +PYTEST_COV_OPTS ?= $(PYTEST_OPTS) --cov=kraken --cov-report=xml:coverage.xml --cov-report=term-missing --cov-report=html +TEST_DIR ?= tests ## ======= M A K E F I L E - T A R G E T S ===================================== ## help Show this help message @@ -136,7 +136,8 @@ clean: dist/ \ doc/_build \ src/python_kraken_sdk.egg-info \ - build/ + build/ \ + htmlcov/ rm -f .coverage \ *.csv \ @@ -146,7 +147,8 @@ clean: src/kraken/_version.py \ mypy.xml \ pytest.xml \ - tests/*.zip + tests/*.zip \ + uv.lock find tests -name "__pycache__" | xargs rm -rf find src -name "__pycache__" | xargs rm -rf diff --git a/doc/conf.py b/doc/conf.py index 33cb877..cd46006 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -41,10 +41,8 @@ # Add the package to sys.path: sys.path.insert(0, str(Path("..").resolve() / "src")) -rst_epilog = "" # Read link all targets from file -with Path("links.rst").open(encoding="utf-8") as f: - rst_epilog += f.read() +rst_epilog = Path("links.rst").read_text(encoding="utf-8") def setup(app: Any) -> None: # noqa: ARG001,ANN401 diff --git a/examples/futures_ws_examples.py b/examples/futures_ws_examples.py index 544001e..cef4f4a 100644 --- a/examples/futures_ws_examples.py +++ b/examples/futures_ws_examples.py @@ -102,8 +102,8 @@ async def main() -> None: await asyncio.sleep(6) finally: # Close the sessions properly. - for _client in clients: - await _client.close() + for open_client in clients: + await open_client.close() if __name__ == "__main__": diff --git a/examples/spot_ws_examples.py b/examples/spot_ws_examples.py index fed9806..317c334 100644 --- a/examples/spot_ws_examples.py +++ b/examples/spot_ws_examples.py @@ -115,8 +115,8 @@ async def main() -> None: await asyncio.sleep(6) finally: # Stop the sessions properly. - for _client in clients: - await _client.close() + for open_client in clients: + await open_client.close() if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index ecc9b7e..0ca496d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -263,6 +263,7 @@ ignore = [ "E203", # Whitespace before ':' # false positive on list slices "PLR6301", # Method `…` could be a function or static method # false positive for no-self-use "RUF022", # `__all__` is not sorted + "RUF067", # __init__ doing more than docs and re-exports ] task-tags = ["todo", "TODO", "fixme", "FIXME"] diff --git a/tests/futures/helper.py b/tests/futures/helper.py index 0a37b41..b118f4f 100644 --- a/tests/futures/helper.py +++ b/tests/futures/helper.py @@ -7,6 +7,7 @@ from __future__ import annotations +import contextlib import logging from pathlib import Path @@ -61,17 +62,12 @@ async def on_message( self.LOG.info(message) # the log is read within the tests log: str = "" - try: - with Path(CACHE_DIR / "futures_ws.log").open( - mode="r", + with contextlib.suppress(FileNotFoundError): + log = Path(CACHE_DIR / "futures_ws.log").read_text( # noqa: ASYNC240 encoding="utf-8", - ) as logfile: - log = logfile.read() - except FileNotFoundError: - pass + ) - with Path(CACHE_DIR / "futures_ws.log").open( - mode="w", + Path(CACHE_DIR / "futures_ws.log").write_text( # noqa: ASYNC240 + f"{log}\n{message}", encoding="utf-8", - ) as logfile: - logfile.write(f"{log}\n{message}") + ) diff --git a/tests/spot/helper.py b/tests/spot/helper.py index 0991040..12590c4 100644 --- a/tests/spot/helper.py +++ b/tests/spot/helper.py @@ -12,6 +12,7 @@ from __future__ import annotations +import contextlib import json import logging from pathlib import Path @@ -99,14 +100,8 @@ def ensure_log(cls, content: dict | list) -> None: cls.LOG.info(json.dumps(content)) log: str = "" - try: - with Path(CACHE_DIR / "spot_orderbook-2.log").open( - mode="r", - encoding="utf-8", - ) as logfile: - log = logfile.read() - except FileNotFoundError: - pass + with contextlib.suppress(FileNotFoundError): + log = Path(CACHE_DIR / "spot_orderbook-2.log").read_text(encoding="utf-8") with Path(CACHE_DIR / "spot_orderbook.log").open( mode="a", diff --git a/tests/spot/test_spot_orderbook.py b/tests/spot/test_spot_orderbook.py index 5a81feb..d09d7ff 100644 --- a/tests/spot/test_spot_orderbook.py +++ b/tests/spot/test_spot_orderbook.py @@ -66,7 +66,7 @@ def test_get_first(self) -> None: Checks the ``get_first`` method. """ assert ( - float(10) + float(10) # noqa: RUF069 == SpotOrderBookClientWrapper.get_first(("10", "5")) == SpotOrderBookClientWrapper.get_first((10, 5)) ) @@ -161,9 +161,9 @@ async def execute_add_book() -> None: asyncio.run(execute_add_book()) for expected in ( - '{"method": "subscribe", "result": {"channel": "book", "depth": 10, ' + '{"method": "subscribe", "result": {"channel": "book", "depth": 10, ' # noqa: ISC004 '"snapshot": true, "symbol": "BTC/USD"}, "success": true, "time_in": ', - '{"channel": "book", "type": "snapshot", "data": ' + '{"channel": "book", "type": "snapshot", "data": ' # noqa: ISC004 '[{"symbol": "BTC/USD", "bids": ', ): assert expected in caplog.text diff --git a/tests/spot/test_spot_trade.py b/tests/spot/test_spot_trade.py index 6a68e4f..69861f9 100644 --- a/tests/spot/test_spot_trade.py +++ b/tests/spot/test_spot_trade.py @@ -312,7 +312,7 @@ def test_truncate_volume(self: Self, spot_trade: Trade) -> None: different inputs for volume. NOTE: This test may break in the future since the lot_decimals, - pair_decimals, ordermin and costmin attributes could change. + pair_decimals, ordermin, and costmin attributes could change. """ for volume, expected in ( (1, "1.00000000"), @@ -326,18 +326,6 @@ def test_truncate_volume(self: Self, spot_trade: Trade) -> None: ) sleep(3) - for volume, expected in ( - (2, "2.00000000"), - (12.158, "12.15800000"), - (13.1052093, "13.10520930"), - (4.32595342455, "4.32595342"), - ): - assert ( - spot_trade.truncate(amount=volume, amount_type="volume", pair="DOTUSD") - == expected - ) - sleep(3) - def test_truncate_fail_price_costmin(self: Self, spot_trade: Trade) -> None: """ Checks if the truncate function fails if the price is less than the costmin.