MartinPdeS-docs 0.1.4__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MartinPdeS-docs
3
- Version: 0.1.4
3
+ Version: 0.2.0
4
4
  Summary: Shared Sphinx configuration for MartinPdeS scientific Python packages.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -39,3 +39,21 @@ globals().update(
39
39
 
40
40
  Project-specific values can be assigned below this call to override any
41
41
  shared default.
42
+
43
+ For a multi-section Sphinx-Gallery, pass the section names instead of
44
+ repeating the directory mappings:
45
+
46
+ ```python
47
+ globals().update(
48
+ configure(
49
+ project="FlowCyPy",
50
+ package="FlowCyPy",
51
+ repository="MartinPdeS/FlowCyPy",
52
+ gallery_sections=["tutorials", "studies", "validation"],
53
+ gallery_default_thumb="_static/gallery-default.png",
54
+ )
55
+ )
56
+ ```
57
+
58
+ Use `gallery_options` for project-specific Sphinx-Gallery settings such as an
59
+ additional image scraper or an example error policy.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MartinPdeS-docs
3
- Version: 0.1.4
3
+ Version: 0.2.0
4
4
  Summary: Shared Sphinx configuration for MartinPdeS scientific Python packages.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -39,3 +39,21 @@ globals().update(
39
39
 
40
40
  Project-specific values can be assigned below this call to override any
41
41
  shared default.
42
+
43
+ For a multi-section Sphinx-Gallery, pass the section names instead of
44
+ repeating the directory mappings:
45
+
46
+ ```python
47
+ globals().update(
48
+ configure(
49
+ project="FlowCyPy",
50
+ package="FlowCyPy",
51
+ repository="MartinPdeS/FlowCyPy",
52
+ gallery_sections=["tutorials", "studies", "validation"],
53
+ gallery_default_thumb="_static/gallery-default.png",
54
+ )
55
+ )
56
+ ```
57
+
58
+ Use `gallery_options` for project-specific Sphinx-Gallery settings such as an
59
+ additional image scraper or an example error policy.
@@ -27,3 +27,21 @@ globals().update(
27
27
 
28
28
  Project-specific values can be assigned below this call to override any
29
29
  shared default.
30
+
31
+ For a multi-section Sphinx-Gallery, pass the section names instead of
32
+ repeating the directory mappings:
33
+
34
+ ```python
35
+ globals().update(
36
+ configure(
37
+ project="FlowCyPy",
38
+ package="FlowCyPy",
39
+ repository="MartinPdeS/FlowCyPy",
40
+ gallery_sections=["tutorials", "studies", "validation"],
41
+ gallery_default_thumb="_static/gallery-default.png",
42
+ )
43
+ )
44
+ ```
45
+
46
+ Use `gallery_options` for project-specific Sphinx-Gallery settings such as an
47
+ additional image scraper or an example error policy.
@@ -1,6 +1,8 @@
1
1
  """Configurable defaults for the shared project documentation sites."""
2
2
 
3
3
  import os
4
+ from collections.abc import Mapping, Sequence
5
+ from importlib.metadata import PackageNotFoundError, version as distribution_version
4
6
  from pathlib import Path
5
7
 
6
8
 
@@ -18,6 +20,21 @@ def _raster_thumbnail_path(logo: str, favicon: str) -> str | None:
18
20
  return None
19
21
 
20
22
 
23
+ def _resolve_version(package: str, version: str | None) -> str:
24
+ """Resolve the documentation version without importing the package."""
25
+ if version is not None:
26
+ return version
27
+
28
+ environment_version = os.getenv("tag")
29
+ if environment_version:
30
+ return environment_version
31
+
32
+ try:
33
+ return distribution_version(package)
34
+ except PackageNotFoundError:
35
+ return "latest"
36
+
37
+
21
38
  def configure(
22
39
  *,
23
40
  project: str,
@@ -29,7 +46,10 @@ def configure(
29
46
  extensions: list[str] | None = None,
30
47
  html_theme_options: dict | None = None,
31
48
  sphinx_gallery_conf: dict | None = None,
32
- version: str = "latest",
49
+ gallery_sections: Sequence[str] | None = None,
50
+ gallery_default_thumb: str | None = None,
51
+ gallery_options: Mapping[str, object] | None = None,
52
+ version: str | None = None,
33
53
  source_suffix: str = ".rst",
34
54
  master_doc: str = "index",
35
55
  ) -> dict:
@@ -37,13 +57,20 @@ def configure(
37
57
 
38
58
  In a project's ``conf.py`` use ``globals().update(configure(...))`` and
39
59
  keep project-specific settings below that call so they remain easy to
40
- override.
60
+ override. Pass ``gallery_sections`` when examples are split into named
61
+ directories; use ``gallery_default_thumb`` for a project-specific raster
62
+ fallback; and use ``gallery_options`` for less common Sphinx-Gallery
63
+ settings.
41
64
  """
65
+ resolved_version = _resolve_version(package, version)
66
+
42
67
  default_extensions = [
43
68
  "sphinx.ext.autodoc",
44
69
  "sphinx.ext.autosummary",
45
70
  "sphinx.ext.intersphinx",
71
+ "sphinx.ext.mathjax",
46
72
  "sphinx.ext.napoleon",
73
+ "sphinx.ext.autosectionlabel",
47
74
  "sphinx.ext.viewcode",
48
75
  "sphinx.ext.todo",
49
76
  "sphinx_design",
@@ -85,7 +112,7 @@ def configure(
85
112
  ]
86
113
  options["switcher"] = {
87
114
  "json_url": f"https://raw.githubusercontent.com/{repository}/documentation_page/version_switcher.json",
88
- "version_match": version,
115
+ "version_match": resolved_version,
89
116
  }
90
117
 
91
118
  html_context = {}
@@ -111,6 +138,8 @@ def configure(
111
138
  "plot_gallery": True,
112
139
  "thumbnail_size": [600, 600],
113
140
  "download_all_examples": False,
141
+ "reset_modules_order": "after",
142
+ "within_subsection_order": "FileNameSortKey",
114
143
  # Use the project's favicon for examples that do not create a figure.
115
144
  # The path is interpreted relative to the documentation source tree,
116
145
  # just like ``html_favicon``.
@@ -120,6 +149,14 @@ def configure(
120
149
  "capture_repr": ("_repr_html_", "__repr__"),
121
150
  "nested_sections": True,
122
151
  }
152
+ if gallery_sections:
153
+ sections = list(gallery_sections)
154
+ gallery["examples_dirs"] = [f"../examples/{section}" for section in sections]
155
+ gallery["gallery_dirs"] = [f"gallery/{section}" for section in sections]
156
+ if gallery_default_thumb is not None:
157
+ gallery["default_thumb_file"] = gallery_default_thumb
158
+ if gallery_options:
159
+ gallery.update(gallery_options)
123
160
  if sphinx_gallery_conf:
124
161
  gallery.update(sphinx_gallery_conf)
125
162
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "MartinPdeS-docs"
7
- version = "0.1.4"
7
+ version = "0.2.0"
8
8
  description = "Shared Sphinx configuration for MartinPdeS scientific Python packages."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -15,6 +15,26 @@ def test_configuration_has_project_overrides():
15
15
  assert config["sphinx_gallery_conf"]["image_scrapers"] == ("matplotlib",)
16
16
  assert config["sphinx_gallery_conf"]["thumbnail_size"] == [600, 600]
17
17
  assert config["sphinx_gallery_conf"]["default_thumb_file"] is None
18
+ assert config["sphinx_gallery_conf"]["reset_modules_order"] == "after"
19
+ assert config["sphinx_gallery_conf"]["within_subsection_order"] == "FileNameSortKey"
20
+
21
+ sections = configure(
22
+ project="Example",
23
+ package="example",
24
+ gallery_sections=["tutorials", "validation"],
25
+ gallery_default_thumb="_static/gallery-default.png",
26
+ )
27
+ assert sections["sphinx_gallery_conf"]["examples_dirs"] == [
28
+ "../examples/tutorials",
29
+ "../examples/validation",
30
+ ]
31
+ assert sections["sphinx_gallery_conf"]["gallery_dirs"] == [
32
+ "gallery/tutorials",
33
+ "gallery/validation",
34
+ ]
35
+ assert sections["sphinx_gallery_conf"]["default_thumb_file"] == (
36
+ "_static/gallery-default.png"
37
+ )
18
38
 
19
39
  raster = configure(
20
40
  project="Example",
@@ -37,3 +57,25 @@ def test_custom_extensions_and_theme_options_are_preserved():
37
57
 
38
58
  assert config["extensions"] == ["custom.extension"]
39
59
  assert config["html_theme_options"]["announcement"] == "Hello"
60
+
61
+
62
+ def test_gallery_options_override_shared_defaults():
63
+ config = configure(
64
+ project="Example",
65
+ package="example",
66
+ gallery_options={"image_scrapers": ("matplotlib", "pyvista")},
67
+ )
68
+
69
+ assert config["sphinx_gallery_conf"]["image_scrapers"] == ("matplotlib", "pyvista")
70
+
71
+
72
+ def test_version_can_be_resolved_from_the_environment(monkeypatch):
73
+ monkeypatch.setenv("tag", "v2.3.4")
74
+
75
+ config = configure(
76
+ project="Example",
77
+ package="example",
78
+ repository="MartinPdeS/Example",
79
+ )
80
+
81
+ assert config["html_theme_options"]["switcher"]["version_match"] == "v2.3.4"