diff --git a/morgan/__init__.py b/morgan/__init__.py index 755fed9..abeb7ac 100644 --- a/morgan/__init__.py +++ b/morgan/__init__.py @@ -20,7 +20,7 @@ from morgan import configurator, metadata, server from morgan.__about__ import __version__ -from morgan.utils import Cache, to_single_dash +from morgan.utils import Cache, to_single_dash, touch_file PYPI_ADDRESS = "https://pypi.org/simple/" PREFERRED_HASH_ALG = "sha256" @@ -386,6 +386,7 @@ def _download_file( if os.path.exists(target): truehash = self._hash_file(target, hashalg) if truehash == exphash: + touch_file(target, fileinfo) return True print("\t{}...".format(fileinfo["url"]), end=" ") @@ -402,6 +403,7 @@ def _download_file( ) ) + touch_file(target, fileinfo) return True def _hash_file(self, filepath: str, hashalg: str) -> str: diff --git a/morgan/utils.py b/morgan/utils.py index 425efc1..c8ca4e6 100644 --- a/morgan/utils.py +++ b/morgan/utils.py @@ -1,5 +1,7 @@ +import os import re +import dateutil # type: ignore[import-untyped] from packaging.requirements import Requirement @@ -42,3 +44,13 @@ def is_simple_case(self, req): if all(spec.operator in ('>', '>=') for spec in specifier._specs): return True return False + + +def touch_file(path: str, fileinfo: dict): + 'upload-time: 2025-05-28T18:46:29.349478Z' + time_str = fileinfo.get('upload-time') + if not path or not time_str: + return + dt = dateutil.parser.parse(time_str) + ts = dt.timestamp() + os.utime(path, (ts, ts)) diff --git a/pyproject.toml b/pyproject.toml index 0756ff5..e89ef59 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ dependencies = [ # solved in morgan/__init__.py "importlib-metadata~=4.12.0; python_version < '3.8'", "tomli~=2.0.1", + "python-dateutil", ] classifiers = [ "Development Status :: 4 - Beta",