Skip to content

Commit 3bd52c9

Browse files
authored
Merge pull request ceph#63913 from phlogistonjohn/jjm-bwc-pyold
script/build-with-container: add workarounds for older python versions
2 parents 641f50d + 45e0979 commit 3bd52c9

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/script/build-with-container.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
import enum
7272
import glob
7373
import hashlib
74-
import functools
7574
import json
7675
import logging
7776
import os
@@ -95,6 +94,12 @@ def __str__(self):
9594
return self.value
9695

9796

97+
try:
98+
from functools import cache as ftcache
99+
except ImportError:
100+
ftcache = lambda f: f
101+
102+
98103
class DistroKind(StrEnum):
99104
CENTOS10 = "centos10"
100105
CENTOS8 = "centos8"
@@ -236,7 +241,7 @@ def _git_command(ctx, args):
236241

237242
# Assume that the git version will not be changing after the 1st time
238243
# the command is run.
239-
@functools.cache
244+
@ftcache
240245
def _git_current_branch(ctx):
241246
cmd = _git_command(ctx, ["rev-parse", "--abbrev-ref", "HEAD"])
242247
res = _run(cmd, check=True, capture_output=True)
@@ -253,7 +258,7 @@ def _git_current_sha(ctx, short=True):
253258
return res.stdout.decode("utf8").strip()
254259

255260

256-
@functools.cache
261+
@ftcache
257262
def _hash_sources(bsize=4096):
258263
hh = hashlib.sha256()
259264
buf = bytearray(bsize)
@@ -683,7 +688,20 @@ def bc_make_source_rpm(ctx):
683688

684689
def _glob_search(ctx, pattern):
685690
overlay = ctx.overlay()
686-
return glob.glob(pattern, root_dir=overlay.upper if overlay else None)
691+
try:
692+
return glob.glob(pattern, root_dir=overlay.upper if overlay else None)
693+
except TypeError:
694+
log.info("glob with root_dir failed... falling back to chdir")
695+
try:
696+
prev_dir = os.getcwd()
697+
if overlay:
698+
os.chdir(overlay.upper)
699+
log.debug("chdir %s -> %s", prev_dir, overlay.upper)
700+
result = glob.glob(pattern)
701+
finally:
702+
if overlay:
703+
os.chdir(prev_dir)
704+
return result
687705

688706

689707
@Builder.set(Steps.RPM)

0 commit comments

Comments
 (0)