Skip to content

Commit 9a9f9ed

Browse files
committed
Fix pip install race condition by persisting build timestamp
1 parent b8e7289 commit 9a9f9ed

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,6 @@ outputs/
249249
models/
250250

251251
nemo_retriever/run_results/
252+
253+
# Ephemeral stamp file used to keep version deterministic across pip build subprocesses
254+
.build_stamp

nemo_retriever/src/nemo_retriever/version.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pathlib import Path
1313
import os
1414
import subprocess
15+
import tempfile
1516

1617
try:
1718
from ._build_info import BUILD_DATE as _PACKAGE_BUILD_DATE
@@ -23,6 +24,7 @@
2324

2425
_PKG_NAME = "nemo-retriever"
2526
_UNKNOWN = "unknown"
27+
_BUILD_STAMP = Path(tempfile.gettempdir()) / ".nemo_retriever_build_stamp"
2628

2729

2830
def _utc_now() -> datetime:
@@ -57,7 +59,28 @@ def _build_datetime() -> datetime:
5759
except ValueError:
5860
pass
5961

60-
return _utc_now()
62+
# Stamp file in the system temp dir makes the timestamp deterministic
63+
# across the two separate subprocesses pip spawns during a PEP 517 build
64+
# (metadata + wheel). We use tempdir rather than the source tree because
65+
# pip may copy the source to different locations for each step.
66+
if _BUILD_STAMP.exists():
67+
try:
68+
cached = _BUILD_STAMP.read_text().strip()
69+
if cached:
70+
ts = float(cached)
71+
# Only reuse if less than 60 s old to avoid stale stamps.
72+
if abs(_utc_now().timestamp() - ts) < 60:
73+
return datetime.fromtimestamp(ts, tz=timezone.utc)
74+
_BUILD_STAMP.unlink(missing_ok=True)
75+
except (OSError, ValueError):
76+
pass
77+
78+
now = _utc_now()
79+
try:
80+
_BUILD_STAMP.write_text(str(now.timestamp()))
81+
except OSError:
82+
pass
83+
return now
6184

6285

6386
@lru_cache(maxsize=1)

0 commit comments

Comments
 (0)