2525 included in the generated documentation. This option may appear
2626 any number of times to skip multiple objects.
2727
28+ * ``:include: str``
29+ This option is the opposite of :skip: -- if specified, only the object
30+ names that match any of the names passed to :include: will be included
31+ in the generated documentation. This option may appear multiple times
32+ to include multiple objects.
33+
2834 * ``:no-main-docstr:``
2935 If present, the docstring for the module/package will not be generated.
3036 The function and class tables will still be used, however.
@@ -232,6 +238,7 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
232238
233239 # initialize default options
234240 toskip = []
241+ includes = []
235242 inhdiag = app .config .automodapi_inheritance_diagram
236243 maindocstr = True
237244 top_head = True
@@ -245,6 +252,8 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
245252 for opname , args in _automodapiargsrex .findall (spl [grp * 3 + 2 ]):
246253 if opname == 'skip' :
247254 toskip .append (args .strip ())
255+ elif opname == 'include' :
256+ includes .append (args .strip ())
248257 elif opname == 'inheritance-diagram' :
249258 inhdiag = True
250259 elif opname == 'no-inheritance-diagram' :
@@ -290,8 +299,8 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
290299 if warnings :
291300 logger .warning (msg , location )
292301
293- ispkg , hascls , hasfuncs , hasother = _mod_info (
294- modnm , toskip , onlylocals = onlylocals )
302+ ispkg , hascls , hasfuncs , hasother , toskip = _mod_info (
303+ modnm , toskip , includes , onlylocals = onlylocals )
295304
296305 # add automodule directive only if no-main-docstr isn't present
297306 if maindocstr :
@@ -394,16 +403,20 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
394403 return sourcestr
395404
396405
397- def _mod_info (modname , toskip = [], onlylocals = True ):
406+ def _mod_info (modname , toskip = [], include = [], onlylocals = True ):
398407 """
399408 Determines if a module is a module or a package and whether or not
400409 it has classes or functions.
401410 """
402411
403412 hascls = hasfunc = hasother = False
404413
414+ skips = []
405415 for localnm , fqnm , obj in zip (* find_mod_objs (modname , onlylocals = onlylocals )):
406- if localnm not in toskip :
416+ if localnm in toskip or (include and localnm not in include ):
417+ skips .append (localnm )
418+
419+ else :
407420 hascls = hascls or inspect .isclass (obj )
408421 hasfunc = hasfunc or inspect .isroutine (obj )
409422 hasother = hasother or (not inspect .isclass (obj ) and
@@ -418,7 +431,7 @@ def _mod_info(modname, toskip=[], onlylocals=True):
418431 ispkg = (hasattr (pkg , '__file__' ) and isinstance (pkg .__file__ , str ) and
419432 os .path .split (pkg .__file__ )[1 ].startswith ('__init__.py' ))
420433
421- return ispkg , hascls , hasfunc , hasother
434+ return ispkg , hascls , hasfunc , hasother , skips
422435
423436
424437def process_automodapi (app , docname , source ):
0 commit comments