Hi,

As far as I know, there are no proper way to obtain build directory in 
conf.py.
But, as a adhoc way, you con obtain it through environment variables.

in Makefile:
    BUILDDIR      = _build
    export BUILDDIR

in conf.py:
    builddir = os.environ['BUILDDIR']
    jinja_contexts = { 
        'messages': json.load(open(os.path.join(builddir, 
"messages.json"))) 
    }

Thanks,
Takeshi KOMIYA

2016年9月9日金曜日 17時55分22秒 UTC+9 Markus Schöpflin:
>
> I am using the Jinja extension from sphinxcontrib. For this I have added 
> the 
> following to conf.py: 
>
>    extensions = ['sphinxcontrib.jinja'] 
>
>    import json 
>    jinja_contexts = { 
>        'messages': json.load(open("messages.json")) 
>    } 
>
> The file "messages.json" is created automatically during the build of the 
> project, before sphinx-build is called. The file is located in the build 
> directory of the project. 
>
> Now I'm struggling to refer to that file from conf.py, as the current 
> directory is set to the directory where conf.py is located (which is the 
> source directory of the project) when conf.py is loaded. 
>
> My workaround currently is to copy conf.py to the build directory and 
> execute 
> sphinx-build like so, with the current directory set to the build 
> directory: 
>
>    sphinx-build -b html -c . -d doctree '/.../source' html 
>
> Is there a way to avoid copying conf.py to the build directory first? E.g. 
> any 
> variable which holds the value of the directory where sphinx-build is 
> executed 
> in, which can be accessed from conf.py? 
>
> I also tried to add -D build_dir='/...' to sphinx-build in the hope that 
> maybe 
> this would make build_dir defined when conf.py is evaluated, but this is 
> not 
> the case. 
>
> TIA, Markus 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to