Closed db75a273-8eee-440b-8904-6efc78875e47 closed 6 years ago
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
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.
This script is indeed unusable. Here is a proper patch file, tested by running it on a few files.
Looks good. I suggest you test again and commit.
This issue was resolved with the patch in bpo-14492.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at =
created_at =
labels = ['type-bug']
title = 'problem with packaged dependency extracter script, pdeps'
updated_at =
user = 'https://bugs.python.org/Coffeepot'
```
bugs.python.org fields:
```python
activity =
actor = 'cheryl.sabella'
assignee = 'none'
closed = True
closed_date =
closer = 'cheryl.sabella'
components = ['Demos and Tools']
creation =
creator = '$$Coffeepot$$'
dependencies = []
files = ['20681']
hgrepos = []
issue_num = 11123
keywords = ['patch']
message_count = 4.0
messages = ['127947', '127949', '139886', '308058']
nosy_count = 4.0
nosy_names = ['amaury.forgeotdarc', 'eric.araujo', '$$Coffeepot$$', 'cheryl.sabella']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = 'resolved'
status = 'closed'
superseder = '14492'
type = 'behavior'
url = 'https://bugs.python.org/issue11123'
versions = ['Python 3.2', 'Python 3.3']
```