Skip to content

Commit 91b4be0

Browse files
committed
Merge branch 'main' into feat/port-difference-formatter
2 parents 6cce0a9 + 95a3985 commit 91b4be0

40 files changed

+1002
-240
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
rev: 'v1.18.2'
2121
hooks:
2222
- id: mypy
23-
args: [--strict, --ignore-missing-imports, --check-untyped-defs]
23+
args: [--strict, --ignore-missing-imports, --check-untyped-defs, --allow-untyped-decorators]
2424
additional_dependencies:
2525
- types-click
2626
- types-PyYAML

poetry.lock

Lines changed: 634 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ pytest = "^9.0.2"
3030
pytest-cov = "^7.0.0"
3131
isort = "^7.0.0"
3232
requests-mock = "^1.12.1"
33+
mypy = "1.18.2"
34+
types-click = "^7.1.8"
35+
types-pyyaml = "^6.0.12.20250915"
36+
types-requests = "^2.32.4.20260107"
37+
boto3-stubs = { extras = ["s3"], version = "^1.42.25" }
3338

3439
[tool.poetry.group.docs.dependencies]
3540
sphinx-rtd-theme = "^3.0.2"
Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Self
2+
3+
14
class UnsupportedDistroVersion(Exception):
25
pass
36

@@ -6,63 +9,65 @@ class NotAPatchRelease(Exception):
69
pass
710

811

9-
def DistroVersion(maybe_distro_version):
10-
version_components = maybe_distro_version.split(".")
11-
if len(version_components) > 3 or len(version_components) < 2:
12-
raise UnsupportedDistroVersion(
13-
f"Unexpected version number format {maybe_distro_version}"
14-
)
15-
16-
if not all(map(lambda x: x.isdigit(), version_components)):
17-
raise UnsupportedDistroVersion(
18-
f"Unexpected version number format {maybe_distro_version}"
19-
)
20-
21-
if len(version_components) == 2:
22-
return LegacyDistroVersion(*(int(c) for c in version_components))
23-
elif len(version_components) == 3:
24-
return SemverDistroVersion(*(int(c) for c in version_components))
25-
else:
26-
raise UnsupportedDistroVersion(
27-
f"Unexpected number of version components: {maybe_distro_version}"
28-
)
29-
30-
3112
class BaseDistroVersion:
32-
major = None
33-
minor = None
34-
patch = None
13+
major: int = 0
14+
minor: int = 0
15+
patch: int = 0
3516

36-
def is_patch_release(self):
17+
def is_patch_release(self) -> int:
3718
return self.patch and self.patch > 0
3819

3920

4021
class LegacyDistroVersion(BaseDistroVersion):
41-
def __init__(self, major, patch):
22+
def __init__(self: Self, major: int, patch: int) -> None:
4223
self.major = major
4324
self.patch = patch
4425

45-
def __str__(self):
26+
def __str__(self) -> str:
4627
return f"{self.major}.{self.patch}"
4728

48-
def previous_patch_release(self):
29+
def previous_patch_release(self) -> "LegacyDistroVersion":
4930
if not self.is_patch_release():
5031
raise NotAPatchRelease(f"{self} is not a patch release")
5132

5233
return LegacyDistroVersion(self.major, self.patch - 1)
5334

5435

5536
class SemverDistroVersion(BaseDistroVersion):
56-
def __init__(self, major, minor, patch):
37+
def __init__(self, major: int, minor: int, patch: int) -> None:
5738
self.major = major
5839
self.minor = minor
5940
self.patch = patch
6041

61-
def __str__(self):
42+
def __str__(self) -> str:
6243
return f"{self.major}.{self.minor}.{self.patch}"
6344

64-
def previous_patch_release(self):
45+
def previous_patch_release(self) -> "SemverDistroVersion":
6546
if not self.is_patch_release():
6647
raise NotAPatchRelease(f"{self} is not a patch release")
6748

6849
return SemverDistroVersion(self.major, self.minor, self.patch - 1)
50+
51+
52+
def DistroVersion(
53+
maybe_distro_version: str,
54+
) -> LegacyDistroVersion | SemverDistroVersion:
55+
version_components = maybe_distro_version.split(".")
56+
if len(version_components) > 3 or len(version_components) < 2:
57+
raise UnsupportedDistroVersion(
58+
f"Unexpected version number format {maybe_distro_version}"
59+
)
60+
61+
if not all(map(lambda x: x.isdigit(), version_components)):
62+
raise UnsupportedDistroVersion(
63+
f"Unexpected version number format {maybe_distro_version}"
64+
)
65+
66+
if len(version_components) == 2:
67+
return LegacyDistroVersion(*(int(c) for c in version_components))
68+
elif len(version_components) == 3:
69+
return SemverDistroVersion(*(int(c) for c in version_components))
70+
else:
71+
raise UnsupportedDistroVersion(
72+
f"Unexpected number of version components: {maybe_distro_version}"
73+
)

