Skip to content

Commit 21f74e4

Browse files
FEAT: update theme to latest pydata-sphinx-theme layout (#190)
* MAINT: move breadcrumbs.html to components/ dir * MAINT: collect examples under a common sub-package * MAINT: remove docs-navbar.html * MAINT: move icon-links.html to components/ * FIX: explicit conditionals in layout.html for announcement * FEAT: apply theme structure * FIX: theme variable name Co-authored-by: Revathy Venugopal <[email protected]> * resolve style error * FIX: remove unused section * FEAT: add default configuration * Remove unused section * Resolves code style error * FEAT: add default HTML options * FIX: remove blank line in theme.conf * FIX: remove unused html_logo variable Co-authored-by: Revathy Venugopal <[email protected]> --------- Co-authored-by: Revathy Venugopal <[email protected]> Co-authored-by: Revathyvenugopal162 <[email protected]>
1 parent 2ef49f2 commit 21f74e4

34 files changed

+105
-113
lines changed

doc/source/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# Project information
2323
project = "ansys_sphinx_theme"
2424
copyright = f"(c) {datetime.now().year} ANSYS, Inc. All rights reserved"
25-
author = "Ansys Inc."
25+
author = "ANSYS, Inc."
2626
release = version = __version__
2727
cname = os.getenv("DOCUMENTATION_CNAME", "nocname.com")
2828

@@ -40,7 +40,6 @@
4040
# specify the location of your github repo
4141
html_theme_options = {
4242
"github_url": "https://github.com/ansys/ansys-sphinx-theme",
43-
"use_edit_page_button": True,
4443
"contact_mail": "[email protected]",
4544
"additional_breadcrumbs": [
4645
("Ansys Internal Developer Portal", "https://dev.docs.ansys.com"),
@@ -55,7 +54,6 @@
5554
"json_url": f"https://{cname}/release/versions.json",
5655
"version_match": get_version_match(__version__),
5756
},
58-
"navbar_end": ["version-switcher", "theme-switcher", "navbar-icon-links"],
5957
}
6058

6159
html_short_title = html_title = "Ansys Sphinx Theme"

pyproject.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ name = "ansys_sphinx_theme"
4646

4747
[tool.flit.sdist]
4848
include = [
49-
"src/ansys_sphinx_theme/layout.html",
50-
"src/ansys_sphinx_theme/breadcrumbs.html",
51-
"src/ansys_sphinx_theme/docs-navbar.html",
52-
"src/ansys_sphinx_theme/theme.conf",
53-
"src/ansys_sphinx_theme/_templates/",
54-
"src/ansys_sphinx_theme/static/",
49+
"src/ansys_sphinx_theme/theme/ansys_sphinx_theme/layout.html",
50+
"src/ansys_sphinx_theme/theme/ansys_sphinx_theme/components/breadcrumbs.html",
51+
"src/ansys_sphinx_theme/theme/ansys_sphinx_theme/theme.conf",
52+
"src/ansys_sphinx_theme/theme/ansys_sphinx_theme/_templates/",
53+
"src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/",
5554
]
5655

5756
[project.urls]

src/ansys_sphinx_theme/__init__.py

Lines changed: 90 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,115 @@
11
"""This is the ansys-sphinx-theme module."""
2-
import os
3-
from pathlib import Path
2+
import pathlib
3+
from typing import Dict
4+
5+
import sphinx
46

57
from ansys_sphinx_theme.latex import generate_404 # noqa: F401
68

79
__version__ = "0.9.dev0"
810

9-
# get location of this directory
10-
_this_path = os.path.dirname(os.path.realpath(__file__))
11+
12+
# Declare the fundamental paths of the theme
13+
THIS_PATH = pathlib.Path(__file__).parent.resolve()
14+
THEME_PATH = THIS_PATH / "theme" / "ansys_sphinx_theme"
15+
STATIC_PATH = THEME_PATH / "static"
16+
STYLE_PATH = STATIC_PATH / "css"
17+
CSS_PATH = STYLE_PATH / "ansys_sphinx_theme.css"
18+
TEMPLATES_PATH = THEME_PATH / "_templates"
1119

1220
# make logo paths available
13-
pyansys_logo_black = os.path.join(_this_path, "static", "pyansys-logo-black-cropped.png")
14-
pyansys_logo_white = os.path.join(_this_path, "static", "pyansys-logo-white-cropped.png")
15-
ansys_favicon = os.path.join(_this_path, "static", "ansys-favicon.png")
16-
ansys_logo_white = os.path.join(_this_path, "static", "ansys_logo_white.pdf")
17-
ansys_logo_white_cropped = os.path.join(_this_path, "static", "ansys_logo_white_cropped.pdf")
18-
watermark = os.path.join(_this_path, "static", "watermark.pdf")
19-
ansys_logo_black = os.path.join(_this_path, "static", "ansys_logo_black_cropped.jpg")
21+
ansys_favicon = str((STATIC_PATH / "ansys-favicon.png").absolute())
22+
ansys_logo_black = str((STATIC_PATH / "ansys_logo_black_cropped.jpg").absolute())
23+
ansys_logo_white = str((STATIC_PATH / "ansys_logo_white.pdf").absolute())
24+
ansys_logo_white_cropped = str((STATIC_PATH / "ansys_logo_white_cropped.pdf").absolute())
25+
page_404 = str((STATIC_PATH / "404.rst").absolute())
26+
pyansys_logo_black = str((STATIC_PATH / "pyansys-logo-black-cropped.png").absolute())
27+
pyansys_logo_white = str((STATIC_PATH / "pyansys-logo-white-cropped.png").absolute())
28+
watermark = str((STATIC_PATH / "watermark.pdf").absolute())
29+
30+
31+
def get_html_theme_path() -> pathlib.Path:
32+
"""Return list of HTML theme paths.
2033
21-
# Enable default 404 page
22-
page_404 = os.path.join(_this_path, "static", "404.rst")
34+
Returns
35+
-------
36+
pathlib.Path
37+
Path pointing to the installation directory of the theme.
2338
24-
html_logo = pyansys_logo_black
25-
CSS_FILENAME = "ansys_sphinx_theme.css"
39+
"""
40+
return THEME_PATH.resolve()
2641

2742

28-
def get_html_theme_path():
29-
"""Return list of HTML theme paths."""
30-
return Path(__file__).parents[0].absolute()
43+
def get_version_match(semver: str) -> str:
44+
"""Evaluate the version match for the multi-documentation.
3145
46+
Parameters
47+
----------
48+
semver : str
49+
Semantic version number in the form of a string.
3250
33-
def get_version_match(semver):
34-
"""Evaluate the version match for the multi-documentation."""
51+
Returns
52+
-------
53+
str
54+
Matching version number in the form of a string.
55+
56+
"""
3557
if semver.endswith("dev0"):
3658
return "dev"
3759
major, minor, _ = semver.split(".")
3860
return ".".join([major, minor])
3961

4062

41-
def setup(app):
42-
"""Connect to the sphinx theme app."""
63+
def setup_default_html_theme_options(app):
64+
"""Set up the default configuration for the HTML options.
65+
66+
Parameters
67+
----------
68+
app : sphinx.application.Sphinx
69+
Application instance for rendering the documentation.
70+
71+
Notes
72+
-----
73+
This function is the only way to overwrite ``pydata-sphinx-theme``
74+
configuration. Variables declared in the ``theme.conf`` do not include
75+
inherited ones.
76+
77+
"""
78+
# Place all switchers and icons at the end of the navigation bar
79+
app.config.html_theme_options.setdefault(
80+
"navbar_end", ["version-switcher", "theme-switcher", "navbar-icon-links"]
81+
)
82+
83+
84+
def setup(app: sphinx.application.Sphinx) -> Dict:
85+
"""Connect to the sphinx theme app.
86+
87+
Parameters
88+
----------
89+
app : sphinx.application.Sphinx
90+
Application instance for rendering the documentation.
91+
92+
Returns
93+
-------
94+
Dict
95+
Dictionary containing application status.
96+
97+
"""
98+
# Add the theme configuration
4399
theme_path = get_html_theme_path()
44100
app.add_html_theme("ansys_sphinx_theme", theme_path)
45-
theme_css_path = theme_path / "static" / "css" / CSS_FILENAME
46-
if not theme_css_path.exists():
47-
raise FileNotFoundError(f"Unable to locate ansys-sphinx theme at {theme_css_path}")
48-
app.add_css_file(str(theme_css_path.relative_to(theme_path / "static")))
49-
50-
# add templates for autosummary
51-
path_templates = os.path.join(_this_path, "_templates")
52-
app.config.templates_path.append(path_templates)
101+
app.config.templates_path.append(str(THEME_PATH / "components"))
102+
103+
# Add default HTML configuration
104+
setup_default_html_theme_options(app)
105+
106+
# Verify that the main CSS file exists
107+
if not CSS_PATH.exists():
108+
raise FileNotFoundError(f"Unable to locate ansys-sphinx theme at {CSS_PATH.absolute()}")
109+
app.add_css_file(str(CSS_PATH.relative_to(STATIC_PATH)))
110+
111+
# Add templates for autosummary
112+
app.config.templates_path.append(str(TEMPLATES_PATH))
53113

54114
return {
55115
"version": __version__,

src/ansys_sphinx_theme/docs-navbar.html

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""A sub-package containing various examples for checking their rendering."""
File renamed without changes.

src/ansys_sphinx_theme/icon-links.html

Lines changed: 0 additions & 27 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)