Skip to content

Commit 0e0ac54

Browse files
authored
Migrate theme to toml config (#304)
Migrate theme to toml config
1 parent 7ff34a6 commit 0e0ac54

4 files changed

Lines changed: 92 additions & 119 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ classifiers = [
2323
requires-python = ">=3.9"
2424
dependencies = [
2525
"pydata-sphinx-theme~=0.16.0",
26-
"sphinx"
26+
"sphinx>=7.3.0"
2727
]
2828

2929
[project.optional-dependencies]

src/sunpy_sphinx_theme/__init__.py

Lines changed: 11 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
__all__ = ["ON_RTD", "PNG_ICON", "SVG_ICON", "get_html_theme_path"]
1616

1717

18+
def get_theme_options(app):
19+
"""
20+
This gets the user configured options and the defaults and merges them.
21+
"""
22+
return {**app.builder.theme.get_options(), **utils.get_theme_options_dict(app)}
23+
24+
1825
def get_html_theme_path():
1926
"""
2027
Return list of HTML theme paths.
@@ -23,66 +30,6 @@ def get_html_theme_path():
2330
return parent / "theme" / "sunpy"
2431

2532

26-
def default_navbar():
27-
return [
28-
(
29-
"About",
30-
[
31-
("Our Mission", "about/", 2),
32-
("SunPy Project", "about/project/", 2),
33-
("Presentations", "about/presentations/", 2),
34-
("Meetings", "about/meetings/", 2),
35-
("Code of Conduct", "coc/", 2),
36-
],
37-
),
38-
(
39-
"Documentation",
40-
[
41-
# Core goes first always
42-
("sunpy", "https://docs.sunpy.org/", 3),
43-
# Other affiliated packages are in alphabetical order
44-
("aiapy", "https://aiapy.readthedocs.io/", 3),
45-
("dkist", "https://docs.dkist.nso.edu/projects/python-tools", 3),
46-
("drms", "https://docs.sunpy.org/projects/drms/", 3),
47-
("irispy", "https://irispy.readthedocs.io/", 3),
48-
("ndcube", "https://docs.sunpy.org/projects/ndcube/", 3),
49-
("roentgen", "https://roentgen.readthedocs.io/", 3),
50-
("scope", "https://statistical-confidence-of-oscillatory-processes-with-emd.readthedocs.io", 3),
51-
("solarmach", "https://solarmach.readthedocs.io/en/stable/", 3),
52-
("sunkit-image", "https://docs.sunpy.org/projects/sunkit-image/", 3),
53-
("sunkit-instruments ", "https://docs.sunpy.org/projects/sunkit-instruments/", 3),
54-
("sunkit-magex", "https://docs.sunpy.org/projects/sunkit-magex/", 3),
55-
("sunkit-pyvista", "https://docs.sunpy.org/projects/sunkit-pyvista/", 3),
56-
("sunpy-soar", "https://docs.sunpy.org/projects/soar/", 3),
57-
("sunraster", "https://docs.sunpy.org/projects/sunraster/", 3),
58-
("xrtpy", "https://xrtpy.readthedocs.io/", 3),
59-
# Provisional packages submenu
60-
(
61-
"Provisional",
62-
[
63-
("pyflct", "https://pyflct.readthedocs.io/", 3),
64-
("radiospectra", "https://docs.sunpy.org/projects/radiospectra/", 3),
65-
],
66-
),
67-
# Tools submenu
68-
(
69-
"Tools",
70-
[
71-
("ablog", "https://ablog.readthedocs.io/en/stable/", 3),
72-
("mpl-animators", "https://docs.sunpy.org/projects/mpl-animators/", 3),
73-
("streamtracer", "https://docs.sunpy.org/projects/streamtracer/", 3),
74-
],
75-
),
76-
],
77-
),
78-
("Packages", "affiliated/", 2),
79-
("Get Help", "help/", 2),
80-
("Contribute", "contribute/", 2),
81-
("Blog", "blog/", 2),
82-
("Cite SunPy", "https://docs.sunpy.org/en/stable/citation.html", 3),
83-
]
84-
85-
8633
def update_config(app) -> None:
8734
"""
8835
Update config with new default values and handle deprecated keys.
@@ -91,31 +38,20 @@ def update_config(app) -> None:
9138
# At this point, modifying app.config.html_theme_options will NOT update the
9239
# page's HTML context (e.g. in jinja, `theme_keyword`).
9340
# To do this, you must manually modify `app.builder.theme_options`.
94-
theme_options = utils.get_theme_options_dict(app)
41+
theme_options = get_theme_options(app)
9542

9643
if theme_options.get("sst_logo") and not isinstance(theme_options["sst_logo"], dict):
9744
sst_logo = str(theme_options["sst_logo"])
9845
theme_options["sst_logo"] = {"light": sst_logo, "dark": sst_logo}
9946

10047
theme_options["sst_is_root"] = bool(theme_options.get("sst_is_root", False))
10148

102-
if not theme_options.get("navbar_links"):
103-
theme_options["navbar_links"] = default_navbar()
104-
105-
if not theme_options.get("footer_links", False):
106-
theme_options["footer_links"] = [
107-
("Code", "https://github.com/sunpy", 3),
108-
("Forum", "https://community.openastronomy.org/c/sunpy", 3),
109-
("Chat", "https://openastronomy.element.io/#/room/#sunpy:openastronomy.org", 3),
110-
]
111-
112-
# TODO: This is nasty
11349
# Set the default value of show_source to False unless it's specified in the user config
114-
if "html_show_sourcelink" not in app.config._raw_config: # NOQA: SLF001
50+
if not utils.config_provided_by_user(app, "html_show_sourcelink"):
11551
app.config.html_show_sourcelink = False
11652

11753
# Set the logo to the sunpy logo unless it's overridden in the user config
118-
if "html_logo" not in app.config._raw_config: # NOQA: SLF001
54+
if not utils.config_provided_by_user(app, "html_logo"):
11955
app.config.html_logo = str(get_html_theme_path() / "static" / "img" / "sunpy_icon.svg")
12056

12157

@@ -160,7 +96,7 @@ def generate_search_config(app):
16096
"""
16197
This function parses the config for the "Documentation" section of the theme config.
16298
"""
163-
theme_config = utils.get_theme_options_dict(app)
99+
theme_config = get_theme_options(app)
164100
search_projects = theme_config.get("rtd_search_projects", None)
165101
if search_projects is None:
166102
navbar_links = theme_config["navbar_links"]

src/sunpy_sphinx_theme/theme/sunpy/theme.conf

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[theme]
2+
inherit = "pydata_sphinx_theme"
3+
sidebars = [
4+
"components/navbar-logo.html",
5+
"icon-links.html",
6+
"components/sst-sidebar-nav.html",
7+
]
8+
9+
[options]
10+
navbar_start = "components/navbar_start.html"
11+
navbar_center = "components/navbar_center.html"
12+
footer_start = "copyright.html"
13+
footer_center = "components/footer-links.html"
14+
footer_end = "components/built-with.html"
15+
16+
sst_site_root = "https://sunpy.org"
17+
sst_is_root = false
18+
sst_project_name = "SunPy"
19+
sst_logo = ""
20+
navbar_links = [
21+
["About",
22+
[
23+
["Our Mission", "about/", 2],
24+
["SunPy Project", "about/project/", 2],
25+
["Presentations", "about/presentations/", 2],
26+
["Meetings", "about/meetings/", 2],
27+
["Code of Conduct", "coc/", 2]
28+
]
29+
],
30+
["Documentation",
31+
[
32+
["sunpy", "https://docs.sunpy.org/", 3],
33+
["aiapy", "https://aiapy.readthedocs.io/", 3],
34+
["dkist", "https://docs.dkist.nso.edu/projects/python-tools", 3],
35+
["drms", "https://docs.sunpy.org/projects/drms/", 3],
36+
["irispy", "https://irispy.readthedocs.io/", 3],
37+
["ndcube", "https://docs.sunpy.org/projects/ndcube/", 3],
38+
["roentgen", "https://roentgen.readthedocs.io/", 3],
39+
["scope", "https://statistical-confidence-of-oscillatory-processes-with-emd.readthedocs.io", 3],
40+
["solarmach", "https://solarmach.readthedocs.io/en/stable/", 3],
41+
["sunkit-image", "https://docs.sunpy.org/projects/sunkit-image/", 3],
42+
["sunkit-instruments ", "https://docs.sunpy.org/projects/sunkit-instruments/", 3],
43+
["sunkit-magex", "https://docs.sunpy.org/projects/sunkit-magex/", 3],
44+
["sunkit-pyvista", "https://docs.sunpy.org/projects/sunkit-pyvista/", 3],
45+
["sunpy-soar", "https://docs.sunpy.org/projects/soar/", 3],
46+
["sunraster", "https://docs.sunpy.org/projects/sunraster/", 3],
47+
["xrtpy", "https://xrtpy.readthedocs.io/", 3],
48+
["Provisional",
49+
[
50+
["pyflct", "https://pyflct.readthedocs.io/", 3],
51+
["radiospectra", "https://docs.sunpy.org/projects/radiospectra/", 3]
52+
]
53+
],
54+
["Tools",
55+
[
56+
["ablog", "https://ablog.readthedocs.io/en/stable/", 3],
57+
["mpl-animators", "https://docs.sunpy.org/projects/mpl-animators/", 3],
58+
["streamtracer", "https://docs.sunpy.org/projects/streamtracer/", 3]
59+
]
60+
]
61+
]
62+
],
63+
["Packages", "affiliated/", 2],
64+
["Get Help", "help/", 2],
65+
["Contribute", "contribute/", 2],
66+
["Blog", "blog/", 2],
67+
["Cite SunPy", "https://docs.sunpy.org/en/stable/citation.html", 3]
68+
]
69+
footer_links = [
70+
["Code", "https://github.com/sunpy", 3],
71+
["Forum", "https://community.openastronomy.org/c/sunpy", 3],
72+
["Chat", "https://openastronomy.element.io/#/room/#sunpy:openastronomy.org", 3],
73+
]
74+
goatcounter_analytics_url = ""
75+
goatcounter_non_domain_endpoint = "False"
76+
pygment_light_style = "github-light"
77+
rtd_search = "True"
78+
rtd_search_projects = ""
79+
rtd_search_load_more_label = "\"Load more results\""
80+
rtd_search_no_results_label = "\"There are no results for this search\""

0 commit comments

Comments
 (0)