Skip to content

Commit af02bf0

Browse files
committed
fix: Adapt to ruff 0.16 changes
Also switch to prek (from pre-commit) to run hooks
1 parent f97b5cb commit af02bf0

7 files changed

Lines changed: 311 additions & 217 deletions

File tree

‎.github/workflows/tests.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jobs:
1212
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
1313
with:
1414
enable-cache: true
15+
- uses: j178/prek-action@4e14d07f9231acabce116ccfca13b13dd9755ece # v3.0.0
16+
with:
17+
install-only: true
1518
- run: uv run ./bin/lint
1619
- run: uv run ./bin/test
1720
- name: Upload coverage reports to Codecov

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
33
rev: v0.16.1
44
hooks:
5-
- id: ruff
5+
- id: ruff-check
66
args: [--fix]
77
- id: ruff-format
88
- repo: https://github.com/python-jsonschema/check-jsonschema

‎bin/lint‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22
set -eu
33

4-
pre-commit run -a
4+
prek run --all-files --show-diff-on-failure

‎pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ dpn = "docker_python_nodejs:dpn"
2121
[dependency-groups]
2222
dev = [
2323
"pytest",
24-
"pre-commit",
2524
"ruff",
2625
"pytest-cov",
2726
"mypy",
@@ -45,7 +44,8 @@ ignore = [
4544
"D", # FIXME: docs
4645
"TD", # Allow TODOs
4746
"FBT001", # Allow boolean function args
48-
"FIX001" # Allow fixme's
47+
"FIX001", # Allow fixme's
48+
"CPY001", # No copyright headers
4949
]
5050

5151
[tool.ruff.lint.per-file-ignores]

‎src/docker_python_nodejs/versions.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _wanted_tag(tag: DockerTagDict, ver: str, distro: str) -> bool:
102102

103103
def _latest_patch(tags: list[DockerTagDict], ver: str, distro: str) -> str | None:
104104
tags = [tag for tag in tags if _wanted_tag(tag, ver, distro)]
105-
return sorted(tags, key=lambda x: Version.parse(x["name"]), reverse=True)[0]["name"] if tags else None
105+
return max(tags, key=lambda x: Version.parse(x["name"]))["name"] if tags else None
106106

107107

108108
def scrape_supported_python_versions() -> list[SupportedVersion]:
@@ -195,7 +195,7 @@ def decide_nodejs_versions(distros: list[str], supported_versions: list[Supporte
195195
if rel["version"][1:].startswith(ver) and _has_arch_files(rel["files"], distro)
196196
]
197197
latest_patch_version = (
198-
sorted(matching_releases, key=lambda x: Version.parse(x["version"][1:]), reverse=True)[0]["version"][1:]
198+
max(matching_releases, key=lambda x: Version.parse(x["version"][1:]))["version"][1:]
199199
if matching_releases
200200
else None
201201
)

‎tests/test_versions.py‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from typing import TYPE_CHECKING
2+
3+
from docker_python_nodejs.versions import _latest_patch
4+
5+
if TYPE_CHECKING:
6+
from docker_python_nodejs.docker_hub import DockerTagDict
7+
8+
9+
def _docker_tag(name: str) -> DockerTagDict:
10+
return {
11+
"name": name,
12+
"images": [
13+
{
14+
"architecture": "amd64",
15+
"features": "",
16+
"variant": None,
17+
"digest": "sha256:abc123",
18+
"os": "linux",
19+
"os_features": "",
20+
"os_version": None,
21+
"size": 123456,
22+
"status": "active",
23+
"last_pulled": "2024-01-01T00:00:00Z",
24+
"last_pushed": "2024-01-01T00:00:00Z",
25+
},
26+
{
27+
"architecture": "arm64",
28+
"features": "",
29+
"variant": None,
30+
"digest": "sha256:abc123",
31+
"os": "linux",
32+
"os_features": "",
33+
"os_version": None,
34+
"size": 123456,
35+
"status": "active",
36+
"last_pulled": "2024-01-01T00:00:00Z",
37+
"last_pushed": "2024-01-01T00:00:00Z",
38+
},
39+
],
40+
"creator": 123456,
41+
"id": 1,
42+
"last_updated": "2024-01-01T00:00:00Z",
43+
"last_updater": 123456,
44+
"last_updater_username": "user",
45+
"repository": 123456,
46+
"full_size": 123456,
47+
"v2": True,
48+
"tag_status": "active",
49+
"tag_last_pulled": "2024-01-01T00:00:00Z",
50+
"tag_last_pushed": "2024-01-01T00:00:00Z",
51+
"media_type": "application/vnd.docker.distribution.manifest.v2+json",
52+
"content_type": "application/vnd.docker.distribution.manifest.v2+json",
53+
"digest": "sha256:abc123",
54+
}
55+
56+
57+
def test_latest_patch() -> None:
58+
tags: list[DockerTagDict] = [
59+
_docker_tag("3.19.2-trixie"),
60+
_docker_tag("3.19.3-trixie"),
61+
_docker_tag("3.19.0-trixie"),
62+
]
63+
ver = "3.19"
64+
distro = "trixie"
65+
assert _latest_patch(tags, ver, distro) == "3.19.3-trixie"

0 commit comments

Comments
 (0)