Skip to content

Commit a09c3ff

Browse files
committed
[build] Prefix local version label with commit timestamp so rebuilds sort in order
Local labels are now +<YYYYMMDDHHMM UTC>.g<hash> instead of +<hash>. PEP 440 compares a bare hash label as a string, so pip could pick an older rebuild of the same OpenCV version.
1 parent d22c560 commit a09c3ff

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎setup.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import date
1+
from datetime import date, datetime, timezone
22
import glob
33
import io
44
import os
@@ -593,8 +593,18 @@ def generate_version_file(contrib, headless, rolling, cuda_arch_bin, cuda_arch_p
593593
version = date.today().strftime('%Y%m%d')
594594
opencv_version += ".{}".format(version)
595595
else:
596-
# local version identifier, not to be published on PyPI
597-
version = git_hash
596+
# local version identifier, not to be published on PyPI. Prefix the hash with the
597+
# commit's UTC timestamp so rebuilds of the same OpenCV version sort in commit order:
598+
# PEP 440 compares a bare "+<hash>" label as a string (effectively random), while a
599+
# leading numeric segment compares as an integer. One segment (YYYYMMDDHHMM) because
600+
# PEP 440 drops leading zeros in each segment (".0905" would become ".905").
601+
commit_time = int(
602+
subprocess.check_output(["git", "log", "-1", "--format=%ct", "HEAD"])
603+
.splitlines()[0]
604+
.decode()
605+
)
606+
timestamp = datetime.fromtimestamp(commit_time, timezone.utc).strftime("%Y%m%d%H%M")
607+
version = "{}.g{}".format(timestamp, git_hash)
598608
opencv_version += "+{}".format(version)
599609

600610
with open("cv2/version.py", "w") as f:

0 commit comments

Comments
 (0)