Environment variable documentation helpers
Any environment variables that are loaded using maykin_common.config.config(),
can be documented using the documentation helpers (unless add_to_docs is explicitly set to False).
Documentation per environment variable can be added by providing the documentation
parameter, which has the following attributes:
help_text: the description of the environment variable.group: the name of the group to list this environment variable under (defaults toRequiredif no default is specified, otherwiseOptional).add_to_docs: whether or not this environment variable should be included in the docs (defaultTrue)auto_display_default: whether or not the default specified to theconfighelper should be displayed in the documentation (defaultTrue)
from maykin_common.config_helpers import config, DocumentationParams
ALLOWED_HOSTS = config(
"ALLOWED_HOSTS",
default="",
split=True,
documentation=DocumentationParams(
help_text=(
"a comma separated (without spaces!) list of domains that serve "
"the installation. Used to protect against Host header attacks."
),
group="Required",
)
)
To exclude an environment variable from the documentation, the following shorthand can be used:
from maykin_common.config_helpers import config, no_doc
VARIABLE_TO_BE_EXCLUDED = config(
"VARIABLE_TO_BE_EXCLUDED",
default="",
documentation=no_doc
)
In order to document environment variables that are defined in this way, there are three Sphinx directives that can be used.
To document all groups of environment variables, the config-all-params directive
(maykin_common.documentation.config_directives.ConfigAllParamsDirective) can be used.
This directive accepts the following optional arguments:
members-groupsto only use the specified groupsexclude-groupsto exclude the specified groups (cannot be used together withmembers-groups)exclude-paramsto exclude the specified environment variables
Example usage:
.. config-all-params::
:exclude-groups: Celery, Database
To document a specific group of environment variables, the config-group directive
(maykin_common.documentation.config_directives.ConfigGroupDirective) can be used.
This directive accepts the following optional arguments:
membersto only use the specified environment variablesexcludeto exclude the specified environment variables (cannot be used together withmembers)
Example usage:
.. config-group:: Database
:exclude: DB_POOL_MAX_LIFETIME, DB_POOL_NUM_WORKERS
To document a single environment variable, the config-param directive
(maykin_common.documentation.config_directives.ConfigParamDirective) can be used.
This directive accepts the following optional arguments:
defaultto override the default as defined in the code
.. config-param:: DISABLE_2FA
:default: True