External substitutions file

31 views
Skip to first unread message

Olivier Carrere

unread,
Jan 17, 2020, 5:22:06 AM1/17/20
to sphinx-users
Hi,

How can I put all my substitutions in a dedicated, external file, and include them in my conf.py?

I tried to insert an  external substitutions file with via literalinclude with rst_prolog or rst_epilog, but then, substitions are not evaluated at build time and appear literally in the HTML output.

Thanks

Stefano David

unread,
Jan 19, 2020, 11:13:38 AM1/19/20
to sphinx-users
Hi,
Assuming your substitutions are in replace.txt, in conf. py write

rst_epilog = open("replace.txt", "r").read()
or
rst_prolog = open("replace.txt", "r").read()

Since I use the same replace.txt for different projects, I have a slight different definition of rst_epilog, which I report in case someone finds it useful.

rst_epilog = """
.. |product| replace:: %s
.. |company| replace:: %s
"""  % (project, comp) + open("replace.txt", "r").read()

Here, project and comp are variables defined in conf.py that vary with the project I am working on.
HTH,
Stefano

Olivier Carrere

unread,
Jan 20, 2020, 8:47:46 AM1/20/20
to sphinx-users
It does work!

Thanks a lot, Stefano!
Reply all
Reply to author
Forward
0 new messages