Skip to content

Ruff pyupgrade #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django_prometheus/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def SetupPrometheusEndpointOnPortRange(port_range, addr=""):
thread = PrometheusEndpointServer(httpd)
thread.daemon = True
thread.start()
logger.info("Exporting Prometheus /metrics/ on port %s" % port)
logger.info(f"Exporting Prometheus /metrics/ on port {port}")
return port # Stop trying ports at this point
logger.warning("Cannot export Prometheus /metrics/ - no available ports in supplied range")
return None
Expand Down
4 changes: 2 additions & 2 deletions django_prometheus/tests/end2end/testapp/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def M(metric_name):
This is just intended to help keep the lines shorter in test
cases.
"""
return "django_http_%s" % metric_name
return f"django_http_{metric_name}"


def T(metric_name):
"""Makes a full metric name from a short metric name like M(metric_name)

This method adds a '_total' postfix for metrics."""
return "%s_total" % M(metric_name)
return f"{M(metric_name)}_total"


class TestMiddlewareMetrics:
Expand Down
2 changes: 1 addition & 1 deletion django_prometheus/tests/end2end/testapp/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def M(metric_name):
This is just intended to help keep the lines shorter in test
cases.
"""
return "django_migrations_%s" % metric_name
return f"django_migrations_{metric_name}"


@pytest.mark.django_db()
Expand Down
2 changes: 1 addition & 1 deletion django_prometheus/tests/end2end/testapp/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def M(metric_name):
This is just intended to help keep the lines shorter in test
cases.
"""
return "django_model_%s" % metric_name
return f"django_model_{metric_name}"


@pytest.mark.django_db()
Expand Down
2 changes: 1 addition & 1 deletion django_prometheus/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def format_labels(labels):
Out:
'{method="GET",port="80"}'
"""
return "{%s}" % ",".join([f'{k}="{v}"' for k, v in labels.items()])
return "{{{}}}".format(",".join([f'{k}="{v}"' for k, v in labels.items()]))


def format_vector(vector):
Expand Down
7 changes: 0 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,3 @@ build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
addopts = " --ignore django_prometheus/tests/end2end"

[tool.ruff]
line-length = 120
target-version = "py39"

[tool.ruff.lint]
select = ["B", "C4", "E", "F", "I", "T10", "YTT", "W"]
33 changes: 33 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
line-length = 120
target-version = "py39"

[lint]
select = [
# https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
# https://github.com/PyCQA/flake8-bugbear
"B",
# https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
# https://github.com/adamchainz/flake8-comprehensions
"C4",
# https://docs.astral.sh/ruff/rules/#error-e
# https://github.com/PyCQA/pycodestyle
"E",
# https://docs.astral.sh/ruff/rules/#pyflakes-f
# https://github.com/PyCQA/pyflakes
"F",
# https://docs.astral.sh/ruff/rules/#isort-i
# https://pycqa.github.io/isort/
"I",
# https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
# https://github.com/jbkahn/flake8-debugger
"T10",
# https://docs.astral.sh/ruff/rules/#pyupgrade-up
# https://github.com/asottile/pyupgrade
"UP",
# https://docs.astral.sh/ruff/rules/#flake8-2020-ytt
# https://github.com/asottile-archive/flake8-2020
"YTT",
# https://docs.astral.sh/ruff/rules/#warning-w
# https://github.com/PyCQA/pycodestyle
"W",
]