Hi Martin,

2012/7/23 Martin Bless <[email protected]>:
> So what I need is something like this:
>
>     ## conf.py:
>     # ...
>     # normal settings ...
>     # ...
>     more = parse_yaml() # return a dictionary
>     for k in more.keys():
>         # now I'd like to add
>         ((k)) = more[k]
>        # where ((k)) should be a variable in the conf.py namespace.
>
> Q: How do I do that?

conf.py is loaded into the Sphinx by execfile() function [1].
Therefore, there is no dictionary object of conf.py module.

[1] Sphinx-1.1 series is using another code equivalent to the execfile().

I made a minimum working sample.

   ## conf.py:
   # ...
   # normal settings ...
   # ...
   version = release = '1.0'

   more = {'release': 'foo', 'version': 'bar'}  # parse_yaml() #
return a dictionary
   for k in more:
       exec("%s = %r" % (k, more[k]))


index.rst::

   Welcome to conf.py test
   =========================

   :release: |release|
   :version: |version|


and generated index.txt by `make text`::

   Welcome to conf.py test
   ***********************

   release:
      foo

   version:
      bar


> I just found that this seems to work:
>    html_theme = 'sphinx'
>    k = 'html_theme'
>    v = 'basictheme'
>    L = locals()
>    L[k] = v
>    print html_theme # -> gives 'basictheme'
>
> Q: Is that the right and best way to do this?

Hmm.., there is no guarantee that code will always work.

   http://docs.python.org/library/functions.html#locals
   The contents of this dictionary should not be modified; changes may
   not affect the values of local and free variables used by the interpreter.

Best regards.
-- 
Takayuki SHIMIZUKAWA
Sphinx-users.jp

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.

Reply via email to