diff options
Diffstat (limited to 'Tools/scripts/pdeps.py')
-rwxr-xr-x | Tools/scripts/pdeps.py | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/Tools/scripts/pdeps.py b/Tools/scripts/pdeps.py index f8218ac5243..4e8e930948f 100755 --- a/Tools/scripts/pdeps.py +++ b/Tools/scripts/pdeps.py @@ -64,29 +64,28 @@ m_from = re.compile('^[ \t]*import[ \t]+([^#]+)') # Collect data from one file # def process(filename, table): - fp = open(filename, 'r') - mod = os.path.basename(filename) - if mod[-3:] == '.py': - mod = mod[:-3] - table[mod] = list = [] - while 1: - line = fp.readline() - if not line: break - while line[-1:] == '\\': - nextline = fp.readline() - if not nextline: break - line = line[:-1] + nextline - m_found = m_import.match(line) or m_from.match(line) - if m_found: - (a, b), (a1, b1) = m_found.regs[:2] - else: continue - words = line[a1:b1].split(',') - # print '#', line, words - for word in words: - word = word.strip() - if word not in list: - list.append(word) - fp.close() + with open(filename) as fp: + mod = os.path.basename(filename) + if mod[-3:] == '.py': + mod = mod[:-3] + table[mod] = list = [] + while 1: + line = fp.readline() + if not line: break + while line[-1:] == '\\': + nextline = fp.readline() + if not nextline: break + line = line[:-1] + nextline + m_found = m_import.match(line) or m_from.match(line) + if m_found: + (a, b), (a1, b1) = m_found.regs[:2] + else: continue + words = line[a1:b1].split(',') + # print '#', line, words + for word in words: + word = word.strip() + if word not in list: + list.append(word) # Compute closure (this is in fact totally general) |