MartinPdeS-docs 0.2.3__tar.gz → 0.2.5__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.3
3
+ Version: 0.2.5
4
4
  Summary: Shared Sphinx configuration for MartinPdeS scientific Python packages.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: MartinPdeS-docs
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Shared Sphinx configuration for MartinPdeS scientific Python packages.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -21,10 +21,27 @@ def _raster_thumbnail_path(logo: str, favicon: str) -> str | None:
21
21
  raster_suffixes = {".png", ".jpg", ".jpeg", ".gif"}
22
22
  for candidate in (logo, favicon):
23
23
  if Path(candidate).suffix.lower() in raster_suffixes:
24
- return candidate
24
+ return _resolve_doc_asset(candidate)
25
25
  return None
26
26
 
27
27
 
28
+ def _resolve_doc_asset(path: str) -> str:
29
+ """Resolve a documentation asset relative to common Sphinx build roots."""
30
+ candidate = Path(path)
31
+ if candidate.is_absolute():
32
+ return str(candidate)
33
+
34
+ roots = (
35
+ Path.cwd(),
36
+ Path.cwd() / "docs" / "source",
37
+ )
38
+ for root in roots:
39
+ resolved = root / candidate
40
+ if resolved.is_file():
41
+ return str(resolved)
42
+ return path
43
+
44
+
28
45
  def _resolve_version(package: str, version: str | None) -> str:
29
46
  """Resolve the documentation version without importing the package."""
30
47
  if version is not None:
@@ -198,7 +215,7 @@ def configure(
198
215
  gallery["gallery_dirs"] = [f"gallery/{section}" for section in sections]
199
216
  if gallery is not None:
200
217
  if gallery_default_thumb is not None:
201
- gallery["default_thumb_file"] = gallery_default_thumb
218
+ gallery["default_thumb_file"] = _resolve_doc_asset(gallery_default_thumb)
202
219
  if gallery_options:
203
220
  gallery.update(gallery_options)
204
221
  if sphinx_gallery_conf:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "MartinPdeS-docs"
7
- version = "0.2.3"
7
+ version = "0.2.5"
8
8
  description = "Shared Sphinx configuration for MartinPdeS scientific Python packages."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -1,4 +1,5 @@
1
1
  from importlib.metadata import distribution
2
+ from pathlib import Path
2
3
  import sys
3
4
 
4
5
  from martinpdes_docs import configure
@@ -37,7 +38,10 @@ def test_configuration_has_project_overrides():
37
38
  "gallery/tutorials",
38
39
  "gallery/validation",
39
40
  ]
40
- assert sections["sphinx_gallery_conf"]["default_thumb_file"] == ("_static/gallery-default.png")
41
+ assert sections["sphinx_gallery_conf"]["default_thumb_file"] in {
42
+ "_static/gallery-default.png",
43
+ str(Path.cwd() / "docs" / "source" / "_static" / "gallery-default.png"),
44
+ }
41
45
 
42
46
  raster = configure(
43
47
  project="Example",
@@ -45,7 +49,7 @@ def test_configuration_has_project_overrides():
45
49
  logo="../images/logo.png",
46
50
  favicon="_static/favicon.svg",
47
51
  )
48
- assert raster["sphinx_gallery_conf"]["default_thumb_file"] == "../images/logo.png"
52
+ assert raster["sphinx_gallery_conf"]["default_thumb_file"].endswith("images/logo.png")
49
53
  assert "github_url" not in config["html_theme_options"]
50
54
  assert config["html_context"]["github_repo"] == "Example"
51
55
 
@@ -98,6 +102,21 @@ def test_gallery_options_override_shared_defaults():
98
102
  assert config["sphinx_gallery_conf"]["image_scrapers"] == ("matplotlib", "pyvista")
99
103
 
100
104
 
105
+ def test_gallery_thumbnail_paths_are_resolved_from_docs_source(tmp_path, monkeypatch):
106
+ asset = tmp_path / "docs" / "source" / "_static" / "gallery-default.png"
107
+ asset.parent.mkdir(parents=True)
108
+ asset.write_bytes(b"png")
109
+ monkeypatch.chdir(tmp_path)
110
+
111
+ config = configure(
112
+ project="Example",
113
+ package="example",
114
+ gallery_default_thumb="_static/gallery-default.png",
115
+ )
116
+
117
+ assert config["sphinx_gallery_conf"]["default_thumb_file"] == str(asset)
118
+
119
+
101
120
  def test_version_can_be_resolved_from_the_environment(monkeypatch):
102
121
  monkeypatch.setenv("tag", "v2.3.4")
103
122