Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
.. |pypi| image:: https://img.shields.io/pypi/v/fast-array-utils
:target: https://pypi.org/project/fast-array-utils/

.. |docs| image:: https://app.readthedocs.org/projects/icb-fast-array-utils/badge/
:target: https://fast-array-utils.readthedocs.io/
.. |docs| image:: https://app.readthedocs.org/projects/fast-array-utils/badge/
:target: https://fast-array-utils.scverse.org/

.. |ci| image:: https://github.com/scverse/fast-array-utils/actions/workflows/ci.yml/badge.svg
:target: https://github.com/scverse/fast-array-utils/actions/workflows/ci.yml
Expand Down
130 changes: 14 additions & 116 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,145 +5,43 @@

from datetime import UTC, datetime
from importlib.metadata import metadata
from pathlib import Path
from typing import TYPE_CHECKING

from docutils.nodes import Text
from sphinx.util import logging
from scverse_doc.registry import intersphinx


if TYPE_CHECKING:
from typing import Final

from docutils.nodes import TextElement, reference
from sphinx.addnodes import pending_xref
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment


HERE: Final = Path(__file__).parent
LOGGER: Final = logging.getLogger("fast_array_utils")


# -- General configuration ------------------------------------------------


# General information
project = "fast-array-utils"
meta = metadata(project)
author = meta["author-email"].split('"')[1]
copyright = f"{datetime.now(tz=UTC):%Y}, {author}." # noqa: A001
version = meta["version"]
release = version

# default settings
master_doc = "index"
extensions = [
"sphinx.ext.intersphinx",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinx_autofixture",
]
extensions = ["scverse_doc", "sphinx_autofixture"]
source_repository = "https://github.com/scverse/fast-array-utils"

# API documentation when building
nitpicky = True
autosummary_generate = True
autodoc_member_order = "bysource"
autodoc_default_options = {
"special-members": True,
# everything except __call__ really, to avoid having to write autosummary templates
"exclude-members": "__setattr__,__delattr__,__repr__,__eq__,__or__,__ror__,__hash__,__weakref__,__init__,__new__",
}
napoleon_google_docstring = False
napoleon_numpy_docstring = True
todo_include_todos = False
intersphinx_mapping = dict(
anndata=("https://anndata.scverse.org/en/stable/", None),
intersphinx_mapping = intersphinx() | dict(
cupy=("https://docs.cupy.dev/en/stable/", None),
dask=("https://docs.dask.org/en/stable/", None),
h5py=("https://docs.h5py.org/en/stable/", None),
numba=("https://numba.readthedocs.io/en/stable/", None),
numpy=("https://numpy.org/doc/stable/", None),
pytest=("https://docs.pytest.org/en/stable/", None),
python=("https://docs.python.org/3", None),
scipy=("https://docs.scipy.org/doc/scipy/", None),
zarr=("https://zarr.readthedocs.io/en/stable/", None),
)
xref_overrides = {
"numpy._typing._array_like.NDArray": ("py:data", "numpy.typing.NDArray"),
"numpy._typing._dtype_like.DTypeLike": ("py:data", "numpy.typing.DTypeLike"),
"DTypeLike": ("py:data", "numpy.typing.DTypeLike"),
"ArrayLike": ("py:data", "numpy.typing.ArrayLike"),
"numpy.float64": ("py:attr", "numpy.float64"),
"np.floating": "numpy.floating",
"np.random.Generator": "numpy.random.Generator",
}
nitpick_ignore = [
("py:class", "P"),
("py:class", "R"),
("py:class", "Arr"),
("py:class", "Array"),
("py:class", "ToDType"),
("py:class", "testing.fast_array_utils._array_type.Arr"),
("py:class", "testing.fast_array_utils._array_type.Inner"),
("py:class", "_DTypeLikeNum"),
("py:class", name) for name in ["A", "P", "R", "Arr", "Array", "Inner", "ToDType", "_DTypeLikeNum", "testing.fast_array_utils._array_type._DTypeLikeNum"]
]

# Options for HTML output
html_theme = "furo"
html_theme_options = dict(
source_repository="https://github.com/scverse/fast-array-utils/",
source_branch="main",
source_directory="docs/",
)

_np_nocls = {"float64": "attr"}
_optional_types = {
"CupyArray": "cupy.ndarray",
"CupySpMatrix": "cupyx.scipy.sparse.spmatrix",
"sparray": "scipy.sparse.sparray",
"spmatrix": "scipy.sparse.spmatrix",
"DaskArray": "dask.array.Array",
"H5Dataset": "h5py.Dataset",
"ZarrArray": "zarr.Array",
}


def find_type_alias(name: str) -> tuple[str, str, str | None] | tuple[None, None, None]:
"""Find a type alias."""
import numpy.typing as npt

from fast_array_utils import types, typing

if name in typing.__all__:
return "data", f"fast_array_utils.typing.{name}", None
if name.startswith("types.") and name[6:] in {*types.__all__, *_optional_types}:
if path := _optional_types.get(name[6:]):
return "class", path, None
return "data", f"fast_array_utils.{name}", None
if name.startswith("np."):
name = name.removeprefix("np.")
return _np_nocls.get(name, "class"), f"numpy.{name}", f"np.{name}"
if name in npt.__all__:
return "data", f"numpy.typing.{name}", None
return None, None, None


def resolve_type_aliases(app: Sphinx, env: BuildEnvironment, node: pending_xref, contnode: TextElement) -> reference | None:
"""Resolve :class: references to our type aliases as :attr: instead."""
if (node["refdomain"], node["reftype"]) != ("py", "class"):
return None
typ, target, name = find_type_alias(node["reftarget"])
if typ is None or target is None:
return None
if target.startswith("fast_array_utils."):
ref = env.get_domain("py").resolve_xref(env, node["refdoc"], app.builder, typ, target, node, contnode)
else:
from sphinx.ext.intersphinx import resolve_reference_any_inventory

node["reftype"] = typ
node["reftarget"] = target
ref = resolve_reference_any_inventory(env=env, honor_disabled_refs=False, node=node, contnode=contnode)
if ref is None:
msg = f"Could not resolve {typ} {target} (from {node['reftarget']})"
LOGGER.warning(msg, type="ref")
return ref
if name:
ref.children[:] = [Text(name)]
return ref


def setup(app: Sphinx) -> None: # noqa: D103
app.connect("missing-reference", resolve_type_aliases, priority=800)
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ optional-dependencies.sparse = [ "scipy>=1.15" ]
optional-dependencies.testing = [ "packaging" ]
urls."Issue Tracker" = "https://github.com/scverse/fast-array-utils/issues"
urls."Source Code" = "https://github.com/scverse/fast-array-utils"
urls.Documentation = "https://icb-fast-array-utils.readthedocs-hosted.com/"
urls.Documentation = "https://fast-array-utils.scverse.org/"
entry-points.pytest11.fast_array_utils = "testing.fast_array_utils.pytest"

[dependency-groups]
Expand All @@ -46,8 +46,8 @@ test = [
{ include-group = "test-min" },
]
doc = [
"furo>=2024.8.6",
"pytest>=8.4",
"scverse-doc[full]>=0.5.1",
"sphinx>=9.0.1",
"sphinx-autofixture>=0.4.1",
]
Expand All @@ -64,7 +64,7 @@ typecheck = [
"cupy-stubs",
"mypy",
"scipy-stubs",
"sphinx",
"scverse-doc",
]

[tool.hatch]
Expand Down
Loading