summaryrefslogtreecommitdiff
path: root/numpy/distutils/from_template.py
diff options
context:
space:
mode:
authorWarren Weckesser <warren.weckesser@gmail.com>2018-03-10 12:42:11 -0500
committerWarren Weckesser <warren.weckesser@gmail.com>2018-03-10 18:28:47 -0500
commit16331cc1cf9b2cf3505d0c4742a854dc00923d9d (patch)
treeedb04657705a50a2d1a720e2974517c3abc9d4b3 /numpy/distutils/from_template.py
parentc486d8d0d496f6b366dc827a3d41ed1e9d593ec8 (diff)
downloadnumpy-16331cc1cf9b2cf3505d0c4742a854dc00923d9d.tar.gz
BUG: distutils: Remove named templates from the output.
The code now does not copy the named templates found outside a function or subroutine to the output file. Fixes gh-10712.
Diffstat (limited to 'numpy/distutils/from_template.py')
-rw-r--r--numpy/distutils/from_template.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/numpy/distutils/from_template.py b/numpy/distutils/from_template.py
index 8f587eab9..b7ce47708 100644
--- a/numpy/distutils/from_template.py
+++ b/numpy/distutils/from_template.py
@@ -98,6 +98,11 @@ def find_repl_patterns(astr):
names[name] = thelist
return names
+def find_and_remove_repl_patterns(astr):
+ names = find_repl_patterns(astr)
+ astr = re.subn(named_re, '', astr)[0]
+ return astr, names
+
item_re = re.compile(r"\A\\(?P<index>\d+)\Z")
def conv(astr):
b = astr.split(',')
@@ -194,8 +199,9 @@ def process_str(allstr):
names = {}
names.update(_special_names)
for sub in struct:
- writestr += newstr[oldend:sub[0]]
- names.update(find_repl_patterns(newstr[oldend:sub[0]]))
+ cleanedstr, defs = find_and_remove_repl_patterns(newstr[oldend:sub[0]])
+ writestr += cleanedstr
+ names.update(defs)
writestr += expand_sub(newstr[sub[0]:sub[1]], names)
oldend = sub[1]
writestr += newstr[oldend:]