Repository Architecture#
Overview of the project structure and how the major components fit together.
Build System#
The project uses two build systems:
Node.js (webpack) — compiles SCSS and JS source assets into production files
Python (sphinx-theme-builder) — packages and distributes the Sphinx theme
Key build config files:
package.json+webpack.config.js— Node.js asset compilationpyproject.toml— Python package configurationtox.ini— Environment management and task automation.pre-commit-config.yaml— Code quality hooks
src/quantecon_book_theme/ — Theme Source#
This is where most changes are made.
__init__.py — Python Module#
The main theme module. Sets up the quantecon-book-theme extension, inheriting
from sphinx-book-theme. Key functions:
setup_pygments_css()— generates Pygments CSS when custom code styling is disabledadd_pygments_style_class()— adds CSS class to enable/disable custom highlightinghash_assets_for_files()— adds cache-busting hashes to static assets
/theme/quantecon_book_theme/ — HTML Templates#
The actual Sphinx theme distributed via PyPI. Follows the
sphinx-basic-ng template structure.
layout.html— inherits from PyData Sphinx Theme. Includes preconnect hints, SRI hashes, and external library loadingtheme.conf— Sphinx theme configuration filemacros/— Jinja macrossections/— HTML templates for major page sectionscomponents/— HTML templates for self-contained page components
/assets/scripts/ — JavaScript Modules#
ES6 modules organized by feature, compiled by webpack into a single bundle:
Module |
Purpose |
Exports |
|---|---|---|
|
Entry point |
Imports all modules |
|
Dark mode, contrast, font size |
|
|
Sidebar toggle and navigation |
|
|
Search functionality |
|
|
Fullscreen, back-to-top |
|
|
Collapsible code, table containers |
|
|
Tooltips and launcher settings |
|
|
Page header and changelog |
|
|
Collapsible stderr output |
|
/assets/styles/ — SCSS Modules#
Compiled by webpack into a single CSS file. Entry point is index.scss using
@forward directives:
Module |
Purpose |
|---|---|
|
Typography, HTML elements, resets |
|
Dark mode color overrides |
|
Top navigation bar |
|
Left sidebar navigation |
|
Main content area layout |
|
Content typography and spacing |
|
Note/warning/tip boxes |
|
Footnote styling |
|
Stderr warning collapsible styling |
|
Modal dialog styles |
|
API documentation styles |
|
Color variable definitions |
Modules that need color variables use @use "colors" syntax.
docs/ — Documentation#
The theme’s own documentation, structured into User Guide and Developer Guide:
docs/user/— Configuration and usage documentation for theme usersdocs/developer/— Contributing, architecture, and testing guidesdocs/reference/— Visual demos of theme elementsdocs/api/— Python API autodoc
tests/ — Testing#
Uses pytest with beautifulsoup to validate generated HTML:
conftest.py— shared fixtures for directory pathstest_build.py— HTML build and regression teststest_module_structure.py— modular SCSS/JS organization teststest_rtl_functionality.py— RTL language support teststest_custom_colors.py— color scheme tests
External Dependencies (CDN)#
Library |
Version |
Purpose |
|---|---|---|
2.9.2 |
Tooltip positioning engine |
|
6.3.1 |
Tooltip library |
|
latest |
Icon set |
Loaded with SRI (Subresource Integrity) hashes for security.
Parent Theme#
This theme inherits from the PyData Sphinx Theme. If you encounter unfamiliar code, check the PyData Theme source files.