Skip to content

Commit 6dbaa14

Browse files
committed
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 <[email protected]>
1 parent c8478a8 commit 6dbaa14

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

conf.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,12 @@
274274
# Family Configuration file to use
275275
family_config_inputfile = f"{FAMILY}/{FAMILY}_{OS}_config.txt"
276276

277-
# Hash table for Replacement Variables
278-
family_replacevars = {}
279-
# Hash table for Configuration Values
280-
family_configvals = {}
277+
# Hash table for Replacement Variables and Config Values
278+
family_replacevars, family_configvals = interpretvalues.read_familyvals(family_config_inputfile)
279+
280+
# Unpack replacement variables and place them in the preamble for all documents
281+
rst_prolog = replacevars.unpack_replacevars(family_replacevars)
282+
print(f'rst_prolog = """{rst_prolog}"""')
281283

282284
def setup(app):
283285
"""
@@ -287,11 +289,6 @@ def setup(app):
287289
# Load overrides
288290
app.add_css_file("css/theme_overrides.css")
289291

290-
# Read the replacement variables and the configuration values
291-
print("Device Family Build setup started")
292-
interpretvalues.read_familyvals(app, family_config_inputfile,
293-
family_replacevars, family_configvals)
294-
295292
print("Build setup: Filled Replacement Variables (family_replacevars)"
296293
"and Configuration Values (family_configvals) hash tables")
297294
print("family_replacevars = ")
@@ -309,6 +306,8 @@ def setup(app):
309306
print(elem)
310307
print(']')
311308

312-
# Write to the replacevars.rst.inc file for usage by Sphinx
313-
replacevars.write_replacevars(app, family_replacevars)
309+
# Load family config values into application context
310+
for key, value in family_configvals.items():
311+
app.add_config_value(key, value, 'env')
312+
314313
print("Device Family Build setup completed")

scripts/interpretvalues.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
# in <DEVICE_FAMILY>_config.txt
1818
# (i.e. each has name, key pairs)
1919

20-
def read_familyvals(app, valuesfile, fam_replacevars, fam_configvals):
20+
def read_familyvals(valuesfile):
21+
fam_replacevars = {}
22+
fam_configvals = {}
2123
filt_hash_pair = [None] * 2
2224
with open("configs" + os.sep + valuesfile, 'r') as f:
2325
text = f.readlines() # read text lines to list
@@ -67,6 +69,4 @@ def read_familyvals(app, valuesfile, fam_replacevars, fam_configvals):
6769
filt_hash_pair[k] = filt_hash_item
6870
# Fill fam_configvals hash table
6971
fam_configvals[filt_hash_pair[0]] = filt_hash_pair[1]
70-
app.add_config_value(filt_hash_pair[0], filt_hash_pair[1], 'env')
71-
#print(fam_replacevars)
72-
#print(fam_configvals)
72+
return (fam_replacevars, fam_configvals)

scripts/replacevars.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
# write_replacevars
42
# -----------------
53
# Description: Writes replacement variable array to source/${OS}/replacevars.rst.inc
@@ -8,14 +6,12 @@
86
# replacevars - Input hash table of replacevars that will be converted into
97
# "replace" directives in the replacevars.rst.inc file
108

11-
def write_replacevars(app, replacevars):
12-
replacevarsfile= os.environ.get('ROOTDIR') + "/source/" + "_replacevars.rst"
9+
def unpack_replacevars(replacevars):
1310
replacevarstext = ["\n"]
1411
for key, val in replacevars.items():
1512
if val == "\\":
1613
replacevarstext.append(f".. |{key}| unicode:: U+00000\n")
1714
else:
1815
replacevarstext.append(f".. |{key}| replace:: {val}\n")
19-
with open(replacevarsfile, 'w', encoding='utf-8') as vars_file:
20-
replacevarstext.append("\n")
21-
vars_file.write("\n".join(replacevarstext))
16+
replacevarstext.append("\n")
17+
return ''.join(replacevarstext)

0 commit comments

Comments
 (0)