|
20 | 20 | import sys
|
21 | 21 | from contextlib import suppress
|
22 | 22 |
|
23 |
| -# --------- autosummary templates ------------------ |
24 |
| -# TODO: eventually replace this with a sphinx.ext.auto_accessor module |
25 |
| -import sphinx |
26 |
| -from sphinx.ext.autodoc import AttributeDocumenter, Documenter, MethodDocumenter |
27 |
| -from sphinx.util import rpartition |
| 23 | +import sphinx_autosummary_accessors |
28 | 24 |
|
29 | 25 | # make sure the source version is preferred (#3567)
|
30 | 26 | root = pathlib.Path(__file__).absolute().parent.parent
|
|
53 | 49 | matplotlib.use("Agg")
|
54 | 50 |
|
55 | 51 | try:
|
56 |
| - import rasterio |
| 52 | + import rasterio # noqa: F401 |
57 | 53 | except ImportError:
|
58 | 54 | allowed_failures.update(
|
59 | 55 | ["gallery/plot_rasterio_rgb.py", "gallery/plot_rasterio.py"]
|
60 | 56 | )
|
61 | 57 |
|
62 | 58 | try:
|
63 |
| - import cartopy |
| 59 | + import cartopy # noqa: F401 |
64 | 60 | except ImportError:
|
65 | 61 | allowed_failures.update(
|
66 | 62 | [
|
|
88 | 84 | "IPython.sphinxext.ipython_directive",
|
89 | 85 | "IPython.sphinxext.ipython_console_highlighting",
|
90 | 86 | "nbsphinx",
|
| 87 | + "sphinx_autosummary_accessors", |
91 | 88 | ]
|
92 | 89 |
|
93 | 90 | extlinks = {
|
|
116 | 113 | numpydoc_show_class_members = False
|
117 | 114 |
|
118 | 115 | # Add any paths that contain templates here, relative to this directory.
|
119 |
| -templates_path = ["_templates"] |
| 116 | +templates_path = ["_templates", sphinx_autosummary_accessors.templates_path] |
120 | 117 |
|
121 | 118 | # The suffix of source filenames.
|
122 | 119 | source_suffix = ".rst"
|
|
275 | 272 |
|
276 | 273 | # -- Options for LaTeX output ---------------------------------------------
|
277 | 274 |
|
278 |
| -latex_elements = { |
279 |
| - # The paper size ('letterpaper' or 'a4paper'). |
280 |
| - # 'papersize': 'letterpaper', |
281 |
| - # The font size ('10pt', '11pt' or '12pt'). |
282 |
| - # 'pointsize': '10pt', |
283 |
| - # Additional stuff for the LaTeX preamble. |
284 |
| - # 'preamble': '', |
285 |
| -} |
| 275 | +# latex_elements = { |
| 276 | +# # The paper size ('letterpaper' or 'a4paper'). |
| 277 | +# # 'papersize': 'letterpaper', |
| 278 | +# # The font size ('10pt', '11pt' or '12pt'). |
| 279 | +# # 'pointsize': '10pt', |
| 280 | +# # Additional stuff for the LaTeX preamble. |
| 281 | +# # 'preamble': '', |
| 282 | +# } |
286 | 283 |
|
287 | 284 | # Grouping the document tree into LaTeX files. List of tuples
|
288 | 285 | # (source start file, target name, title,
|
|
364 | 361 | "dask": ("https://docs.dask.org/en/latest", None),
|
365 | 362 | "cftime": ("https://unidata.github.io/cftime", None),
|
366 | 363 | }
|
367 |
| - |
368 |
| - |
369 |
| -# --------- autosummary templates ------------------ |
370 |
| -# TODO: eventually replace this with a sphinx.ext.auto_accessor module |
371 |
| -class AccessorDocumenter(MethodDocumenter): |
372 |
| - """ |
373 |
| - Specialized Documenter subclass for accessors. |
374 |
| - """ |
375 |
| - |
376 |
| - objtype = "accessor" |
377 |
| - directivetype = "method" |
378 |
| - |
379 |
| - # lower than MethodDocumenter so this is not chosen for normal methods |
380 |
| - priority = 0.6 |
381 |
| - |
382 |
| - def format_signature(self): |
383 |
| - # this method gives an error/warning for the accessors, therefore |
384 |
| - # overriding it (accessor has no arguments) |
385 |
| - return "" |
386 |
| - |
387 |
| - |
388 |
| -class AccessorLevelDocumenter(Documenter): |
389 |
| - """ |
390 |
| - Specialized Documenter subclass for objects on accessor level (methods, |
391 |
| - attributes). |
392 |
| - """ |
393 |
| - |
394 |
| - # This is the simple straightforward version |
395 |
| - # modname is None, base the last elements (eg 'hour') |
396 |
| - # and path the part before (eg 'Series.dt') |
397 |
| - # def resolve_name(self, modname, parents, path, base): |
398 |
| - # modname = 'pandas' |
399 |
| - # mod_cls = path.rstrip('.') |
400 |
| - # mod_cls = mod_cls.split('.') |
401 |
| - # |
402 |
| - # return modname, mod_cls + [base] |
403 |
| - |
404 |
| - def resolve_name(self, modname, parents, path, base): |
405 |
| - if modname is None: |
406 |
| - if path: |
407 |
| - mod_cls = path.rstrip(".") |
408 |
| - else: |
409 |
| - mod_cls = None |
410 |
| - # if documenting a class-level object without path, |
411 |
| - # there must be a current class, either from a parent |
412 |
| - # auto directive ... |
413 |
| - mod_cls = self.env.temp_data.get("autodoc:class") |
414 |
| - # ... or from a class directive |
415 |
| - if mod_cls is None: |
416 |
| - mod_cls = self.env.temp_data.get("py:class") |
417 |
| - # ... if still None, there's no way to know |
418 |
| - if mod_cls is None: |
419 |
| - return None, [] |
420 |
| - # HACK: this is added in comparison to ClassLevelDocumenter |
421 |
| - # mod_cls still exists of class.accessor, so an extra |
422 |
| - # rpartition is needed |
423 |
| - modname, accessor = rpartition(mod_cls, ".") |
424 |
| - modname, cls = rpartition(modname, ".") |
425 |
| - parents = [cls, accessor] |
426 |
| - # if the module name is still missing, get it like above |
427 |
| - if not modname: |
428 |
| - modname = self.env.temp_data.get("autodoc:module") |
429 |
| - if not modname: |
430 |
| - if sphinx.__version__ > "1.3": |
431 |
| - modname = self.env.ref_context.get("py:module") |
432 |
| - else: |
433 |
| - modname = self.env.temp_data.get("py:module") |
434 |
| - # ... else, it stays None, which means invalid |
435 |
| - return modname, parents + [base] |
436 |
| - |
437 |
| - |
438 |
| -class AccessorAttributeDocumenter(AccessorLevelDocumenter, AttributeDocumenter): |
439 |
| - |
440 |
| - objtype = "accessorattribute" |
441 |
| - directivetype = "attribute" |
442 |
| - |
443 |
| - # lower than AttributeDocumenter so this is not chosen for normal attributes |
444 |
| - priority = 0.6 |
445 |
| - |
446 |
| - |
447 |
| -class AccessorMethodDocumenter(AccessorLevelDocumenter, MethodDocumenter): |
448 |
| - |
449 |
| - objtype = "accessormethod" |
450 |
| - directivetype = "method" |
451 |
| - |
452 |
| - # lower than MethodDocumenter so this is not chosen for normal methods |
453 |
| - priority = 0.6 |
454 |
| - |
455 |
| - |
456 |
| -class AccessorCallableDocumenter(AccessorLevelDocumenter, MethodDocumenter): |
457 |
| - """ |
458 |
| - This documenter lets us removes .__call__ from the method signature for |
459 |
| - callable accessors like Series.plot |
460 |
| - """ |
461 |
| - |
462 |
| - objtype = "accessorcallable" |
463 |
| - directivetype = "method" |
464 |
| - |
465 |
| - # lower than MethodDocumenter; otherwise the doc build prints warnings |
466 |
| - priority = 0.5 |
467 |
| - |
468 |
| - def format_name(self): |
469 |
| - return MethodDocumenter.format_name(self).rstrip(".__call__") |
470 |
| - |
471 |
| - |
472 |
| -def setup(app): |
473 |
| - app.add_autodocumenter(AccessorDocumenter) |
474 |
| - app.add_autodocumenter(AccessorAttributeDocumenter) |
475 |
| - app.add_autodocumenter(AccessorMethodDocumenter) |
476 |
| - app.add_autodocumenter(AccessorCallableDocumenter) |
0 commit comments