From 01bca4a09efb13f376ec347c5b0a8764a0268c54 Mon Sep 17 00:00:00 2001 From: Casper van Elteren Date: Mon, 5 Oct 2026 16:29:12 +1000 Subject: [PATCH 01/10] Fix build-time docstring normalization --- tools/expand_docstrings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/expand_docstrings.py b/tools/expand_docstrings.py index 980d96c5d..b9e6a0423 100644 --- a/tools/expand_docstrings.py +++ b/tools/expand_docstrings.py @@ -4,6 +4,7 @@ import ast import importlib +import inspect import re import sys from pathlib import Path @@ -62,12 +63,12 @@ def _rewrite_file(path: Path, package_root: Path, snippets) -> int: if not literals: return 0 - expanded = [_expand(node.value, snippets) for node in literals] + expanded = [_expand(inspect.cleandoc(node.value), snippets) for node in literals] if any(missing for _, missing in expanded): # Some registries live in the module containing the documented object, # so import only when a key cannot be resolved from the central registry. importlib.import_module(_module_name(package_root, path)) - expanded = [_expand(node.value, snippets) for node in literals] + expanded = [_expand(inspect.cleandoc(node.value), snippets) for node in literals] lines = source.splitlines(keepends=True) offsets = [] From d06d9a54f1fbeb3bde1a663ecacd965ebeff9bd9 Mon Sep 17 00:00:00 2001 From: Casper van Elteren Date: Mon, 5 Oct 2026 16:29:25 +1000 Subject: [PATCH 02/10] Correct subplot C/F ordering documentation --- ultraplot/figure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ultraplot/figure.py b/ultraplot/figure.py index f4ccc5c01..d877b72ee 100644 --- a/ultraplot/figure.py +++ b/ultraplot/figure.py @@ -232,7 +232,7 @@ def _any_not_none(*values): The number of rows and columns in the subplot grid. Ignored if `array` was passed. Use these arguments for simple subplot grids. order : {'C', 'F'}, default: 'C' - Whether subplots are numbered in column-major (``'C'``) or row-major (``'F'``) + Whether subplots are numbered in row-major (``'C'``) or column-major (``'F'``) order. Analogous to `numpy.array` ordering. This controls the order that subplots appear in the `SubplotGrid` returned by this function, and the order of subplot a-b-c labels (see `~ultraplot.axes.Axes.format`). From 755ee484209a8caebeba14f272af4690cc4a151d Mon Sep 17 00:00:00 2001 From: Casper van Elteren Date: Mon, 5 Oct 2026 16:29:29 +1000 Subject: [PATCH 03/10] Fix projection parameter docstring syntax --- ultraplot/axes/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ultraplot/axes/base.py b/ultraplot/axes/base.py index d73558897..5aea24ca1 100644 --- a/ultraplot/axes/base.py +++ b/ultraplot/axes/base.py @@ -89,8 +89,7 @@ # Projection docstring _proj_docstring = """ -projection : -str, `cartopy.crs.Projection`, or `~mpl_toolkits.basemap.Basemap`, optional +projection : str, `cartopy.crs.Projection`, or `~mpl_toolkits.basemap.Basemap`, optional The map projection specification(s). If ``'cart'`` or ``'cartesian'`` (the default), a :class:`~ultraplot.axes.CartesianAxes` is created. If ``'polar'``, a :class:`~ultraplot.axes.PolarAxes` is created. Otherwise, the argument is From 93b7b3a6235c37cea1d404e771384e39294a019d Mon Sep 17 00:00:00 2001 From: Casper van Elteren Date: Mon, 5 Oct 2026 16:29:53 +1000 Subject: [PATCH 04/10] Add docstring regression tests --- ultraplot/tests/test_docstrings.py | 67 ++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 ultraplot/tests/test_docstrings.py diff --git a/ultraplot/tests/test_docstrings.py b/ultraplot/tests/test_docstrings.py new file mode 100644 index 000000000..272b75311 --- /dev/null +++ b/ultraplot/tests/test_docstrings.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +"""Tests for shared and build-time materialized docstrings.""" + +import inspect +import runpy +from pathlib import Path + +import ultraplot as uplt + + +def _load_docstring_expander(): + path = Path(__file__).resolve().parents[2] / "tools" / "expand_docstrings.py" + return runpy.run_path(str(path)) + + +def test_build_docstring_expansion_preserves_numpy_indentation(tmp_path): + """Build-time expansion should match runtime normalize-before-substitute semantics.""" + rewrite_file = _load_docstring_expander()["_rewrite_file"] + package_root = tmp_path / "pkg" + package_root.mkdir() + path = package_root / "example.py" + path.write_text( + 'def example():\n' + ' """Summary.\n' + "\n" + " Parameters\n" + " ----------\n" + " %(params)s\n" + ' """\n' + ) + snippets = { + "params": ( + "first : int\n" + " First value.\n" + "second : str\n" + " Second value." + ) + } + + assert rewrite_file(path, package_root, snippets) == 1 + + namespace = {} + exec(compile(path.read_text(), str(path), "exec"), namespace) + assert inspect.getdoc(namespace["example"]) == ( + "Summary.\n" + "\n" + "Parameters\n" + "----------\n" + "first : int\n" + " First value.\n" + "second : str\n" + " Second value." + ) + + +def test_subplots_parameter_docstrings_are_numpy_style(): + """Shared subplot parameter snippets should render as valid NumPy-style entries.""" + doc = inspect.getdoc(uplt.subplots) or "" + assert ( + "projection : str, `cartopy.crs.Projection`, " + "or `~mpl_toolkits.basemap.Basemap`, optional" + ) in doc + assert "\nprojection :\n" not in doc + assert ( + "Whether subplots are numbered in row-major (``'C'``) " + "or column-major (``'F'``)" + ) in doc From 6e83000632b5f23a7a1ab77ca652abff6f271196 Mon Sep 17 00:00:00 2001 From: Casper van Elteren Date: Mon, 5 Oct 2026 16:46:30 +1000 Subject: [PATCH 05/10] Apply Black formatting --- ultraplot/tests/test_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ultraplot/tests/test_docstrings.py b/ultraplot/tests/test_docstrings.py index 272b75311..97231199c 100644 --- a/ultraplot/tests/test_docstrings.py +++ b/ultraplot/tests/test_docstrings.py @@ -20,7 +20,7 @@ def test_build_docstring_expansion_preserves_numpy_indentation(tmp_path): package_root.mkdir() path = package_root / "example.py" path.write_text( - 'def example():\n' + "def example():\n" ' """Summary.\n' "\n" " Parameters\n" From cb6dda83b9c763039fe42bbcac92a8cbc459c38b Mon Sep 17 00:00:00 2001 From: Casper van Elteren Date: Mon, 5 Oct 2026 17:11:13 +1000 Subject: [PATCH 06/10] Fix Black workflow staging --- .github/workflows/black.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index a6ef14289..1aeb912c8 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -45,6 +45,6 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add --update -- '*.py' '*.pyi' + git add -u git commit -m "Apply Black formatting" git push From 191c0334070daad82f2097d8255e6e17b1070895 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2026 07:11:36 +0000 Subject: [PATCH 07/10] Apply Black formatting --- ultraplot/tests/test_docstrings.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ultraplot/tests/test_docstrings.py b/ultraplot/tests/test_docstrings.py index 97231199c..8d9856c2a 100644 --- a/ultraplot/tests/test_docstrings.py +++ b/ultraplot/tests/test_docstrings.py @@ -30,10 +30,7 @@ def test_build_docstring_expansion_preserves_numpy_indentation(tmp_path): ) snippets = { "params": ( - "first : int\n" - " First value.\n" - "second : str\n" - " Second value." + "first : int\n" " First value.\n" "second : str\n" " Second value." ) } From b1c12cece5d6763d3698ef3ef8ab552dfd7aab34 Mon Sep 17 00:00:00 2001 From: Casper van Elteren Date: Mon, 5 Oct 2026 17:12:06 +1000 Subject: [PATCH 08/10] Trigger Black formatting --- ultraplot/tests/test_docstrings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ultraplot/tests/test_docstrings.py b/ultraplot/tests/test_docstrings.py index 8d9856c2a..4fdc8c487 100644 --- a/ultraplot/tests/test_docstrings.py +++ b/ultraplot/tests/test_docstrings.py @@ -62,3 +62,4 @@ def test_subplots_parameter_docstrings_are_numpy_style(): "Whether subplots are numbered in row-major (``'C'``) " "or column-major (``'F'``)" ) in doc + From 382041f00da6a3a2d32451e2fcf0d248d2253f02 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2026 07:12:26 +0000 Subject: [PATCH 09/10] Apply Black formatting --- ultraplot/tests/test_docstrings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ultraplot/tests/test_docstrings.py b/ultraplot/tests/test_docstrings.py index 4fdc8c487..8d9856c2a 100644 --- a/ultraplot/tests/test_docstrings.py +++ b/ultraplot/tests/test_docstrings.py @@ -62,4 +62,3 @@ def test_subplots_parameter_docstrings_are_numpy_style(): "Whether subplots are numbered in row-major (``'C'``) " "or column-major (``'F'``)" ) in doc - From 54a366b7fa35eade6f461743ddac1f7df73bd739 Mon Sep 17 00:00:00 2001 From: Casper van Elteren Date: Mon, 5 Oct 2026 17:12:51 +1000 Subject: [PATCH 10/10] Revert temporary Black workflow staging fix --- .github/workflows/black.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 1aeb912c8..a6ef14289 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -45,6 +45,6 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add -u + git add --update -- '*.py' '*.pyi' git commit -m "Apply Black formatting" git push