MartinPdeS-docs 0.2.1__tar.gz → 0.2.3__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.2.1
3
+ Version: 0.2.3
4
4
  Summary: Shared Sphinx configuration for MartinPdeS scientific Python packages.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -61,3 +61,25 @@ additional image scraper or an example error policy.
61
61
  For packages with compiled extensions, set `prefer_installed_package=True` so
62
62
  documentation builds import the installed wheel instead of the source
63
63
  checkout.
64
+
65
+ The shared configuration also owns the common dark-mode context, CSS files,
66
+ autodoc defaults, and navigation metadata. Add only project-specific values in
67
+ `conf.py`, for example:
68
+
69
+ ```python
70
+ globals().update(
71
+ configure(
72
+ project="SuPyMode",
73
+ package="SuPyMode",
74
+ repository="MartinPdeS/SuPyMode",
75
+ extension_additions=["pyvista.ext.plot_directive"],
76
+ html_css_files=["layout.css"],
77
+ autodoc_default_options={"members": True},
78
+ logo_text="",
79
+ )
80
+ )
81
+ ```
82
+
83
+ Use `include_gallery=False` for documentation sites without executable
84
+ examples. The default theme, context, CSS, and extension set then remain
85
+ centralized in this package.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MartinPdeS-docs
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Shared Sphinx configuration for MartinPdeS scientific Python packages.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -61,3 +61,25 @@ additional image scraper or an example error policy.
61
61
  For packages with compiled extensions, set `prefer_installed_package=True` so
62
62
  documentation builds import the installed wheel instead of the source
63
63
  checkout.
64
+
65
+ The shared configuration also owns the common dark-mode context, CSS files,
66
+ autodoc defaults, and navigation metadata. Add only project-specific values in
67
+ `conf.py`, for example:
68
+
69
+ ```python
70
+ globals().update(
71
+ configure(
72
+ project="SuPyMode",
73
+ package="SuPyMode",
74
+ repository="MartinPdeS/SuPyMode",
75
+ extension_additions=["pyvista.ext.plot_directive"],
76
+ html_css_files=["layout.css"],
77
+ autodoc_default_options={"members": True},
78
+ logo_text="",
79
+ )
80
+ )
81
+ ```
82
+
83
+ Use `include_gallery=False` for documentation sites without executable
84
+ examples. The default theme, context, CSS, and extension set then remain
85
+ centralized in this package.
@@ -49,3 +49,25 @@ additional image scraper or an example error policy.
49
49
  For packages with compiled extensions, set `prefer_installed_package=True` so
50
50
  documentation builds import the installed wheel instead of the source
51
51
  checkout.
