]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
script/build-with-container: add workarounds for older python versions
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 13 Jun 2025 00:37:56 +0000 (20:37 -0400)
committerDavid Galloway <david.galloway@ibm.com>
Fri, 15 Aug 2025 17:57:03 +0000 (13:57 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 45e0979b60bd4e508fd1e00ac3bfdab5cdcf8a52)

src/script/build-with-container.py

index ad49e49fb7f4d788f6e57d34299675cd500ccc50..94c9fb3809cf95fb0cd70b0ded8d0a327d81bb14 100755 (executable)
@@ -71,7 +71,6 @@ import contextlib
 import enum
 import glob
 import hashlib
-import functools
 import json
 import logging
 import os
@@ -95,6 +94,12 @@ except ImportError:
             return self.value
 
 
+try:
+    from functools import cache as ftcache
+except ImportError:
+    ftcache = lambda f: f
+
+
 class DistroKind(StrEnum):
     CENTOS10 = "centos10"
     CENTOS8 = "centos8"
@@ -251,7 +256,7 @@ def _git_command(ctx, args):
 
 # Assume that the git version will not be changing after the 1st time
 # the command is run.
-@functools.cache
+@ftcache
 def _git_current_branch(ctx):
     cmd = _git_command(ctx, ["rev-parse", "--abbrev-ref", "HEAD"])
     res = _run(cmd, check=True, capture_output=True)
@@ -268,7 +273,7 @@ def _git_current_sha(ctx, short=True):
     return res.stdout.decode("utf8").strip()
 
 
-@functools.cache
+@ftcache
 def _hash_sources(bsize=4096):
     hh = hashlib.sha256()
     buf = bytearray(bsize)
@@ -698,7 +703,20 @@ def bc_make_source_rpm(ctx):
 
 def _glob_search(ctx, pattern):
     overlay = ctx.overlay()
-    return glob.glob(pattern, root_dir=overlay.upper if overlay else None)
+    try:
+        return glob.glob(pattern, root_dir=overlay.upper if overlay else None)
+    except TypeError:
+        log.info("glob with root_dir failed... falling back to chdir")
+    try:
+        prev_dir = os.getcwd()
+        if overlay:
+            os.chdir(overlay.upper)
+            log.debug("chdir %s -> %s", prev_dir, overlay.upper)
+        result = glob.glob(pattern)
+    finally:
+        if overlay:
+            os.chdir(prev_dir)
+    return result
 
 
 @Builder.set(Steps.RPM)