Skip to content

Commit

Permalink
feat(conf): no replacevars file
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
StaticRocket committed Dec 5, 2024
1 parent 5de9b4f commit 1b680b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
21 changes: 10 additions & 11 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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 = ")
Expand All @@ -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")
8 changes: 4 additions & 4 deletions scripts/interpretvalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
# in <DEVICE_FAMILY>_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
Expand Down Expand Up @@ -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)
10 changes: 3 additions & 7 deletions scripts/replacevars.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

# write_replacevars
# -----------------
# Description: Writes replacement variable array to source/${OS}/replacevars.rst.inc
Expand All @@ -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)

0 comments on commit 1b680b8

Please sign in to comment.