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

pdoc fails to run if any module uses zipimporter #7

Closed
mstetson opened this issue Apr 29, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@mstetson
Copy link

commented Apr 29, 2014

This is what I get trying to run pdoc –http on Mac OS X Lion:

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 639, in __init__
    self.handle()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 337, in handle
    self.handle_one_request()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 325, in handle_one_request
    method()
  File "/usr/local/bin/pdoc", line 100, in do_GET
    modules.append((name, quick_desc(imp, name, ispkg)))
  File "/usr/local/bin/pdoc", line 253, in quick_desc
    fp = path.join(imp.path, name, '__init__.py')
AttributeError: 'zipimport.zipimporter' object has no attribute 'path'

This is caused by quick_desc assuming the importer has a path attribute. The zipimporter doesn't. The function should be rewritten to use get_source() (see importlib.abc.InspectLoader). As a temporary workaround, I changed the quick_desc function to start like this:

def quick_desc(imp, name, ispkg):
    if not hasattr(imp, "path"):
        return ''

That won't get a description for zipped modules, but at least they don't halt the program altogether.

@BurntSushi

This comment has been minimized.

Copy link
Contributor

commented May 10, 2014

Nice find. I've put a bandaide on it with your suggestion for the time being. I've pushed out a new release of pdoc.

The function should be rewritten to use get_source() (see importlib.abc.InspectLoader).

It looks like this is only available in Python 3. I've added #9 for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.