@@ -133,13 +133,9 @@ def joinuser(*args):
133
133
134
134
# Regexes needed for parsing Makefile (and similar syntaxes,
135
135
# like old-style Setup files).
136
- try :
137
- import re
138
- _variable_rx = re .compile (r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)" )
139
- _findvar1_rx = re .compile (r"\$\(([A-Za-z][A-Za-z0-9_]*)\)" )
140
- _findvar2_rx = re .compile (r"\${([A-Za-z][A-Za-z0-9_]*)}" )
141
- except ImportError :
142
- pass
136
+ _variable_rx = r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)"
137
+ _findvar1_rx = r"\$\(([A-Za-z][A-Za-z0-9_]*)\)"
138
+ _findvar2_rx = r"\${([A-Za-z][A-Za-z0-9_]*)}"
143
139
144
140
145
141
def _safe_realpath (path ):
@@ -233,6 +229,8 @@ def _parse_makefile(filename, vars=None, keep_unresolved=True):
233
229
optional dictionary is passed in as the second argument, it is
234
230
used instead of a new dictionary.
235
231
"""
232
+ import re
233
+
236
234
if vars is None :
237
235
vars = {}
238
236
done = {}
@@ -245,7 +243,7 @@ def _parse_makefile(filename, vars=None, keep_unresolved=True):
245
243
for line in lines :
246
244
if line .startswith ('#' ) or line .strip () == '' :
247
245
continue
248
- m = _variable_rx .match (line )
246
+ m = re .match (_variable_rx , line )
249
247
if m :
250
248
n , v = m .group (1 , 2 )
251
249
v = v .strip ()
@@ -278,8 +276,8 @@ def _parse_makefile(filename, vars=None, keep_unresolved=True):
278
276
while len (variables ) > 0 :
279
277
for name in tuple (variables ):
280
278
value = notdone [name ]
281
- m1 = _findvar1_rx .search (value )
282
- m2 = _findvar2_rx .search (value )
279
+ m1 = re .search (_findvar1_rx , value )
280
+ m2 = re .search (_findvar2_rx , value )
283
281
if m1 and m2 :
284
282
m = m1 if m1 .start () < m2 .start () else m2
285
283
else :
@@ -812,6 +810,7 @@ def expand_makefile_vars(s, vars):
812
810
variable expansions; if 'vars' is the output of 'parse_makefile()',
813
811
you're fine. Returns a variable-expanded version of 's'.
814
812
"""
813
+ import re
815
814
816
815
# This algorithm does multiple expansion, so if vars['foo'] contains
817
816
# "${bar}", it will expand ${foo} to ${bar}, and then expand
@@ -820,7 +819,7 @@ def expand_makefile_vars(s, vars):
820
819
# according to make's variable expansion semantics.
821
820
822
821
while True :
823
- m = _findvar1_rx .search (s ) or _findvar2_rx .search (s )
822
+ m = re .search (_findvar1_rx , s ) or re .search (_findvar2_rx , s )
824
823
if m :
825
824
(beg , end ) = m .span ()
826
825
s = s [0 :beg ] + vars .get (m .group (1 )) + s [end :]
0 commit comments