This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add function try_add_config_value for sphinx
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
@file | ||
@brief Helpers for sphinx extensions. | ||
.. versionadded:: 1.5 | ||
""" | ||
|
||
|
||
def try_add_config_value(app, name, default, rebuild, types_=()): | ||
""" | ||
Add a variables in the config file if it does not have it yet. | ||
@param app Sphinx application | ||
@param name name of the variable | ||
@param default default value | ||
@param rebuild see below | ||
@param types_ expected types | ||
@return True if added, False if already present. | ||
Rebuild can be (source: `Sphinx <http://www.sphinx-doc.org/en/stable/extdev/appapi.html#sphinx.application.Sphinx.add_config_value>`_): | ||
* 'env' if a change in the setting only takes effect when a document | ||
is parsed - this means that the whole environment must be rebuilt. | ||
* 'html' if a change in the setting needs a full rebuild of HTML documents. | ||
* '' if a change in the setting will not need any special rebuild. | ||
""" | ||
if name in app.config: | ||
return False | ||
help(app.add_config_value) | ||
app.add_config_value(name, default, rebuild, types_) | ||
return True |