Skip to content

Commit

Permalink
switch back to isort+black+flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
albertodonato committed Oct 20, 2024
1 parent 6661e01 commit cd96f39
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 57 deletions.
57 changes: 32 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ keywords = [
"prometheus",
"sql",
]
license = {file = "LICENSE.txt"}
license = { file = "LICENSE.txt" }
maintainers = [
{name = "Alberto Donato", email = "[email protected]"},
{ name = "Alberto Donato", email = "[email protected]" },
]
authors = [
{name = "Alberto Donato", email = "[email protected]"},
{ name = "Alberto Donato", email = "[email protected]" },
]
requires-python = ">=3.10"
classifiers = [
Expand All @@ -32,6 +32,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Database",
"Topic :: System :: Monitoring",
"Topic :: Utilities",
Expand All @@ -47,42 +48,48 @@ dependencies = [
"prometheus-aioexporter>=2",
"prometheus-client",
"python-dateutil",
"PyYAML",
"SQLAlchemy<1.4",
"sqlalchemy_aio>=0.17",
"pyyaml",
"sqlalchemy<1.4",
"sqlalchemy-aio>=0.17",
"toolrack>=4",
]
[project.optional-dependencies]
testing = [
"pytest<8", # XXX https://github.com/pytest-dev/pytest-asyncio/issues/737
optional-dependencies.testing = [
"pytest",
"pytest-asyncio",
"pytest-mock",
]
[project.urls]
changelog = "https://github.com/albertodonato/query-exporter/blob/main/CHANGES.rst"
homepage = "https://github.com/albertodonato/query-exporter"
repository = "https://github.com/albertodonato/query-exporter"
[project.scripts]
query-exporter = "query_exporter.main:script"
urls.changelog = "https://github.com/albertodonato/query-exporter/blob/main/CHANGES.rst"
urls.homepage = "https://github.com/albertodonato/query-exporter"
urls.repository = "https://github.com/albertodonato/query-exporter"
scripts.query-exporter = "query_exporter.main:script"

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

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

[tool.setuptools.package-data]
query_exporter = ["py.typed", "schemas/*"]
query_exporter = [ "py.typed", "schemas/*" ]

[tool.ruff]
[tool.black]
line-length = 79

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

[tool.pytest.ini_options]
asyncio_mode = "auto"
Expand All @@ -93,7 +100,7 @@ show_missing = true
skip_covered = true

[tool.coverage.run]
source = ["query_exporter"]
source = [ "query_exporter" ]
omit = [
"query_exporter/main.py",
]
Expand Down
4 changes: 2 additions & 2 deletions query_exporter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from pathlib import Path
import re
from typing import (
IO,
Any,
IO,
)
from urllib.parse import (
quote_plus,
Expand All @@ -27,13 +27,13 @@
import yaml

from .db import (
create_db_engine,
DATABASE_LABEL,
DataBaseError,
InvalidQueryParameters,
InvalidQuerySchedule,
Query,
QueryMetric,
create_db_engine,
)

# metric for counting database errors
Expand Down
7 changes: 5 additions & 2 deletions query_exporter/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
from itertools import chain
import logging
import sys
from time import perf_counter, time
from time import (
perf_counter,
time,
)
from traceback import format_tb
from typing import (
Any,
NamedTuple,
cast,
NamedTuple,
)

from croniter import croniter
Expand Down
9 changes: 6 additions & 3 deletions query_exporter/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

from croniter import croniter
from dateutil.tz import gettz
from prometheus_aioexporter import MetricConfig, MetricsRegistry
from prometheus_aioexporter import (
MetricConfig,
MetricsRegistry,
)
from prometheus_client import Counter
from prometheus_client.metrics import MetricWrapperBase
from toolrack.aio import (
Expand All @@ -23,15 +26,15 @@
)

from .config import (
Config,
DB_ERRORS_METRIC_NAME,
QUERIES_METRIC_NAME,
QUERY_LATENCY_METRIC_NAME,
QUERY_TIMESTAMP_METRIC_NAME,
Config,
)
from .db import (
DATABASE_LABEL,
DataBase,
DATABASE_LABEL,
DataBaseConnectError,
DataBaseError,
Query,
Expand Down
8 changes: 4 additions & 4 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import yaml

from query_exporter.config import (
DB_ERRORS_METRIC_NAME,
GLOBAL_METRICS,
QUERIES_METRIC_NAME,
ConfigError,
_get_parameters_sets,
_resolve_dsn,
ConfigError,
DB_ERRORS_METRIC_NAME,
GLOBAL_METRICS,
load_config,
QUERIES_METRIC_NAME,
)
from query_exporter.db import QueryMetric

Expand Down
37 changes: 21 additions & 16 deletions tests/db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from query_exporter.config import DataBaseConfig
from query_exporter.db import (
create_db_engine,
DataBase,
DataBaseConnectError,
DataBaseError,
Expand All @@ -22,7 +23,6 @@
QueryMetric,
QueryResults,
QueryTimeoutExpired,
create_db_engine,
)


Expand All @@ -44,9 +44,10 @@ def test_instantiate_missing_engine_module(self, caplog):
@pytest.mark.parametrize("dsn", ["foo-bar", "unknown:///db"])
def test_instantiate_invalid_dsn(self, caplog, dsn):
"""An error is raised if a the provided DSN is invalid."""
with caplog.at_level(logging.ERROR), pytest.raises(
DataBaseError
) as error:
with (
caplog.at_level(logging.ERROR),
pytest.raises(DataBaseError) as error,
):
create_db_engine(dsn)
assert str(error.value) == f'Invalid database DSN: "{dsn}"'

Expand Down Expand Up @@ -412,9 +413,10 @@ async def test_connect_sql_fail(self, caplog):
connect_sql=["WRONG"],
)
db = DataBase(config)
with caplog.at_level(logging.DEBUG), pytest.raises(
DataBaseQueryError
) as error:
with (
caplog.at_level(logging.DEBUG),
pytest.raises(DataBaseQueryError) as error,
):
await db.connect()
assert not db.connected
assert 'failed executing query "WRONG"' in str(error.value)
Expand Down Expand Up @@ -567,9 +569,10 @@ async def test_execute_query_invalid_count(self, caplog, db):
"SELECT 1 AS metric, 2 AS other",
)
await db.connect()
with caplog.at_level(logging.ERROR), pytest.raises(
DataBaseQueryError
) as error:
with (
caplog.at_level(logging.ERROR),
pytest.raises(DataBaseQueryError) as error,
):
await db.execute(query)
assert (
str(error.value)
Expand Down Expand Up @@ -630,9 +633,10 @@ async def test_execute_query_traceback_debug(self, caplog, mocker, db):
"boom!"
)
await db.connect()
with caplog.at_level(logging.DEBUG), pytest.raises(
DataBaseQueryError
) as error:
with (
caplog.at_level(logging.DEBUG),
pytest.raises(DataBaseQueryError) as error,
):
await db.execute(query)
assert str(error.value) == "boom!"
assert not error.value.fatal
Expand All @@ -659,9 +663,10 @@ async def execute(sql, parameters):

db._conn.execute = execute

with caplog.at_level(logging.WARNING), pytest.raises(
QueryTimeoutExpired
) as error:
with (
caplog.at_level(logging.WARNING),
pytest.raises(QueryTimeoutExpired) as error,
):
await db.execute(query)
assert (
str(error.value)
Expand Down
16 changes: 11 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,27 @@ commands =

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

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

[testenv:run]
Expand Down

0 comments on commit cd96f39

Please sign in to comment.