This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: problem with packaged dependency extracter script, pdeps
Type: behavior Stage: resolved
Components: Demos and Tools Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder: pdeps.py has_key
View: 14492
Assigned To: Nosy List: $$Coffeepot$$, amaury.forgeotdarc, cheryl.sabella, eric.araujo
Priority: normal Keywords: patch

Created on 2011-02-04 22:41 by $$Coffeepot$$, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pdeps.patch amaury.forgeotdarc, 2011-02-04 23:12 review
Messages (4)
msg127947 - (view) Author: ($$Coffeepot$$) Date: 2011-02-04 22:41
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.
msg127949 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-02-04 23:12
This script is indeed unusable. Here is a proper patch file, tested by running it on a few files.
msg139886 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-07-05 16:02
Looks good.  I suggest you test again and commit.
msg308058 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2017-12-11 16:43
This issue was resolved with the patch in #14492.
History
Date User Action Args
2022-04-11 14:57:12adminsetgithub: 55332
2017-12-11 16:43:09cheryl.sabellasetstatus: open -> closed

superseder: pdeps.py has_key

nosy: + cheryl.sabella
messages: + msg308058
resolution: duplicate
stage: patch review -> resolved
2011-07-05 16:02:48eric.araujosetversions: + Python 3.3, - Python 3.1
nosy: + eric.araujo

messages: + msg139886

type: crash -> behavior
stage: patch review
2011-02-04 23:12:01amaury.forgeotdarcsetfiles: + pdeps.patch

nosy: + amaury.forgeotdarc
messages: + msg127949

keywords: + patch
2011-02-04 22:41:18$$Coffeepot$$create