Skip to content

Commit

Permalink
[S3_manage] Handle invalid versions
Browse files Browse the repository at this point in the history
  • Loading branch information
malfet committed Oct 31, 2023
1 parent d12d1f2 commit 96cbf68
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions s3_management/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from collections import defaultdict
from typing import Iterable, List, Type, Dict, Set, TypeVar, Optional
from re import sub, match, search
from packaging.version import parse
from packaging.version import parse as _parse_version, Version, InvalidVersion

import boto3

Expand Down Expand Up @@ -150,6 +150,12 @@ def between_bad_dates(package_build_time: datetime):
return start_bad <= package_build_time <= end_bad


def safe_parse_version(ver_str: str) -> Version:
try:
return _parse_version(ver_str)
except InvalidVersion:
return Version(0, 0, 0)

class S3Index:
def __init__(self: S3IndexType, objects: List[S3Object], prefix: str) -> None:
self.objects = objects
Expand Down Expand Up @@ -177,7 +183,7 @@ def nightly_packages_to_show(self: S3IndexType) -> Set[S3Object]:
# sorting, sorts in reverse to put the most recent versions first
all_sorted_packages = sorted(
{self.normalize_package_version(obj) for obj in self.objects},
key=lambda name_ver: parse(name_ver.split('-', 1)[-1]),
key=lambda name_ver: safe_parse_version(name_ver.split('-', 1)[-1]),
reverse=True,
)
packages: Dict[str, int] = defaultdict(int)
Expand Down

0 comments on commit 96cbf68

Please sign in to comment.