From: John Mulligan Date: Fri, 13 Jun 2025 00:37:56 +0000 (-0400) Subject: script/build-with-container: add workarounds for older python versions X-Git-Tag: testing/wip-jcollin-testing-20250821.032900-reef~5^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=2f52e519c799645e0b9fe2ca2c9ef6905314645b;p=ceph-ci.git script/build-with-container: add workarounds for older python versions Signed-off-by: John Mulligan (cherry picked from commit 45e0979b60bd4e508fd1e00ac3bfdab5cdcf8a52) --- diff --git a/src/script/build-with-container.py b/src/script/build-with-container.py index ad49e49fb7f..94c9fb3809c 100755 --- a/src/script/build-with-container.py +++ b/src/script/build-with-container.py @@ -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)