diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2b06458..5e5ad5c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: run: pipx install hatch - name: Lint and typecheck run: | - hatch run lint-check + hatch fmt --linter - name: Test run: | hatch test --all @@ -22,7 +22,7 @@ jobs: - uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: true + fail_ci_if_error: false verbose: true release: diff --git a/pyproject.toml b/pyproject.toml index f0b96a8..7e3f03f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ dynamic = ["version"] description = "Simple Python wrapper for Uptime Kuma" readme = "README.md" license = "MIT" -requires-python = ">=3.8.0" +requires-python = ">=3.12" authors = [ { name = "Manfred Dennerlein Rodelo", email = "manfred@dennerlein.name" }, { name = "Jayakorn Karikan", email = "jayakornk@gmail.com" }, @@ -40,32 +40,18 @@ include = [ "/pythonkuma", ] -[tool.ruff] -target-version = "py312" -line-length = 88 - -[tool.ruff.lint] -preview = true -ignore = ["TRY003", "N818"] - - -[tool.ruff.lint.isort] -force-sort-within-sections = true -known-first-party = ["pythonkuma"] -combine-as-imports = true -split-on-trailing-comma = false - -[tool.ruff.lint.pydocstyle] -convention = "numpy" - -[tool.ruff.format] -preview = true -quote-style = "double" -indent-style = "space" - -[tool.ruff.lint.mccabe] -max-complexity = 25 - -[tool.ruff.lint.flake8-tidy-imports] -ban-relative-imports = "parents" - +[tool.hatch.envs.hatch-static-analysis] +dependencies = ["ruff==0.11.13"] +config-path = "ruff.toml" + +[tool.pytest.ini_options] +addopts = "--cov=pythonkuma/ --cov-report=term-missing" +asyncio_mode = "auto" +asyncio_default_fixture_loop_scope="module" +testpaths = ["tests"] +pythonpath = ["pythonkuma"] + +[tool.hatch.envs.hatch-test] +extra-dependencies = [ + "pytest-cov" +] \ No newline at end of file diff --git a/pythonkuma/__init__.py b/pythonkuma/__init__.py index 326edbf..510e2d0 100644 --- a/pythonkuma/__init__.py +++ b/pythonkuma/__init__.py @@ -1,4 +1,5 @@ """Python API wrapper for Uptime Kuma.""" + from .exceptions import ( UptimeKumaAuthenticationException, UptimeKumaConnectionException, diff --git a/pythonkuma/const.py b/pythonkuma/const.py index b3fe4ba..1bd8acd 100644 --- a/pythonkuma/const.py +++ b/pythonkuma/const.py @@ -1,4 +1,5 @@ """Uptime Kuma constants.""" + from logging import Logger, getLogger LOGGER: Logger = getLogger(__package__) diff --git a/pythonkuma/decorator.py b/pythonkuma/decorator.py index c8dc18d..3c4a59e 100644 --- a/pythonkuma/decorator.py +++ b/pythonkuma/decorator.py @@ -1,4 +1,5 @@ """Decorator for Uptime Kuma""" + from __future__ import annotations from typing import TYPE_CHECKING @@ -44,9 +45,7 @@ async def wrapper(*args, **kwargs): ) from exception except TimeoutError: - raise exceptions.UptimeKumaConnectionException( - f"Request timeout for '{url}'" - ) from None + raise exceptions.UptimeKumaConnectionException(f"Request timeout for '{url}'") from None except exceptions.UptimeKumaConnectionException as exception: raise exceptions.UptimeKumaConnectionException(exception) from exception diff --git a/pythonkuma/models.py b/pythonkuma/models.py index 75673a9..b11cac5 100644 --- a/pythonkuma/models.py +++ b/pythonkuma/models.py @@ -1,4 +1,5 @@ """Uptime Kuma models""" + from __future__ import annotations from dataclasses import dataclass @@ -87,11 +88,7 @@ def from_prometheus(data: dict[str, Any]) -> UptimeKumaApiResponse: for sample in family.samples: if sample.name.startswith("monitor"): existed = next( - ( - i - for i, x in enumerate(monitors) - if x["monitor_name"] == sample.labels["monitor_name"] - ), + (i for i, x in enumerate(monitors) if x["monitor_name"] == sample.labels["monitor_name"]), None, ) if existed is None: @@ -99,8 +96,6 @@ def from_prometheus(data: dict[str, Any]) -> UptimeKumaApiResponse: monitors.append(temp) else: monitors[existed][sample.name] = sample.value - obj["data"] = [ - UptimeKumaMonitor.from_dict(monitor) for monitor in monitors - ] + obj["data"] = [UptimeKumaMonitor.from_dict(monitor) for monitor in monitors] return UptimeKumaApiResponse(**obj) diff --git a/pythonkuma/uptimekuma.py b/pythonkuma/uptimekuma.py index 62f122c..3d60407 100644 --- a/pythonkuma/uptimekuma.py +++ b/pythonkuma/uptimekuma.py @@ -1,4 +1,5 @@ """Uptime Kuma client.""" + from aiohttp import ClientSession from .decorator import api_request diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..28fd02e --- /dev/null +++ b/ruff.toml @@ -0,0 +1,38 @@ +line-length = 120 + +[format] +docstring-code-format = true +docstring-code-line-length = 80 +quote-style = "double" +indent-style = "space" + +[lint] + +[lint.per-file-ignores] +"**/scripts/*" = [ + "INP001", + "T201", +] +"**/tests/**/*" = [ + "PLC1901", + "PLR2004", + "PLR6301", + "S", + "TID252", +] + +[lint.flake8-tidy-imports] +ban-relative-imports = "parents" + +[lint.isort] +known-first-party = ["pyuptimekuma"] +force-sort-within-sections = true +combine-as-imports = true +split-on-trailing-comma = false + +[lint.flake8-pytest-style] +fixture-parentheses = false +mark-parentheses = false + +[lint.pydocstyle] +convention = "numpy" \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_dummy.py b/tests/test_dummy.py new file mode 100644 index 0000000..62e45ca --- /dev/null +++ b/tests/test_dummy.py @@ -0,0 +1,2 @@ +def test_dummy(): + pass \ No newline at end of file