New submission from $$Coffeepot$$ <coffeepotttttt...@yahoo.com>: This bug concerns the pdeps script, <python directory>\Tools\Scripts\pdeps.py. This script opens a list of files and extracts a list of their inter-dependencies.
I'm running Python 3.1.1 on Windows XP, installed via binary installer, but have confirmed that the bug is present in the source distribution of Python 3.2 rc2, the newest code I know of. (In fact, the only difference between the pdeps.py files in each version was the shebang line, 3.2 rc2 shebang line: "#! /usr/bin/env python3", 3.1.1 shebang line: "#! /usr/bin/env python".) When I tried out the module I found a series of small bugs, basically typos, each of which caused the script to crash due to an unhandled exception. 1. The relevant section of the unmodified pdeps.py file ---- # Compiled regular expressions to search for import statements # m_import = re.compile('^[ \t]*from[ \t]+([^ \t]+)[ \t]+') m_from = re.compile('^[ \t]*import[ \t]+([^#]+)') # Collect data from one file # def process(filename, table): ... if m_import.match(line) >= 0: (a, b), (a1, b1) = m_import.regs[:2] elif m_from.match(line) >= 0: (a, b), (a1, b1) = m_from.regs[:2] ... The match method of a compiled regular expression returns an SREMatch object, so the conditionals must be changed. In addition, the regs data is a member of the match object itself, not the compiled expression object, so the right side of the assignments must also be changed. modified version ---- ... import_match = m_import.match(line) from_match = m_from.match(line) if import_match: (a, b), (a1, b1) = import_match.regs[:2] elif from_match: (a, b), (a1, b1) = from_match.regs[:2] ... 2. unmodified ---- # Invert a table (this is again totally general). # All keys of the original table are made keys of the inverse, # so there may be empty lists in the inverse. # def inverse(table): inv = {} for key in table.keys(): if not inv.has_key(key): inv[key] = [] for item in table[key]: store(inv, item, key) return inv Dictionaries have no has_key method, though I vaguely recall that they used to. That's a quick fix though. modified ---- # Invert a table (this is again totally general). # All keys of the original table are made keys of the inverse, # so there may be empty lists in the inverse. # def inverse(table): inv = {} for key in table.keys(): if key in inv: inv[key] = [] for item in table[key]: store(inv, item, key) return inv output of fc, windows file comparing utility, run on the pdeps file from 3.2 rc2, and the modified pdeps file from 3.1.1 ---- >fc original-pdeps.py pdeps.py Comparing files original-pdeps.py and PDEPS.PY ***** original-pdeps.py #! /usr/bin/env python3 ***** PDEPS.PY #! /usr/bin/env python ***** ***** original-pdeps.py line = line[:-1] + nextline if m_import.match(line) >= 0: (a, b), (a1, b1) = m_import.regs[:2] elif m_from.match(line) >= 0: (a, b), (a1, b1) = m_from.regs[:2] else: continue ***** PDEPS.PY line = line[:-1] + nextline import_match = m_import.match(line) from_match = m_from.match(line) if import_match: (a, b), (a1, b1) = import_match.regs[:2] elif from_match: (a, b), (a1, b1) = from_match.regs[:2] else: continue ***** ***** original-pdeps.py for key in table.keys(): if not inv.has_key(key): inv[key] = [] ***** PDEPS.PY for key in table.keys(): if key in inv: inv[key] = [] ***** With these changes the pdep script works as expected. This is a pretty lower priority bug imho. It prevents anyone from using the script, but fixing the bug took about 5 minutes, and I doubt the pdeps script gets much use anyway. This bug is unlikely to inconvenience anyone. ---------- components: Demos and Tools messages: 127947 nosy: $$Coffeepot$$ priority: normal severity: normal status: open title: problem with packaged dependency extracter script, pdeps type: crash versions: Python 3.1, Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11123> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com