Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydoc info for a package doesn't list all package contents #44328

Closed
ngrover mannequin opened this issue Dec 11, 2006 · 3 comments
Closed

pydoc info for a package doesn't list all package contents #44328

ngrover mannequin opened this issue Dec 11, 2006 · 3 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ngrover
Copy link
Mannequin

ngrover mannequin commented Dec 11, 2006

BPO 1613479
Nosy @merwok
Files
  • pydoc.py
  • 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:

    assignee = None
    closed_at = <Date 2011-02-04.00:03:51.793>
    created_at = <Date 2006-12-11.20:40:12.000>
    labels = ['type-bug', 'library']
    title = "pydoc info for a package doesn't list all package contents"
    updated_at = <Date 2011-02-04.00:03:51.791>
    user = 'https://bugs.python.org/ngrover'

    bugs.python.org fields:

    activity = <Date 2011-02-04.00:03:51.791>
    actor = 'eric.araujo'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-02-04.00:03:51.793>
    closer = 'eric.araujo'
    components = ['Library (Lib)']
    creation = <Date 2006-12-11.20:40:12.000>
    creator = 'ngrover'
    dependencies = []
    files = ['2252']
    hgrepos = []
    issue_num = 1613479
    keywords = ['patch']
    message_count = 3.0
    messages = ['30787', '109838', '127831']
    nosy_count = 2.0
    nosy_names = ['ngrover', 'eric.araujo']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1613479'
    versions = []

    @ngrover
    Copy link
    Mannequin Author

    ngrover mannequin commented Dec 11, 2006

    When using pydoc to query a package, a "PACKAGE CONTENTS" list is provided to show the modules and packages that are in that package. That list will be incomplete if we are querying a package that has been split across multiple directories.

    Suppose you have the following:

    /first/path/foo/init.py
    /first/path/foo/one.py
    /second/path/foo/init.py
    /second/path/foo/two.py

    and sys.path includes /first/path/ and /second/path/. If both of the foo/init.py files are empty, then "import foo" will only allow you to import modules from one of those two foo/ directories (whichever is found first in sys.path). However, if we add the following to both foo/init.py files, then we can import foo.one and foo.two because "foo" is considered to be a single package split across two directories:

    from pkgutil import extend_path
    __path__ = extend_path(__path__, __name__)

    Please see http://www.python.org/doc/2.4.2/lib/module-pkgutil.html for some related information.

    On line 1052 of pydoc.py, we have the following:

    for file in os.listdir(object.__path__[0]):

    and in that loop we only read the contents of the FIRST directory in the package's __path__. That should be updated to read the contents of ALL directories in the package's __path__. The following change will do that:

    % diff -w pydoc.py pydoc.py.orig
    1052,1054c1052,1053
    < for objectDir in object.__path__:
    < for file in os.listdir(objectDir):
    < path = os.path.join(objectDir, file)
    ---

            for file in os.listdir(object.\_\_path__[0]):
                path = os.path.join(object.\_\_path__[0], file)
    

    I've attached that updated pydoc.py file to this submission. Please consider that as a replacement for the existing pydoc.py module that's currently being distributed.

    @ngrover ngrover mannequin added stdlib Python modules in the Lib dir labels Dec 11, 2006
    @devdanzin devdanzin mannequin added type-feature A feature request or enhancement labels Mar 30, 2009
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 10, 2010

    Surely this is a bug?

    @BreamoreBoy BreamoreBoy mannequin added type-bug An unexpected behavior, bug, or error and removed type-feature A feature request or enhancement labels Jul 10, 2010
    @merwok
    Copy link
    Member

    merwok commented Feb 4, 2011

    I’ve just tested that the behavior is now correct. I reproduced the tree structure, set PYTHONPATH, ran “pydoc foo” to get only “one” listed, added the pkgutil call in first/path/foo/init.py, re-ran “pydoc foo”, got “one” and “two” listed. I can also import both submodules.

    The pydoc code now uses pkgutil.iter_modules. Someone must have fixed that before 2.6, closing. Thanks for the report nonetheless!

    @merwok merwok closed this as completed Feb 4, 2011
    @merwok merwok closed this as completed Feb 4, 2011
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant