Re: [sphinx-dev] How to override values in conf.py by values read from a Settings.yml (YAML) file?
2012/7/23 Martin Bless m.bl...@gmx.de: 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? Quick and dirty: globals().update(read_my_dict_from_yaml()) Alternativel you can update the settings after Sphinx has parsed conf.py: def setup(app): for key, value in read_my_dict_from_yaml(): setattr(app.config, key, value) In other words: If in conf.py there is: html_theme = 'sphinx' k = 'html_theme' v = 'basictheme' Q: How do I write `k` = v? globals()[k] = v In other words: Q: How do I access the dictionary in conf.py that dir() queries? Use globals() within conf.py. globals() returns all names on module level, and the settings in conf.py are module-level names. 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? It works accidentally, because on module level locals() is equivalent to globals(). However, according to the documentation locals() returns a *independent* dictionary. Modifications to this dictionary are not guaranteed to propagate to the corresponding namespace. As said above, use globals(). -- 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.
[sphinx-dev] Re: How to override values in conf.py by values read from a Settings.yml (YAML) file?
Hello Takayuki, for k in more: exec(%s = %r % (k, more[k])) I see, this works. index.rst:: Welcome to conf.py test = :release: |release| :version: |version| That looked very promising at first sight - I was very excited. But it's restricted to three values only and no general solution. 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. Yes, your warning is more than apropriate. But as Sebastian points out, globals() can be used. Thanks for answering - it was really helpful. Martin -- Certified TYPO3 Integrator | TYPO3 Documentation Team Member 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.
[sphinx-dev] Re: How to override values in conf.py by values read from a Settings.yml (YAML) file?
Hi Sebastian, Quick and dirty: globals().update(read_my_dict_from_yaml()) Well, looks like it's even the right and clean solution in my case! Alternativel you can update the settings after Sphinx has parsed conf.py: def setup(app): for key, value in read_my_dict_from_yaml(): setattr(app.config, key, value) I see. But my code will be at the end of the conf.py, so globals() is the one. Use globals() within conf.py. globals() returns all names on module level, and the settings in conf.py are module-level names. Yes, that's the important information I had been looking for. Couldn't remember ... Ah, I'm relieved: I have peace in my mind again knowing better about globals(), locals(), setattr(). Q: One question is left: Is there secret attribute for a module like __dict__ that returns the same dictionary as globals()? Martin -- Certified TYPO3 Integrator | TYPO3 Documentation Team Member 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.
Re: [sphinx-dev] Contributions in TODO, autodoc and general
On Wed, Jul 25, 2012 at 12:58 AM, Kevin Hunter hunt...@gmail.com wrote: Without directions suggesting otherwise, here's my best guess at how best to contribute: submit a pull request[2] on bitbucket.org. The main repository behind Sphinx:: https://bitbucket.org/**birkenfeld/sphinxhttps://bitbucket.org/birkenfeld/sphinx Cheers, Kevin That would be my suggestion as well. Kevin Horn -- 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.