52
+
53
+ The shared configuration also owns the common dark-mode context, CSS files,
54
+ autodoc defaults, and navigation metadata. Add only project-specific values in
55
+ `conf.py`, for example:
56
+
57
+ ```python
58
+ globals().update(
59
+ configure(
60
+ project="SuPyMode",
61
+ package="SuPyMode",
62
+ repository="MartinPdeS/SuPyMode",
63
+ extension_additions=["pyvista.ext.plot_directive"],
64
+ html_css_files=["layout.css"],
65
+ autodoc_default_options={"members": True},
66
+ logo_text="",
67
+ )
68
+ )
69
+ ```
70
+
71
+ Use `include_gallery=False` for documentation sites without executable
72
+ examples. The default theme, context, CSS, and extension set then remain
73
+ centralized in this package.
@@ -59,13 +59,20 @@ def configure(
59
59
  logo: str = "_static/logo.svg",
60
60
  favicon: str = "_static/favicon.svg",
61
61
  repository: str | None = None,
62
- extensions: list[str] | None = None,
62
+ extensions: Sequence[str] | None = None,
63
+ extension_additions: Sequence[str] | None = None,
63
64
  html_theme_options: dict | None = None,
65
+ logo_text: str | None = None,
66
+ logo_alt_text: str | None = None,
67
+ html_context: Mapping[str, object] | None = None,
68
+ html_css_files: Sequence[str] | None = None,
69
+ autodoc_default_options: Mapping[str, object] | None = None,
64
70
  sphinx_gallery_conf: dict | None = None,
65
71
  gallery_sections: Sequence[str] | None = None,
66
72
  gallery_default_thumb: str | None = None,
67
73
  gallery_options: Mapping[str, object] | None = None,
68
74
  prefer_installed_package: bool = False,
75
+ include_gallery: bool = True,
69
76
  version: str | None = None,
70
77
  source_suffix: str = ".rst",
71
78
  master_doc: str = "index",
@@ -85,20 +92,8 @@ def configure(
85
92
 
86
93
  resolved_version = _resolve_version(package, version)
87
94
 
88
- default_extensions = [
89
- "sphinx.ext.autodoc",
90
- "sphinx.ext.autosummary",
91
- "sphinx.ext.intersphinx",
92
- "sphinx.ext.mathjax",
93
- "sphinx.ext.napoleon",
94
- "sphinx.ext.autosectionlabel",
95
- "sphinx.ext.viewcode",
96
- "sphinx.ext.todo",
97
- "sphinx_design",
98
- "sphinx_gallery.gen_gallery",
99
- ]
100
95
  options = {
101
- "logo": {"text": project, "image": logo},
96
+ "logo": {"text": project if logo_text is None else logo_text, "image": logo},
102
97
  "navigation_with_keys": True,
103
98
  "show_nav_level": 2,
104
99
  "navbar_align": "content",
@@ -112,6 +107,8 @@ def configure(
112
107
  "pygments_dark_style": "github-dark",
113
108
  "use_edit_page_button": bool(repository),
114
109
  }
110
+ if logo_alt_text is not None:
111
+ options["logo"]["alt_text"] = logo_alt_text
115
112
  if repository:
116
113
  owner, repo = repository.split("/", 1)
117
114
  options["icon_links"] = [
@@ -136,20 +133,43 @@ def configure(
136
133
  "version_match": resolved_version,
137
134
  }
138
135
 
139
- html_context = {}
136
+ context = {
137
+ "doc_path": "docs/source",
138
+ "default_mode": "dark",
139
+ }
140
140
  if repository:
141
141
  owner, repo = repository.split("/", 1)
142
142
  ref_name = os.getenv("GITHUB_REF_NAME", "master")
143
- html_context.update(
143
+ context.update(
144
144
  {
145
145
  "github_user": owner,
146
146
  "github_repo": repo,
147
147
  "github_version": ref_name,
148
148
  }
149
149
  )
150
+ if html_context:
151
+ context.update(html_context)
150
152
  if html_theme_options:
151
153
  options.update(html_theme_options)
152
154
 
155
+ default_extensions = [
156
+ "sphinx.ext.autodoc",
157
+ "sphinx.ext.autosummary",
158
+ "sphinx.ext.intersphinx",
159
+ "sphinx.ext.mathjax",
160
+ "sphinx.ext.napoleon",
161
+ "sphinx.ext.autosectionlabel",
162
+ "sphinx.ext.viewcode",
163
+ "sphinx.ext.todo",
164
+ "sphinx_design",
165
+ ]
166
+ if include_gallery:
167
+ default_extensions.append("sphinx_gallery.gen_gallery")
168
+ if extensions is None:
169
+ configured_extensions = default_extensions + list(extension_additions or ())
170
+ else:
171
+ configured_extensions = list(extensions)
172
+
153
173
  gallery = {
154
174
  "examples_dirs": "../examples/",
155
175
  "gallery_dirs": "gallery/",
@@ -170,40 +190,48 @@ def configure(
170
190
  "capture_repr": ("_repr_html_", "__repr__"),
171
191
  "nested_sections": True,
172
192
  }
173
- if gallery_sections:
193
+ if not include_gallery:
194
+ gallery = None
195
+ elif gallery_sections:
174
196
  sections = list(gallery_sections)
175
197
  gallery["examples_dirs"] = [f"../examples/{section}" for section in sections]
176
198
  gallery["gallery_dirs"] = [f"gallery/{section}" for section in sections]
177
- if gallery_default_thumb is not None:
178
- gallery["default_thumb_file"] = gallery_default_thumb
179
- if gallery_options:
180
- gallery.update(gallery_options)
181
- if sphinx_gallery_conf:
182
- gallery.update(sphinx_gallery_conf)
183
-
184
- return {
199
+ if gallery is not None:
200
+ if gallery_default_thumb is not None:
201
+ gallery["default_thumb_file"] = gallery_default_thumb
202
+ if gallery_options:
203
+ gallery.update(gallery_options)
204
+ if sphinx_gallery_conf:
205
+ gallery.update(sphinx_gallery_conf)
206
+
207
+ css_files = ["default.css", "martinpdes_layout.css"]
208
+ css_files.extend(html_css_files or ())
209
+ autodoc_options = {
210
+ "members": False,
211
+ "members-order": "bysource",
212
+ "undoc-members": False,
213
+ "show-inheritance": True,
214
+ }
215
+ autodoc_options.update(autodoc_default_options or {})
216
+
217
+ configuration = {
185
218
  "project": project,
186
219
  "package": package,
187
220
  "author": author,
188
221
  "copyright": author,
189
- "extensions": extensions or default_extensions,
222
+ "extensions": configured_extensions,
190
223
  "exclude_patterns": ["_build", "Thumbs.db", ".DS_Store"],
191
224
  "suppress_warnings": ["config.cache"],
192
225
  "html_theme": "pydata_sphinx_theme",
193
226
  "html_theme_options": options,
194
- "html_context": html_context,
227
+ "html_context": context,
195
228
  "html_logo": logo,
196
229
  "html_favicon": favicon,
197
230
  "html_static_path": ["_static", str(Path(__file__).parent / "static")],
198
231
  "templates_path": ["_templates"],
199
- "html_css_files": ["default.css", "martinpdes_layout.css"],
232
+ "html_css_files": css_files,
200
233
  "autodoc_typehints": "description",
201
- "autodoc_default_options": {
202
- "members": False,
203
- "members-order": "bysource",
204
- "undoc-members": False,
205
- "show-inheritance": True,
206
- },
234
+ "autodoc_default_options": autodoc_options,
207
235
  "napoleon_google_docstring": False,
208
236
  "napoleon_numpy_docstring": True,
209
237
  "autosectionlabel_prefix_document": True,
@@ -220,12 +248,11 @@ def configure(
220
248
  "latex_elements": {},
221
249
  "latex_documents": [(master_doc, f"{package}.tex", f"{package} Documentation", author, "manual")],
222
250
  "man_pages": [(master_doc, package.lower(), f"{package} Documentation", [author], 1)],
223
- "texinfo_documents": [
224
- (master_doc, package, f"{package} Documentation", author, package,
225
- f"Documentation for {package}.", "Miscellaneous")
226
- ],
251
+ "texinfo_documents": [(master_doc, package, f"{package} Documentation", author, package, f"Documentation for {package}.", "Miscellaneous")],
227
252
  "epub_title": project,
228
253
  "epub_exclude_files": ["search.html"],
229
- "sphinx_gallery_conf": gallery,
230
254
  "_martinpdes_package_root": str(Path(__file__).parent),
231
255
  }
256
+ if gallery is not None:
257
+ configuration["sphinx_gallery_conf"] = gallery
258
+ return configuration
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "MartinPdeS-docs"
7
- version = "0.2.1"
7
+ version = "0.2.3"
8
8
  description = "Shared Sphinx configuration for MartinPdeS scientific Python packages."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -14,6 +14,8 @@ def test_configuration_has_project_overrides():
14
14
  assert config["html_static_path"][1].endswith("martinpdes_docs/static")
15
15
  assert config["templates_path"] == ["_templates"]
16
16
  assert config["html_css_files"] == ["default.css", "martinpdes_layout.css"]
17
+ assert config["html_context"]["doc_path"] == "docs/source"
18
+ assert config["html_context"]["default_mode"] == "dark"
17
19
  assert config["epub_exclude_files"] == ["search.html"]
18
20
  assert config["sphinx_gallery_conf"]["image_scrapers"] == ("matplotlib",)
19
21
  assert config["sphinx_gallery_conf"]["thumbnail_size"] == [600, 600]
@@ -35,9 +37,7 @@ def test_configuration_has_project_overrides():
35
37
  "gallery/tutorials",
36
38
  "gallery/validation",
37
39
  ]
38
- assert sections["sphinx_gallery_conf"]["default_thumb_file"] == (
39
- "_static/gallery-default.png"
40
- )
40
+ assert sections["sphinx_gallery_conf"]["default_thumb_file"] == ("_static/gallery-default.png")
41
41
 
42
42
  raster = configure(
43
43
  project="Example",
@@ -61,6 +61,32 @@ def test_custom_extensions_and_theme_options_are_preserved():
61
61
  assert config["extensions"] == ["custom.extension"]
62
62
  assert config["html_theme_options"]["announcement"] == "Hello"
63
63
 
64
+ additions = configure(
65
+ project="Example",
66
+ package="example",
67
+ extension_additions=["pyvista.ext.plot_directive"],
68
+ html_css_files=["layout.css"],
69
+ logo_text="",
70
+ logo_alt_text="Example logo",
71
+ autodoc_default_options={"members": True},
72
+ )
73
+ assert "pyvista.ext.plot_directive" in additions["extensions"]
74
+ assert additions["html_css_files"][-1] == "layout.css"
75
+ assert additions["html_theme_options"]["logo"] == {
76
+ "text": "",
77
+ "image": "_static/logo.svg",
78
+ "alt_text": "Example logo",
79
+ }
80
+ assert additions["autodoc_default_options"]["members"] is True
81
+
82
+ no_gallery = configure(
83
+ project="Example",
84
+ package="example",
85
+ include_gallery=False,
86
+ )
87
+ assert "sphinx_gallery.gen_gallery" not in no_gallery["extensions"]
88
+ assert "sphinx_gallery_conf" not in no_gallery
89
+
64
90
 
65
91
  def test_gallery_options_override_shared_defaults():
66
92
  config = configure(