From: Richard Kreckel Date: Tue, 31 Dec 2024 14:15:05 +0000 (+0100) Subject: [build] Use Python raw strings in regular expressions. X-Git-Tag: release_1-8-8~6 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=commitdiff_plain;h=2b3fe3bf9cded69da7c4fb0404f23549ee8fea02;p=ginac.git [build] Use Python raw strings in regular expressions. To suppress some Python3 warnings about unescaped '\s' during build. Also, this seems to be recommended best practice. --- diff --git a/ginsh/ginsh_fcn_help.py b/ginsh/ginsh_fcn_help.py index edc675b4..2292eadf 100644 --- a/ginsh/ginsh_fcn_help.py +++ b/ginsh/ginsh_fcn_help.py @@ -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 diff --git a/ginsh/ginsh_op_help.py b/ginsh/ginsh_op_help.py index a38697f1..39ee2799 100644 --- a/ginsh/ginsh_op_help.py +++ b/ginsh/ginsh_op_help.py @@ -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