From 1b680b8abbef0e874fe1da159b8b907fdb41ad59 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 30 Nov 2024 00:55:26 -0600 Subject: [PATCH] feat(conf): no replacevars file Remove the need for a replacevars file by placing all substitutions in the rst_prolog. This restructures things just a little bit so we can get access to required variables before we enter the application context. Signed-off-by: Randolph Sapp --- conf.py | 21 ++++++++++----------- scripts/interpretvalues.py | 8 ++++---- scripts/replacevars.py | 10 +++------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/conf.py b/conf.py index 468eaf999..f575a7b0c 100644 --- a/conf.py +++ b/conf.py @@ -274,10 +274,12 @@ # Family Configuration file to use family_config_inputfile = f"{FAMILY}/{FAMILY}_{OS}_config.txt" -# Hash table for Replacement Variables -family_replacevars = {} -# Hash table for Configuration Values -family_configvals = {} +# Hash table for Replacement Variables and Config Values +family_replacevars, family_configvals = interpretvalues.read_familyvals(family_config_inputfile) + +# Unpack replacement variables and place them in the preamble for all documents +rst_prolog = replacevars.unpack_replacevars(family_replacevars) +print(f'rst_prolog = """{rst_prolog}"""') def setup(app): """ @@ -287,11 +289,6 @@ def setup(app): # Load overrides app.add_css_file("css/theme_overrides.css") - # Read the replacement variables and the configuration values - print("Device Family Build setup started") - interpretvalues.read_familyvals(app, family_config_inputfile, - family_replacevars, family_configvals) - print("Build setup: Filled Replacement Variables (family_replacevars)" "and Configuration Values (family_configvals) hash tables") print("family_replacevars = ") @@ -309,6 +306,8 @@ def setup(app): print(elem) print(']') - # Write to the replacevars.rst.inc file for usage by Sphinx - replacevars.write_replacevars(app, family_replacevars) + # Load family config values into application context + for key, value in family_configvals.items(): + app.add_config_value(key, value, 'env') + print("Device Family Build setup completed") diff --git a/scripts/interpretvalues.py b/scripts/interpretvalues.py index 3e28ce6ab..12f83f309 100644 --- a/scripts/interpretvalues.py +++ b/scripts/interpretvalues.py @@ -17,7 +17,9 @@ # in _config.txt # (i.e. each has name, key pairs) -def read_familyvals(app, valuesfile, fam_replacevars, fam_configvals): +def read_familyvals(valuesfile): + fam_replacevars = {} + fam_configvals = {} filt_hash_pair = [None] * 2 with open("configs" + os.sep + valuesfile, 'r') as f: text = f.readlines() # read text lines to list @@ -67,6 +69,4 @@ def read_familyvals(app, valuesfile, fam_replacevars, fam_configvals): filt_hash_pair[k] = filt_hash_item # Fill fam_configvals hash table fam_configvals[filt_hash_pair[0]] = filt_hash_pair[1] - app.add_config_value(filt_hash_pair[0], filt_hash_pair[1], 'env') - #print(fam_replacevars) - #print(fam_configvals) + return (fam_replacevars, fam_configvals) diff --git a/scripts/replacevars.py b/scripts/replacevars.py index d33c4d424..aeeba99f4 100644 --- a/scripts/replacevars.py +++ b/scripts/replacevars.py @@ -1,5 +1,3 @@ -import os - # write_replacevars # ----------------- # Description: Writes replacement variable array to source/${OS}/replacevars.rst.inc @@ -8,14 +6,12 @@ # replacevars - Input hash table of replacevars that will be converted into # "replace" directives in the replacevars.rst.inc file -def write_replacevars(app, replacevars): - replacevarsfile= os.environ.get('ROOTDIR') + "/source/" + "_replacevars.rst" +def unpack_replacevars(replacevars): replacevarstext = ["\n"] for key, val in replacevars.items(): if val == "\\": replacevarstext.append(f".. |{key}| unicode:: U+00000\n") else: replacevarstext.append(f".. |{key}| replace:: {val}\n") - with open(replacevarsfile, 'w', encoding='utf-8') as vars_file: - replacevarstext.append("\n") - vars_file.write("\n".join(replacevarstext)) + replacevarstext.append("\n") + return ''.join(replacevarstext)