Skip to content

Commit 28cbbfe

Browse files
authored
Fix Python 3.12 SyntaxWarnings by converting regex strings to raw strings in proj.py (#318)
1 parent ecc965e commit 28cbbfe

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

framework/rsf/proj.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ def test(target=None,source=None,env=None):
112112
figdir = env.get('figdir')
113113
bindir = env.get('bindir')
114114

115-
locked = re.sub('.*\/([^\/]+)\/([^\/]+)\/([^\/]+)\/Fig\/',
116-
figdir+'/\\1/\\2/\\3/',os.path.abspath(src))
115+
# Fixed: Use raw strings for regex to avoid Python 3.12 SyntaxWarning: invalid escape sequence '\/'
116+
locked = re.sub(r'.*\/([^\/]+)\/([^\/]+)\/([^\/]+)\/Fig\/',
117+
figdir+r'/\1/\2/\3/',os.path.abspath(src))
117118
print("Comparing %s and %s" % (locked,src))
118119
if os.path.isfile(locked):
119120
if locked.endswith(vpsuffix):
@@ -310,8 +311,9 @@ def __init__(self,**kw):
310311
rsf.path.sconsign(self)
311312

312313
self.resdir = resdir
313-
self.figdir = re.sub('.*\/((?:[^\/]+)\/(?:[^\/]+)\/(?:[^\/]+))$',
314-
self.figs+'/\\1',cwd)
314+
# Fixed: Use raw strings for regex to avoid Python 3.12 SyntaxWarning: invalid escape sequence '\/'
315+
self.figdir = re.sub(r'.*\/((?:[^\/]+)\/(?:[^\/]+)\/(?:[^\/]+))$',
316+
self.figs+r'/\1',cwd)
315317
self.progsuffix = self['PROGSUFFIX']
316318

317319
# Keep certain environmental variables in the environment
@@ -540,13 +542,15 @@ def Flow(self,target,source,flow,stdout=1,stdin=1,rsfflow=1,
540542
if reduce == 'add':
541543
splitpar += ' join=0'
542544
else:
543-
join = re.search('cat\s+axis=(\d)',reduce)
545+
# Fixed: Use raw string for regex to avoid Python 3.12 SyntaxWarning: invalid escape sequence '\s'
546+
join = re.search(r'cat\s+axis=(\d)',reduce)
544547
if join:
545548
splitpar += ' join=%s' % join.group(1)
546549
flow = '|'.join([' '.join([split[1],splitpar,x]) for x in flow.split('|')])
547550
for k in split[2]:
548551
# par=${SOURCES[k]} -> _par=${SOURCES[k]}
549-
flow = re.sub(r'(\S+=\${SOURCES\[%d\]})' % k,'_\\1',flow)
552+
# Fixed: Use raw string for replacement to avoid Python 3.12 escape sequence issues
553+
flow = re.sub(r'(\S+=\${SOURCES\[%d\]})' % k,r'_\1',flow)
550554
elif self.jobs > 1 and rsfflow and sfiles:
551555
# Split the flow into parallel flows
552556
self.__Split(split,reduction,
@@ -585,7 +589,8 @@ def Flow(self,target,source,flow,stdout=1,stdin=1,rsfflow=1,
585589

586590
# May need to do it remotely
587591
if remote:
588-
command = re.sub('"','\\"',command)
592+
# Fixed: Use raw string for replacement to avoid Python 3.12 escape sequence issues
593+
command = re.sub('"',r'\"',command)
589594
command = ' '.join(['$( ssh',node,'$) \"cd ',self.cwd,';',command,'\"'])
590595

591596
targets = []

0 commit comments

Comments
 (0)