Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion morgan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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=" ")
Expand All @@ -402,6 +403,7 @@ def _download_file(
)
)

touch_file(target, fileinfo)
return True

def _hash_file(self, filepath: str, hashalg: str) -> str:
Expand Down
12 changes: 12 additions & 0 deletions morgan/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import re

import dateutil # type: ignore[import-untyped]
from packaging.requirements import Requirement


Expand Down Expand Up @@ -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))
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down