diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,3 @@ # should match https://pypi.python.org/pypi names. For the full spec or # dependency lines, see https://pip.readthedocs.org/en/1.1/requirements.html methodtools -pytz diff --git a/swh/provenance/provenance.py b/swh/provenance/provenance.py --- a/swh/provenance/provenance.py +++ b/swh/provenance/provenance.py @@ -1,6 +1,5 @@ -from datetime import datetime +from datetime import datetime, timezone import os -import pytz from typing import Dict, Generator, List, Optional, Tuple from typing_extensions import Protocol, runtime_checkable @@ -10,6 +9,8 @@ from .origin import OriginEntry from .revision import RevisionEntry +UTCMIN = datetime.min.replace(tzinfo=timezone.utc) + @runtime_checkable class ProvenanceInterface(Protocol): @@ -284,13 +285,12 @@ # Recursively analyse directory nodes. stack.append(child) else: - maxdates = [] - for child in current.children: - assert child.maxdate is not None - maxdates.append(child.maxdate) - current.maxdate = ( - max(maxdates) if maxdates else datetime.min.replace(tzinfo=pytz.UTC) - ) + maxdates = [ + child.maxdate + for child in current.children + if child.maxdate is not None # mostly to please mypy + ] + current.maxdate = max(maxdates) if maxdates else UTCMIN else: # Directory node in the frontier, just use its known date. current.maxdate = current.date @@ -327,9 +327,7 @@ ) provenance.directory_add_to_revision(revision, current.entry, path) directory_process_content( - provenance, - directory=current.entry, - relative=current.entry, + provenance, directory=current.entry, relative=current.entry, ) else: # No point moving the frontier here. Either there are no files or they diff --git a/swh/provenance/revision.py b/swh/provenance/revision.py --- a/swh/provenance/revision.py +++ b/swh/provenance/revision.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timezone from itertools import islice import threading from typing import Iterable, Iterator, Optional, Tuple @@ -20,6 +20,7 @@ self.archive = archive self.id = id self.date = date + assert self.date is None or self.date.tzinfo is not None self.parents = parents self.root = root @@ -78,11 +79,11 @@ def __next__(self): with self.mutex: id, date, root = next(self.revisions) + date = datetime.fromisoformat(date) + if date.tzinfo is None: + date = date.replace(tzinfo=timezone.utc) return RevisionEntry( - self.archive, - hash_to_bytes(id), - date=datetime.fromisoformat(date), - root=hash_to_bytes(root), + self.archive, hash_to_bytes(id), date=date, root=hash_to_bytes(root), )