7171import enum
7272import glob
7373import hashlib
74- import functools
7574import json
7675import logging
7776import 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+
98103class 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
240245def _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
257262def _hash_sources (bsize = 4096 ):
258263 hh = hashlib .sha256 ()
259264 buf = bytearray (bsize )
@@ -683,7 +688,20 @@ def bc_make_source_rpm(ctx):
683688
684689def _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