Skip to content

Commit

Permalink
Update docs version (#154)
Browse files Browse the repository at this point in the history
* No need for heading of attrs/methods

* sphinx book theme version

* add path to docs in conf

* drop autodoc typehints

* use sphinx ext autodoc

* add python to intersphinx mapping

* Back to sphinx_autodoc_typehints

* black

* restore conf.py

---------

Co-authored-by: Philipp A <[email protected]>
  • Loading branch information
adamgayoso and flying-sheep authored Mar 7, 2023
1 parent 81157a8 commit f44f5ee
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ Attributes

{% for item in attributes %}

{{ item }}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoattribute:: {{ [objname, item] | join(".") }}
{%- endfor %}

Expand All @@ -56,9 +53,6 @@ Methods
{% for item in methods %}
{%- if item != '__init__' %}

{{ item }}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automethod:: {{ [objname, item] | join(".") }}
{%- endif -%}
{%- endfor %}
Expand Down
2 changes: 2 additions & 0 deletions {{cookiecutter.project_name}}/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
}

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"anndata": ("https://anndata.readthedocs.io/en/stable/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
}
Expand All @@ -109,6 +110,7 @@
html_theme_options = {
"repository_url": repository_url,
"use_repository_button": True,
"path_to_docs": "docs/",
}

pygments_style = "default"
Expand Down
17 changes: 10 additions & 7 deletions {{cookiecutter.project_name}}/docs/extensions/typed_returns.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# code from https://github.com/theislab/scanpy/blob/master/docs/extensions/typed_returns.py
# with some minor adjustment
from __future__ import annotations

import re
from collections.abc import Generator, Iterable

from sphinx.application import Sphinx
from sphinx.ext.napoleon import NumpyDocstring


def _process_return(lines):
def _process_return(lines: Iterable[str]) -> Generator[str, None, None]:
for line in lines:
m = re.fullmatch(r"(?P<param>\w+)\s+:\s+(?P<type>[\w.]+)", line)
if m:
# Once this is in scanpydoc, we can use the fancy hover stuff
if m := re.fullmatch(r"(?P<param>\w+)\s+:\s+(?P<type>[\w.]+)", line):
yield f'-{m["param"]} (:class:`~{m["type"]}`)'
else:
yield line


def _parse_returns_section(self, section):
lines_raw = list(_process_return(self._dedent(self._consume_to_next_section())))
lines = self._format_block(":returns: ", lines_raw)
def _parse_returns_section(self: NumpyDocstring, section: str) -> list[str]:
lines_raw = self._dedent(self._consume_to_next_section())
if lines_raw[0] == ":":
del lines_raw[0]
lines = self._format_block(":returns: ", list(_process_return(lines_raw)))
if lines and lines[-1]:
lines.append("")
return lines
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dev = [
]
doc = [
"sphinx>=4",
"sphinx-book-theme>=0.3.3",
"sphinx-book-theme>=1.0.0",
"myst-nb",
"sphinxcontrib-bibtex>=1.0.0",
"sphinx-autodoc-typehints",
Expand Down

0 comments on commit f44f5ee

Please sign in to comment.