Skip to content

Commit fdc5325

Browse files
committed
refactor(conf): import required sections instead
Instead of using the config step to concatenate files, just use the running Python interpreter to set things up. Signed-off-by: Randolph Sapp <[email protected]>
1 parent a5179a5 commit fdc5325

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

conf.py

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515

1616
import sys
1717
import os
18+
import importlib
1819

1920
# If extensions (or modules to document with autodoc) are in another directory,
2021
# add these directories to sys.path here. If the directory is relative to the
2122
# documentation root, use os.path.abspath to make it absolute, like shown here.
2223
#sys.path.insert(0, os.path.abspath('.'))
2324
rootdir = os.environ.get('ROOTDIR')
24-
sys.path.append(rootdir + 'python-scripts')
25+
sys.path.insert(0, os.path.abspath(rootdir))
26+
27+
from scripts import interpretvalues, sectinc, replacevars
2528

2629
# -- General configuration ------------------------------------------------
2730

@@ -42,7 +45,7 @@
4245
]
4346

4447
# Add any paths that contain templates here, relative to this directory.
45-
templates_path = ['../_templates']
48+
templates_path = ['_templates']
4649

4750
# The suffix(es) of source filenames.
4851
# You can specify multiple suffix as a list of string:
@@ -240,3 +243,61 @@
240243

241244
# Suppress warnings about excluded documents because every device gets a different toc tree
242245
suppress_warnings = ['toc.excluded']
246+
247+
# -- Tag file loader ------------------------------------------------------
248+
249+
# Defaults
250+
exclude_patterns = []
251+
252+
FAMILY = os.environ.get("DEVFAMILY", "")
253+
OS = os.environ.get("OS", "")
254+
try:
255+
globals().update(importlib.import_module(f"configs.{FAMILY}.{FAMILY}_{OS}_tags").__dict__)
256+
except ModuleNotFoundError as exc:
257+
raise ModuleNotFoundError("Configuration not supported!") from exc
258+
259+
# -- Family setup ---------------------------------------------------------
260+
261+
# List of Inclusion TOC files to use
262+
family_tocfiles = [f"{FAMILY}/{FAMILY}_{OS}_toc.txt"]
263+
# Family Configuration file to use
264+
family_config_inputfile = f"{FAMILY}/{FAMILY}_{OS}_config.txt"
265+
266+
# Hash table for Replacement Variables
267+
family_replacevars = {}
268+
# Hash table for Configuration Values
269+
family_configvals = {}
270+
271+
def setup(app):
272+
"""
273+
Sphinx application entrypoint
274+
"""
275+
276+
# Load overrides
277+
app.add_css_file("css/theme_overrides.css")
278+
279+
# Read the replacement variables and the configuration values
280+
print("Device Family Build setup started")
281+
interpretvalues.read_familyvals(app, family_config_inputfile,
282+
family_replacevars, family_configvals)
283+
284+
print("Build setup: Filled Replacement Variables (family_replacevars)"
285+
"and Configuration Values (family_configvals) hash tables")
286+
print("family_replacevars = ")
287+
print(family_replacevars)
288+
print("family_configvals = ")
289+
print(family_configvals)
290+
291+
# Determine which sections need to be excluded
292+
sectinc.find_all_rst_files(app, exclude_patterns)
293+
sectinc.fill_docs_to_keep(app, family_tocfiles, 0)
294+
sectinc.set_excluded_docs(app, exclude_patterns)
295+
print(FAMILY + " exclude_patterns is:")
296+
print('[')
297+
for elem in exclude_patterns:
298+
print(elem)
299+
print(']')
300+
301+
# Write to the replacevars.rst.inc file for usage by Sphinx
302+
replacevars.write_replacevars(app, family_replacevars)
303+
print("Device Family Build setup completed")

0 commit comments

Comments
 (0)