11# Parse Makefiles and Python Setup(.in) files.
22
3- import regex
3+ import re
44import string
55
66
77# Extract variable definitions from a Makefile.
88# Return a dictionary mapping names to values.
99# May raise IOError.
1010
11- makevardef = regex .compile ('^\ ([a-zA-Z0-9_]+\ )[ \t ]*=\ (.*\ )' )
11+ makevardef = re .compile ('^([a-zA-Z0-9_]+)[ \t ]*=(.*)' )
1212
1313def getmakevars (filename ):
1414 variables = {}
@@ -18,9 +18,10 @@ def getmakevars(filename):
1818 line = fp .readline ()
1919 if not line :
2020 break
21- if makevardef .match (line ) < 0 :
21+ matchobj = makevardef .match (line )
22+ if not matchobj :
2223 continue
23- name , value = makevardef .group (1 , 2 )
24+ ( name , value ) = matchobj .group (1 , 2 )
2425 # Strip trailing comment
2526 i = string .find (value , '#' )
2627 if i >= 0 :
@@ -37,7 +38,7 @@ def getmakevars(filename):
3738# definitions, the second mapping variable names to their values.
3839# May raise IOError.
3940
40- setupvardef = regex .compile ('^\ ([a-zA-Z0-9_]+\)=\ (.*\ )' )
41+ setupvardef = re .compile ('^([a-zA-Z0-9_]+)= (.*)' )
4142
4243def getsetupinfo (filename ):
4344 modules = {}
@@ -52,8 +53,9 @@ def getsetupinfo(filename):
5253 i = string .find (line , '#' )
5354 if i >= 0 :
5455 line = line [:i ]
55- if setupvardef .match (line ) >= 0 :
56- name , value = setupvardef .group (1 , 2 )
56+ matchobj = setupvardef .match (line )
57+ if matchobj :
58+ (name , value ) = matchobj .group (1 , 2 )
5759 variables [name ] = string .strip (value )
5860 else :
5961 words = string .split (line )
0 commit comments