Skip to content

Commit 5cda836

Browse files
authored
Ruff pyupgrade (#465)
* Move ruff config to its own file * Add pyupgrade to ruff config
1 parent 757fedb commit 5cda836

File tree

7 files changed

+39
-13
lines changed

7 files changed

+39
-13
lines changed

django_prometheus/exports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def SetupPrometheusEndpointOnPortRange(port_range, addr=""):
9191
thread = PrometheusEndpointServer(httpd)
9292
thread.daemon = True
9393
thread.start()
94-
logger.info("Exporting Prometheus /metrics/ on port %s" % port)
94+
logger.info(f"Exporting Prometheus /metrics/ on port {port}")
9595
return port # Stop trying ports at this point
9696
logger.warning("Cannot export Prometheus /metrics/ - no available ports in supplied range")
9797
return None

django_prometheus/tests/end2end/testapp/test_middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ def M(metric_name):
1414
This is just intended to help keep the lines shorter in test
1515
cases.
1616
"""
17-
return "django_http_%s" % metric_name
17+
return f"django_http_{metric_name}"
1818

1919

2020
def T(metric_name):
2121
"""Makes a full metric name from a short metric name like M(metric_name)
2222
2323
This method adds a '_total' postfix for metrics."""
24-
return "%s_total" % M(metric_name)
24+
return f"{M(metric_name)}_total"
2525

2626

2727
class TestMiddlewareMetrics:

django_prometheus/tests/end2end/testapp/test_migrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def M(metric_name):
1212
This is just intended to help keep the lines shorter in test
1313
cases.
1414
"""
15-
return "django_migrations_%s" % metric_name
15+
return f"django_migrations_{metric_name}"
1616

1717

1818
@pytest.mark.django_db()

django_prometheus/tests/end2end/testapp/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def M(metric_name):
1010
This is just intended to help keep the lines shorter in test
1111
cases.
1212
"""
13-
return "django_model_%s" % metric_name
13+
return f"django_model_{metric_name}"
1414

1515

1616
@pytest.mark.django_db()

django_prometheus/testutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def format_labels(labels):
189189
Out:
190190
'{method="GET",port="80"}'
191191
"""
192-
return "{%s}" % ",".join([f'{k}="{v}"' for k, v in labels.items()])
192+
return "{{{}}}".format(",".join([f'{k}="{v}"' for k, v in labels.items()]))
193193

194194

195195
def format_vector(vector):

pyproject.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,3 @@ build-backend = "setuptools.build_meta"
44

55
[tool.pytest.ini_options]
66
addopts = " --ignore django_prometheus/tests/end2end"
7-
8-
[tool.ruff]
9-
line-length = 120
10-
target-version = "py39"
11-
12-
[tool.ruff.lint]
13-
select = ["B", "C4", "E", "F", "I", "T10", "YTT", "W"]

ruff.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
line-length = 120
2+
target-version = "py39"
3+
4+
[lint]
5+
select = [
6+
# https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
7+
# https://github.com/PyCQA/flake8-bugbear
8+
"B",
9+
# https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
10+
# https://github.com/adamchainz/flake8-comprehensions
11+
"C4",
12+
# https://docs.astral.sh/ruff/rules/#error-e
13+
# https://github.com/PyCQA/pycodestyle
14+
"E",
15+
# https://docs.astral.sh/ruff/rules/#pyflakes-f
16+
# https://github.com/PyCQA/pyflakes
17+
"F",
18+
# https://docs.astral.sh/ruff/rules/#isort-i
19+
# https://pycqa.github.io/isort/
20+
"I",
21+
# https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
22+
# https://github.com/jbkahn/flake8-debugger
23+
"T10",
24+
# https://docs.astral.sh/ruff/rules/#pyupgrade-up
25+
# https://github.com/asottile/pyupgrade
26+
"UP",
27+
# https://docs.astral.sh/ruff/rules/#flake8-2020-ytt
28+
# https://github.com/asottile-archive/flake8-2020
29+
"YTT",
30+
# https://docs.astral.sh/ruff/rules/#warning-w
31+
# https://github.com/PyCQA/pycodestyle
32+
"W",
33+
]

0 commit comments

Comments
 (0)