Skip to content

Commit 38ee2e9

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 7771478 commit 38ee2e9

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
@@ -273,10 +273,12 @@
273273
# Family Configuration file to use
274274
family_config_inputfile = f"{FAMILY}/{FAMILY}_{OS}_config.txt"
275275

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

281283
def setup(app):
282284
"""
@@ -286,11 +288,6 @@ def setup(app):
286288
# Load overrides
287289
app.add_css_file("css/theme_overrides.css")
288290

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

311-
# Write to the replacevars.rst.inc file for usage by Sphinx
312-
replacevars.write_replacevars(app, family_replacevars)
308+
# Load family config values into application context
309+
for key, value in family_configvals.items():
310+
app.add_config_value(key, value, 'env')
311+
313312
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)