Skip to content

Commit

Permalink
require Python3.11, switch to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
albertodonato committed Nov 3, 2024
1 parent 3dd4f29 commit 077a319
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 68 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,57 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- name: Install dependencies
run: |
pip install --upgrade pip tox
- name: Lint
run: |
tox -e lint
tox run -e lint
check:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.11"
- "3.12"
- "3.13"
steps:
- name: Repository checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install --upgrade pip tox
- name: Check
run: |
tox -e check
tox run -e check
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.11"
- "3.12"
- "3.13"
steps:
- name: Repository checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
Expand Down
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
*.pyc
*.pyo
/build
/*.egg-info
/.coverage
/.mypy_cache
/.tox
.eggs
.pybuild
.cache
/build
/html
15 changes: 15 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.11"

sphinx:
configuration: docs/conf.py

python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
2 changes: 1 addition & 1 deletion prometheus_aioexporter/_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
Counter,
Enum,
Gauge,
generate_latest,
Histogram,
Info,
Summary,
generate_latest,
)
from prometheus_client.metrics import MetricWrapperBase
from prometheus_client.registry import Collector
Expand Down
4 changes: 2 additions & 2 deletions prometheus_aioexporter/_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ._web import PrometheusExporter


class PrometheusExporterScript(Script): # type: ignore
class PrometheusExporterScript(Script):
"""Expose metrics to Prometheus."""

#: Name of the script, can be set by subsclasses.
Expand Down Expand Up @@ -169,7 +169,7 @@ def _setup_logging(self, log_level: str) -> None:
self.name,
)
for name in names:
setup_logger(name=name, stream=sys.stderr, level=level)
setup_logger(name=name, stream=sys.stderr, level=level) # type: ignore

def _configure_registry(self, include_process_stats: bool = False) -> None:
"""Configure the MetricRegistry."""
Expand Down
56 changes: 22 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ keywords = [
"library",
"prometheus",
]
license = {file = "LICENSE.txt"}
license = { file = "LICENSE.txt" }
maintainers = [
{name = "Alberto Donato", email = "alberto.donato@gmail.com"},
{ name = "Alberto Donato", email = "alberto.donato@gmail.com" },
]
authors = [
{name = "Alberto Donato", email = "alberto.donato@gmail.com"},
{ name = "Alberto Donato", email = "alberto.donato@gmail.com" },
]
requires-python = ">=3.10"
requires-python = ">=3.11"
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
Expand All @@ -42,60 +42,48 @@ dependencies = [
"prometheus-client>=0.4",
"toolrack>=2.1",
]
[project.optional-dependencies]
testing = [
optional-dependencies.testing = [
"pytest",
"pytest-aiohttp",
"pytest-asyncio",
"pytest-mock",
"trustme",
]
[project.urls]
changelog = "https://github.com/albertodonato/prometheus-aioexporter/blob/main/CHANGES.rst"
homepage = "https://github.com/albertodonato/prometheus-aioexporter"
repository = "https://github.com/albertodonato/prometheus-aioexporter"
[project.scripts]
prometheus-aioexporter-sample = "prometheus_aioexporter.sample:script"
urls.changelog = "https://github.com/albertodonato/prometheus-aioexporter/blob/main/CHANGES.rst"
urls.homepage = "https://github.com/albertodonato/prometheus-aioexporter"
urls.repository = "https://github.com/albertodonato/prometheus-aioexporter"
scripts.prometheus-aioexporter-sample = "prometheus_aioexporter.sample:script"

[tool.setuptools.dynamic]
version = {attr = "prometheus_aioexporter.__version__"}
version = { attr = "prometheus_aioexporter.__version__" }

[tool.setuptools.packages.find]
include = ["prometheus_aioexporter*"]
include = [ "prometheus_aioexporter*" ]

[tool.black]
line-length = 79
[tool.setuptools.package-data]
prometheus_aioexporter = [ "py.typed" ]

[tool.isort]
combine_as_imports = true
force_grid_wrap = 2
force_sort_within_sections = true
from_first = false
include_trailing_comma = true
multi_line_output = 3
order_by_type = false
profile = "black"
use_parentheses = true
[tool.ruff]
line-length = 79

[tool.flake8]
ignore = ["E203", "E501", "W503"]
max-line-length = 80
select = ["C", "E", "F", "W", "B", "B950"]
lint.select = [ "I", "RUF", "UP" ]
lint.isort.combine-as-imports = true
lint.isort.force-sort-within-sections = true

[tool.pytest.ini_options]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"

[tool.coverage.report]
fail_under = 100.0
show_missing = true
skip_covered = true

[tool.coverage.run]
source = ["prometheus_aioexporter"]
omit = ["prometheus_aioexporter/sample.py"]
source = [ "prometheus_aioexporter" ]
omit = [ "prometheus_aioexporter/sample.py" ]

[tool.mypy]
ignore_missing_imports = true
install_types = true
non_interactive = true
strict = true
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Iterator
import ssl
from typing import Iterator

import pytest
from trustme import (
Expand Down
2 changes: 1 addition & 1 deletion tests/metric_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable
from typing import (
Any,
Callable,
cast,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/script_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from argparse import ArgumentParser
from collections.abc import Iterator
from io import StringIO
import logging
from ssl import SSLContext
from typing import Iterator
from unittest import mock

import pytest
Expand Down
18 changes: 10 additions & 8 deletions tests/web_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from ssl import SSLContext
from typing import (
Any,
from collections.abc import (
Awaitable,
Callable,
cast,
Coroutine,
Iterator,
)
from ssl import SSLContext
from typing import (
Any,
cast,
)
from unittest import mock

from aiohttp.test_utils import (
Expand Down Expand Up @@ -84,10 +86,10 @@ def test_run(
ssl_context=exporter.ssl_context,
)

@pytest.mark.parametrize("exporter", [ssl_context, None], indirect=True)
@pytest.mark.parametrize("exporter", [ssl_context, False], indirect=True)
async def test_homepage(
self,
ssl_context_server: SSLContext,
ssl_context_server: SSLContext | bool,
create_server_client: Callable[
[PrometheusExporter], Coroutine[Any, Any, TestServer]
],
Expand All @@ -96,7 +98,7 @@ async def test_homepage(
) -> None:
server = await create_server_client(exporter)
client = await aiohttp_client(server)
ssl_client_context = None
ssl_client_context: SSLContext | bool = False
if exporter.ssl_context is not None:
ssl_client_context = ssl_context_server
request = await client.request("GET", "/", ssl=ssl_client_context)
Expand Down Expand Up @@ -177,7 +179,7 @@ async def test_metrics_update_handler(
args = []

async def update_handler(
metrics: dict[str, MetricWrapperBase]
metrics: dict[str, MetricWrapperBase],
) -> None:
args.append(metrics)

Expand Down
23 changes: 12 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,30 @@ deps =
commands =
pytest --cov prometheus_aioexporter/ {posargs}

[testenv:docs]
deps =
-r docs/requirements.txt
.
commands =
sphinx-build -b html docs html {posargs}

[testenv:format]
deps =
black
isort
pyproject-fmt
ruff
tox-ini-fmt
commands =
isort {[base]lint_files}
black -q {[base]lint_files}
ruff format {[base]lint_files}
ruff check --fix {[base]lint_files}
- pyproject-fmt pyproject.toml
- tox-ini-fmt tox.ini

[testenv:lint]
deps =
black
flake8
flake8-pyproject
isort
pyproject-fmt
ruff
commands =
isort --check-only --diff {[base]lint_files}
black --check {[base]lint_files}
flake8 {[base]lint_files}
ruff check {[base]lint_files}
pyproject-fmt --check pyproject.toml

[base]
Expand Down

0 comments on commit 077a319

Please sign in to comment.