Skip to content
Open
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
25 changes: 24 additions & 1 deletion nemo_retriever/src/nemo_retriever/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pathlib import Path
import os
import subprocess
import tempfile

try:
from ._build_info import BUILD_DATE as _PACKAGE_BUILD_DATE
Expand All @@ -23,6 +24,7 @@

_PKG_NAME = "nemo-retriever"
_UNKNOWN = "unknown"
_BUILD_STAMP = Path(tempfile.gettempdir()) / ".nemo_retriever_build_stamp"


def _utc_now() -> datetime:
Expand Down Expand Up @@ -57,7 +59,28 @@ def _build_datetime() -> datetime:
except ValueError:
pass

return _utc_now()
# Stamp file in the system temp dir makes the timestamp deterministic
# across the two separate subprocesses pip spawns during a PEP 517 build
# (metadata + wheel). We use tempdir rather than the source tree because
# pip may copy the source to different locations for each step.
if _BUILD_STAMP.exists():
try:
cached = _BUILD_STAMP.read_text().strip()
if cached:
ts = float(cached)
# Only reuse if less than 60 s old to avoid stale stamps.
if abs(_utc_now().timestamp() - ts) < 60:
return datetime.fromtimestamp(ts, tz=timezone.utc)
_BUILD_STAMP.unlink(missing_ok=True)
except (OSError, ValueError):
pass

now = _utc_now()
try:
_BUILD_STAMP.write_text(str(now.timestamp()))
except OSError:
pass
return now


@lru_cache(maxsize=1)
Expand Down
Loading