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 doesn't find methods of cython extension types #49

Open
jswhit opened this issue May 18, 2015 · 2 comments

Comments

Projects
None yet
1 participant
@jswhit
Copy link

commented May 18, 2015

Ran into this when trying to use pdoc to generate html docs from docstrings in my project (netcdf4-python). If you have a Cython extension type, for example

cdef class Shrubbery:
   """A class of Shrubbery"""
   cdef int width, height
   def __init__(self, w, h):
        self.width = w
        self.height = h
   def describe(self):
        """descibe the shubbery"""
        print "This shrubbery is", self.width, \
            "by", self.height, "cubits."

pdoc will generate the documentation for the class, and it's instance variables, but not it's methods. Is this a known issue? If so, are there workarounds?

@jswhit

This comment has been minimized.

Copy link
Author

commented May 18, 2015

To demonstrate, create a package Shrubbery with

setup.py
Shrubbery/init.py
Shrubbery/_Shrubbery.pyx

setup.py:

from distutils.core  import setup, Extension
from Cython.Build import cythonize
extensions = [Extension("Shubbery._Shrubbery",["Shrubbery/_Shrubbery.pyx"])]
ext_modules = cythonize(extensions)
setup(name = "Shrubbery",
  cmdclass = {},
  version = "0.0.1",
  long_description = "fake module",
  packages = ['Shrubbery'],
  ext_modules = ext_modules)

Shrubbery/init.py:

from ._Shrubbery import Shrubbery, __doc__
__all__ = ['Shrubbery']

Shrubbery/_Shrubbery.pyx:

"""
The Shrubbery Module
"""
cdef class Shrubbery:
   """A class of Shrubbery"""
   cdef int width, height
   def __init__(self, w, h):
        self.width = w
        self.height = h
   def describe(self):
        """descibe the shubbery"""
        print "This shrubbery is", self.width, \
            "by", self.height, "cubits."

After installation, pdoc Shrubbery produces:

Module Shrubbery
----------------
The Shrubbery Module

Classes
-------
Shrubbery
    A class of Shrubbery

    Ancestors (in MRO)
    ------------------
    Shrubbery.Shrubbery
    __builtin__.object

Note that the describe method is missing.

@jswhit

This comment has been minimized.

Copy link
Author

commented May 19, 2015

Here's my workaround, in case it helps

diff --git a/pdoc/__init__.py b/pdoc/__init__.py
index d0ec24f..9b7cfdb 100644
--- a/pdoc/__init__.py
+++ b/pdoc/__init__.py
@@ -570,7 +570,7 @@ class Module (Doc):
             # modules and module level variables.
             if inspect.isfunction(obj) or inspect.isbuiltin(obj):
                 self.doc[name] = Function(name, self, obj)
-            elif inspect.ismethod(obj):
+            elif inspect.ismethod(obj) or inspect.ismethoddescriptor(obj):
                 self.doc[name] = Function(name, self, obj)
             elif inspect.isclass(obj):
                 self.doc[name] = Class(name, self, obj)
@@ -912,6 +912,9 @@ class Class (Doc):
             if inspect.ismethod(obj):
                 self.doc[name] = Function(name, self.module, obj.__func__,
                                           cls=self, method=True)
+            elif inspect.ismethoddescriptor(obj):
+                self.doc[name] = Function(name, self.module, obj,
+                                          cls=self, method=False)
             elif inspect.isfunction(obj):
                self.doc[name] = Function(name, self.module, obj,
                                            cls=self, method=False)
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.