Skip to content

Commit c78ed19

Browse files
committed
Lint: Fix pyright errors in s3 module
1 parent ef7d368 commit c78ed19

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

src/gardenlinux/s3/__main__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
"""
77

88
import argparse
9-
import os
10-
import re
11-
import sys
12-
from functools import reduce
13-
from pathlib import Path
14-
from typing import Any, List, Set
159

1610
from .s3_artifacts import S3Artifacts
1711

src/gardenlinux/s3/bucket.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(
5656
if endpoint_url is not None:
5757
s3_resource_config["endpoint_url"] = endpoint_url
5858

59-
self._s3_resource = boto3.resource("s3", **s3_resource_config)
59+
self._s3_resource: Any = boto3.resource("s3", **s3_resource_config)
6060

6161
self._bucket = self._s3_resource.Bucket(bucket_name)
6262
self._logger = logger
@@ -116,7 +116,9 @@ def download_fileobj(self, key, fp, *args, **kwargs):
116116

117117
self._logger.info(f"Downloaded {key} from S3 as binary data")
118118

119-
def read_cache_file_or_filter(self, cache_file, cache_ttl: int = 3600, **kwargs):
119+
def read_cache_file_or_filter(
120+
self, cache_file: str | PathLike[str] | None, cache_ttl: int = 3600, **kwargs
121+
):
120122
"""
121123
Read S3 object keys from cache if valid or filter for S3 object keys.
122124
@@ -128,19 +130,24 @@ def read_cache_file_or_filter(self, cache_file, cache_ttl: int = 3600, **kwargs)
128130
:since: 0.9.0
129131
"""
130132

131-
if not isinstance(cache_file, PathLike):
132-
cache_file = Path(cache_file)
133+
if cache_file is not None:
134+
cache_path = Path(cache_file)
133135

134-
if cache_file.exists() and (time() - cache_file.stat().st_mtime) < cache_ttl:
135-
with cache_file.open("r") as fp:
136-
return json.loads(fp.read())
136+
if (
137+
cache_path.exists()
138+
and (time() - cache_path.stat().st_mtime) < cache_ttl
139+
):
140+
with cache_path.open("r") as fp:
141+
return json.loads(fp.read())
142+
else:
143+
cache_path = None
137144

138145
artifacts = [
139146
s3_object.key for s3_object in self._bucket.objects.filter(**kwargs).all()
140147
]
141148

142-
if cache_file is not None:
143-
with cache_file.open("w") as fp:
149+
if cache_path is not None:
150+
with cache_path.open("w") as fp:
144151
fp.write(json.dumps(artifacts))
145152

146153
return artifacts

src/gardenlinux/s3/s3_artifacts.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import yaml
1919

2020
from ..features.cname import CName
21-
from ..logger import LoggerSetup
2221
from .bucket import Bucket
2322

2423

@@ -53,7 +52,7 @@ def __init__(
5352
:since: 0.8.0
5453
"""
5554

56-
self._bucket = Bucket(bucket_name, endpoint_url, s3_resource_config)
55+
self._bucket = Bucket(bucket_name, endpoint_url, s3_resource_config, logger)
5756

5857
@property
5958
def bucket(self):
@@ -68,8 +67,8 @@ def bucket(self):
6867

6968
def download_to_directory(
7069
self,
71-
cname,
72-
artifacts_dir,
70+
cname: str,
71+
artifacts_dir: str | PathLike[str],
7372
):
7473
"""
7574
Download S3 artifacts to a given directory.
@@ -80,8 +79,7 @@ def download_to_directory(
8079
:since: 0.8.0
8180
"""
8281

83-
if not isinstance(artifacts_dir, PathLike):
84-
artifacts_dir = Path(artifacts_dir)
82+
artifacts_dir = Path(artifacts_dir)
8583

8684
if not artifacts_dir.is_dir():
8785
raise RuntimeError(f"Artifacts directory given is invalid: {artifacts_dir}")
@@ -101,8 +99,8 @@ def download_to_directory(
10199

102100
def upload_from_directory(
103101
self,
104-
cname,
105-
artifacts_dir,
102+
cname: str,
103+
artifacts_dir: str | PathLike[str],
106104
delete_before_push=False,
107105
):
108106
"""
@@ -115,8 +113,7 @@ def upload_from_directory(
115113
:since: 0.8.0
116114
"""
117115

118-
if not isinstance(artifacts_dir, PathLike):
119-
artifacts_dir = Path(artifacts_dir)
116+
artifacts_dir = Path(artifacts_dir)
120117

121118
cname_object = CName(cname)
122119

@@ -146,6 +143,9 @@ def upload_from_directory(
146143
f"Release file data and given cname conflict detected: Commit ID {cname_object.commit_id}"
147144
)
148145

146+
if cname_object.version is None:
147+
raise RuntimeError("CName version could not be determined!")
148+
149149
commit_hash = release_config.get(UNNAMED_SECTION, "GARDENLINUX_COMMIT_ID_LONG")
150150

151151
feature_set = release_config.get(UNNAMED_SECTION, "GARDENLINUX_FEATURES")

0 commit comments

Comments
 (0)