Skip to content

Commit

Permalink
fix(ecmwf_realtime): Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
devsjc committed Oct 28, 2024
1 parent 17318e3 commit 34b625d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/branch_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:

- name: Typecheck package
run: uv run mypy .
# TODO: GitHub output when https://github.com/python/mypy/pull/17771 merged

# Job to run unittests
# * Produces a JUnit XML report that can be displayed in the GitHub UI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def _wanted_file(filename: str, it: dt.datetime, max_step: int) -> bool:
"""
prefix: str = os.getenv("ECMWF_DISSEMINATION_REALTIME_FILE_PREFIX", "A2")
pattern: str = r"^" + prefix + r"[DS](\d{8})(\d{8})\d$"
match: re.Match | None = re.search(pattern=pattern, string=filename)
match: re.Match[str] | None = re.search(pattern=pattern, string=filename)
if match is None:
return False
if it.strftime("%m%d%H%M") != match.group(1):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def test__download_and_convert(self) -> None:
urls: list[str] = [
f"s3://{f}"
for f in c._fs.ls(f"{c.bucket}/ecmwf")
if c._wanted_file(f.split("/")[-1], test_it, c.model())
if c._wanted_file(
filename=f.split("/")[-1],
it=test_it,
max_step=max(c.model().expected_coordinates.step),
)
]

for url in urls:
Expand All @@ -59,8 +63,6 @@ def test__download_and_convert(self) -> None:
def test__wanted_file(self) -> None:
"""Test the _wanted_file method."""

c: ECMWFRealTimeS3ModelRepository = ECMWFRealTimeS3ModelRepository()

@dataclasses.dataclass
class TestCase:
name: str
Expand Down Expand Up @@ -94,8 +96,8 @@ class TestCase:

for t in tests:
with self.subTest(name=t.name):
result = c._wanted_file(
result = ECMWFRealTimeS3ModelRepository._wanted_file(
filename=t.filename,
it=test_it,
max_step=max(c.model().expected_coordinates.step))
max_step=max(ECMWFRealTimeS3ModelRepository.model().expected_coordinates.step))
self.assertEqual(result, t.expected)
6 changes: 4 additions & 2 deletions src/nwp_consumer/internal/services/consumer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def consume(self, it: dt.datetime | None = None) -> ResultE[pathlib.Path]:
if isinstance(write_result, Failure):
log.error(
f"Error writing data for init time '{it:%Y-%m-%d %H:%M}' "
f"and model {self.mr.repository().name}: {write_result.failure()!s}",
f"and model {self.mr.repository().name}: "
f"{write_result.failure()!s}",
)
failed_etls += 1

Expand All @@ -102,7 +103,8 @@ def consume(self, it: dt.datetime | None = None) -> ResultE[pathlib.Path]:
if failed_etls > 0:
monitor.join()
return Failure(OSError(
f"Failed to write {failed_etls} regions for init time '{it:%Y-%m-%d %H:%M}'. "
f"Failed to write {failed_etls} regions "
f"for init time '{it:%Y-%m-%d %H:%M}'. "
"See error logs for details.",
))

Expand Down

0 comments on commit 34b625d

Please sign in to comment.