src/gardenlinux/git/repository.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def root(self) -> Path:
7474
:since: 0.10.0
7575
"""
7676

77-
root_dir = self.workdir
77+
root_dir: Path = Path(self.workdir)
7878

7979
if self.is_bare:
80-
root_dir = self.path
80+
root_dir = Path(self.path)
8181

82-
usual_git_dir = Path(root_dir, ".git")
82+
usual_git_dir = root_dir / ".git"
8383

8484
# Possible submodule Git repository. Validate repository containing `.git` directory.
8585
if self.path != str(usual_git_dir):

src/gardenlinux/github/release/__init__.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
import os
34
import sys
45

@@ -7,10 +8,12 @@
78
from gardenlinux.constants import RELEASE_ID_FILE, REQUESTS_TIMEOUTS
89
from gardenlinux.logger import LoggerSetup
910

10-
LOGGER = LoggerSetup.get_logger("gardenlinux.github.release", "INFO")
11+
LOGGER = LoggerSetup.get_logger("gardenlinux.github.release", logging.INFO)
1112

1213

13-
def create_github_release(owner, repo, tag, commitish, latest, body):
14+
def create_github_release(
15+
owner: str, repo: str, tag: str, commitish: str, latest: bool, body: str
16+
) -> int | None:
1417
token = os.environ.get("GITHUB_TOKEN")
1518
if not token:
1619
raise ValueError("GITHUB_TOKEN environment variable not set")
@@ -40,26 +43,32 @@ def create_github_release(owner, repo, tag, commitish, latest, body):
4043
if response.status_code == 201:
4144
LOGGER.info("Release created successfully")
4245
response_json = response.json()
43-
return response_json.get("id")
46+
return int(response_json.get("id")) # Will raise KeyError if missing
4447
else:
4548
LOGGER.error("Failed to create release")
4649
LOGGER.debug(response.json())
4750
response.raise_for_status()
4851

52+
return None # Simply to make mypy happy. should not be reached.
4953

50-
def write_to_release_id_file(release_id):
54+
55+
def write_to_release_id_file(release_id: str | int) -> None:
5156
try:
5257
with open(RELEASE_ID_FILE, "w") as file:
53-
file.write(release_id)
58+
file.write(str(release_id))
5459
LOGGER.info(f"Created {RELEASE_ID_FILE} successfully.")
5560
except IOError as e:
5661
LOGGER.error(f"Could not create {RELEASE_ID_FILE} file: {e}")
5762
sys.exit(1)
5863

5964

6065
def upload_to_github_release_page(
61-
github_owner, github_repo, gardenlinux_release_id, file_to_upload, dry_run
62-
):
66+
github_owner: str,
67+
github_repo: str,
68+
gardenlinux_release_id: str | int,
69+
file_to_upload: str,
70+
dry_run: bool,
71+
) -> None:
6372
if dry_run:
6473
LOGGER.info(
6574
f"Dry run: would upload {file_to_upload} to release {gardenlinux_release_id} in repo {github_owner}/{github_repo}"

src/gardenlinux/github/release/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import logging
23

34
from gardenlinux.constants import GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME
45
from gardenlinux.logger import LoggerSetup
@@ -10,10 +11,10 @@
1011
write_to_release_id_file,
1112
)
1213

13-
LOGGER = LoggerSetup.get_logger("gardenlinux.github", "INFO")
14+
LOGGER = LoggerSetup.get_logger("gardenlinux.github", logging.INFO)
1415

1516

16-
def main():
17+
def main() -> None:
1718
parser = argparse.ArgumentParser(description="GitHub Release Script")
1819
subparsers = parser.add_subparsers(dest="command")
1920

src/gardenlinux/github/release_notes/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
def create_github_release_notes(
11-
gardenlinux_version, commitish, releases_s3_bucket_name
12-
):
11+
gardenlinux_version: str, commitish: str, releases_s3_bucket_name: str
12+
) -> str:
1313
package_list = get_package_list(gardenlinux_version)
1414

1515
output = ""

src/gardenlinux/github/release_notes/deployment_platform/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
from typing import Any, Dict
2+
13
from gardenlinux.constants import GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME
24

35

46
class DeploymentPlatform:
57
artifacts_bucket_name = GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME
68

7-
def short_name(self):
9+
def short_name(self) -> str:
810
return "generic"
911

10-
def full_name(self):
12+
def full_name(self) -> str:
1113
return "Generic Deployment Platform"
1214

13-
def published_images_by_regions(self, image_metadata):
15+
def published_images_by_regions(
16+
self, image_metadata: Dict[str, Any]
17+
) -> Dict[str, Any]:
1418
published_image_metadata = image_metadata["published_image_metadata"]
1519
flavor_name = image_metadata["s3_key"].split("/")[-1]
1620

@@ -21,10 +25,10 @@ def published_images_by_regions(self, image_metadata):
2125

2226
return {"flavor": flavor_name, "regions": regions}
2327

24-
def image_extension(self):
28+
def image_extension(self) -> str:
2529
return "raw"
2630

27-
def artifact_for_flavor(self, flavor, markdown_format=True):
31+
def artifact_for_flavor(self, flavor: str, markdown_format: bool = True) -> str:
2832
base_url = (
2933
f"https://{self.__class__.artifacts_bucket_name}.s3.amazonaws.com/objects"
3034
)
@@ -35,11 +39,11 @@ def artifact_for_flavor(self, flavor, markdown_format=True):
3539
else:
3640
return download_url
3741

38-
def region_details(self, image_metadata):
42+
def region_details(self, image_metadata: Dict[str, Any]) -> str:
3943
"""
4044
Generate the detailed region information for the collapsible section
4145
"""
42-
details = ""
46+
details: str = ""
4347

4448
match self.published_images_by_regions(image_metadata):
4549
case {"regions": regions}:
@@ -81,7 +85,7 @@ def region_details(self, image_metadata):
8185

8286
return details
8387

84-
def summary_text(self, image_metadata):
88+
def summary_text(self, image_metadata: Dict[str, Any]) -> str:
8589
"""
8690
Generate the summary text for the collapsible section
8791
"""

src/gardenlinux/github/release_notes/deployment_platform/ali_cloud.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44

55
class AliCloud(DeploymentPlatform):
6-
def short_name(self):
6+
def short_name(self) -> str:
77
return "ali"
88

9-
def full_name(self):
9+
def full_name(self) -> str:
1010
return "Alibaba Cloud"
1111

12-
def image_extension(self):
12+
def image_extension(self) -> str:
1313
return "qcow2"

0 commit comments

Comments
 (0)