]> www.ginac.de Git - ginac.git/commitdiff
[build] Use Python raw strings in regular expressions.
authorRichard Kreckel <kreckel@ginac.de>
Tue, 31 Dec 2024 14:15:05 +0000 (15:15 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Tue, 31 Dec 2024 14:15:05 +0000 (15:15 +0100)
To suppress some Python3 warnings about unescaped '\s' during build.
Also, this seems to be recommended best practice.

ginsh/ginsh_fcn_help.py
ginsh/ginsh_op_help.py

index edc675b4cc3f1bf1cface18a24210494d83dc3bc..2292eadf17be306ff90ffa8348a24013d13b7f6d 100644 (file)
@@ -3,19 +3,19 @@
 # Convert help for ginsh functions from man page to C source
 import sys, re, optparse
 
-rxStart = re.compile('^.*GINSH_FCN_HELP_START$')
-rxEnd = re.compile('^.*GINSH_FCN_HELP_END$')
-fcnRx = re.compile('^[.]BI\s+')
-hlpRx = re.compile('\\\\[-]')
+rxStart = re.compile(r'^.*GINSH_FCN_HELP_START$')
+rxEnd = re.compile(r'^.*GINSH_FCN_HELP_END$')
+fcnRx = re.compile(r'^[.]BI\s+')
+hlpRx = re.compile(r'\\[-]')
 codeFmt = 'insert_help("%s",\n"%s"\n);\n'
 
 def parseProto(pStr):
-       pStr = fcnRx.sub('', pStr)
-       pStr = re.sub('\s', '', pStr)
-       pStr = re.sub('"', '', pStr)
-       pStr = re.sub(',', ', ', pStr)
-       pStr = re.sub('\\[', ' [', pStr)
-       name = pStr.split('(')[0]
+       pStr = fcnRx.sub(r'', pStr)
+       pStr = re.sub(r'\s', '', pStr)
+       pStr = re.sub(r'"', '', pStr)
+       pStr = re.sub(r',', ', ', pStr)
+       pStr = re.sub(r'\[', ' [', pStr)
+       name = pStr.split(r'(')[0]
        return name, pStr
 
 def extractHelp(inp, out):
@@ -32,8 +32,8 @@ def extractHelp(inp, out):
                if fcnRx.match(l):
                        name, proto = parseProto(l)
                elif hlpRx.match(l):
-                       l = hlpRx.sub('', l).strip()
-                       l = re.sub('"', "'", l)
+                       l = hlpRx.sub(r'', l).strip()
+                       l = re.sub(r'"', r"'", l)
                        synopsis = '%s"\n" - %s' % ( proto, l )
                elif l.lower() == '.br':
                        synopsis = synopsis or proto
index a38697f1452bc071dddc7476561f6b13879b1bba..39ee2799514be15c0222e0c5b629682111fad437 100644 (file)
@@ -3,10 +3,10 @@
 # Convert help for ginsh operators from man page to C source
 import sys, re, optparse
 
-rxStart = re.compile('^.*GINSH_OP_HELP_START$')
-rxEnd = re.compile('^.*GINSH_OP_HELP_END$')
-fcnRx = re.compile('^[.]B\s+')
-minusRx = re.compile('\\\\[-]')
+rxStart = re.compile(r'^.*GINSH_OP_HELP_START$')
+rxEnd = re.compile(r'^.*GINSH_OP_HELP_END$')
+fcnRx = re.compile(r'^[.]B\s+')
+minusRx = re.compile(r'\\[-]')
 codeFmt = 'insert_help("operators", "%s\\t" "%s");\n'
 
 def extractHelp(inp, out):
@@ -23,8 +23,8 @@ def extractHelp(inp, out):
                                out.write(codeFmt % ( sym, synopsis ))
                        break
                if fcnRx.match(l):
-                       l = fcnRx.sub('', l)
-                       sym = minusRx.sub('-', l)
+                       l = fcnRx.sub(r'', l)
+                       sym = minusRx.sub(r'-', l)
                elif l.lower() == '.tp':
                        out.write(codeFmt % ( sym, synopsis ))
                        sym, synopsis = None, None