Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I output a config value in a Sphinx .rst file?

I've got the following in conf.py:

def setup(app):
    app.add_config_value('base_url','http://localhost:2000', True)

How do I get this into my .rst files? I wrote this:

:base_url:/my_app/api/application/

But it only prints :base_url: instead of the actual URL.

How do I get the actual config value to be emitted?

like image 226
Matt Culbreth Avatar asked Apr 05 '12 14:04

Matt Culbreth


People also ask

Where is Sphinx configuration file?

The default configuration file is called sphinx. conf , usually located in /etc/sphinxsearch (Debian/Ubuntu), /etc/sphinx/sphinx. conf.

What is a conf py file?

The configuration directory must contain a file named conf.py . This file (containing Python code) is called the “build configuration file” and contains (almost) all configuration needed to customize Sphinx input and output behavior.


2 Answers

Ah hah!

Take a look at the sphinx.ext.extlinks module.

So I have code in my conf.py that does this:

extlinks = {'api_url' : (settings.BASE_URL + '%s', settings.BASE_URL)}

And in my .rst file, I have this:

:api_url:`/myapp/api/application/`

which produces the nicely formatted link as such:

http://localhost:8000/myapp/api/application/
like image 27
Matt Culbreth Avatar answered Oct 20 '22 03:10

Matt Culbreth


For the substitution of links extlinks is fine, for including arbitrary config values as asked in your question you can use rst_epilog for substitutions (or rst_prolog for text, that should be added on top of your .rst files):

In your conf.py:

my_config_value = 42
rst_epilog = '.. |my_conf_val| replace:: %d' % my_config_value

In your .rst source:

My config value is |my_conf_val|!

In your output:

My config value is 42!

like image 173
bmu Avatar answered Oct 20 '22 04:10

bmu