Hello everybody,

maybe there is an obvious solution - but I just don't see it.

At the end of 'conf.py' I want to read and parse an additional
'Settings.yml' configuration file and add those settings to what we
already have in 'conf.py'. If present settings from the YAML file
should take precedence. So I need a way to programmatically define
settings like those in the lines of conf.py. For example:
    html_theme = 'sphinx'

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?


In other words: 
If in conf.py there is:
   html_theme = 'sphinx'
   k = 'html_theme'
   v = 'basictheme'

Q: How do I write `k` = v?


In other words:
Q: How do I access the dictionary in conf.py that dir() queries?


This does not work:
   _dict_[k] = v

This does not work 
because it turns out that '__name__' has the value '__builtins__':
   sys.modules[__name__].__dict__[k] = v


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?


... all the best ...

Martin

-- 
http://mbless.de




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

Reply via email to