Skip to content
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
3 changes: 3 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
enable-cache: true
- uses: j178/prek-action@4e14d07f9231acabce116ccfca13b13dd9755ece # v3.0.0
with:
install-only: true
- run: uv run ./bin/lint
- run: uv run ./bin/test
- name: Upload coverage reports to Codecov
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.22
rev: v0.16.1
hooks:
- id: ruff
- id: ruff-check
args: [--fix]
- id: ruff-format
- repo: https://github.com/python-jsonschema/check-jsonschema
Expand Down
2 changes: 1 addition & 1 deletion bin/lint
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
set -eu

pre-commit run -a
prek run --all-files --show-diff-on-failure
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dpn = "docker_python_nodejs:dpn"
[dependency-groups]
dev = [
"pytest",
"pre-commit",
"ruff",
"pytest-cov",
"mypy",
Expand All @@ -45,7 +44,8 @@ ignore = [
"D", # FIXME: docs
"TD", # Allow TODOs
"FBT001", # Allow boolean function args
"FIX001" # Allow fixme's
"FIX001", # Allow fixme's
"CPY001", # No copyright headers
]

[tool.ruff.lint.per-file-ignores]
Expand Down
4 changes: 2 additions & 2 deletions src/docker_python_nodejs/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _wanted_tag(tag: DockerTagDict, ver: str, distro: str) -> bool:

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


def scrape_supported_python_versions() -> list[SupportedVersion]:
Expand Down Expand Up @@ -195,7 +195,7 @@ def decide_nodejs_versions(distros: list[str], supported_versions: list[Supporte
if rel["version"][1:].startswith(ver) and _has_arch_files(rel["files"], distro)
]
latest_patch_version = (
sorted(matching_releases, key=lambda x: Version.parse(x["version"][1:]), reverse=True)[0]["version"][1:]
max(matching_releases, key=lambda x: Version.parse(x["version"][1:]))["version"][1:]
if matching_releases
else None
)
Expand Down
65 changes: 65 additions & 0 deletions tests/test_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from typing import TYPE_CHECKING

from docker_python_nodejs.versions import _latest_patch

if TYPE_CHECKING:
from docker_python_nodejs.docker_hub import DockerTagDict


def _docker_tag(name: str) -> DockerTagDict:
return {
"name": name,
"images": [
{
"architecture": "amd64",
"features": "",
"variant": None,
"digest": "sha256:abc123",
"os": "linux",
"os_features": "",
"os_version": None,
"size": 123456,
"status": "active",
"last_pulled": "2024-01-01T00:00:00Z",
"last_pushed": "2024-01-01T00:00:00Z",
},
{
"architecture": "arm64",
"features": "",
"variant": None,
"digest": "sha256:abc123",
"os": "linux",
"os_features": "",
"os_version": None,
"size": 123456,
"status": "active",
"last_pulled": "2024-01-01T00:00:00Z",
"last_pushed": "2024-01-01T00:00:00Z",
},
],
"creator": 123456,
"id": 1,
"last_updated": "2024-01-01T00:00:00Z",
"last_updater": 123456,
"last_updater_username": "user",
"repository": 123456,
"full_size": 123456,
"v2": True,
"tag_status": "active",
"tag_last_pulled": "2024-01-01T00:00:00Z",
"tag_last_pushed": "2024-01-01T00:00:00Z",
"media_type": "application/vnd.docker.distribution.manifest.v2+json",
"content_type": "application/vnd.docker.distribution.manifest.v2+json",
"digest": "sha256:abc123",
}


def test_latest_patch() -> None:
tags: list[DockerTagDict] = [
_docker_tag("3.19.2-trixie"),
_docker_tag("3.19.3-trixie"),
_docker_tag("3.19.0-trixie"),
]
ver = "3.19"
distro = "trixie"
assert _latest_patch(tags, ver, distro) == "3.19.3-trixie"
Loading