env.set_versioning_method() allows callable object as a method

This allows to add custom versioning method from extensions.
This commit is contained in:
Takeshi KOMIYA 2019-01-04 17:27:37 +09:00
parent 90b93dda33
commit 70647ccf2d

View File

@ -265,7 +265,7 @@ class BuildEnvironment:
self.settings.setdefault('smart_quotes', True)
def set_versioning_method(self, method, compare):
# type: (str, bool) -> None
# type: (Union[str, Callable], bool) -> None
"""This sets the doctree versioning method for this environment.
Versioning methods are a builder property; only builders with the same
@ -273,9 +273,13 @@ class BuildEnvironment:
raise an exception if the user tries to use an environment with an
incompatible versioning method.
"""
if callable(method):
condition = method
else:
if method not in versioning_conditions:
raise ValueError('invalid versioning method: %r' % method)
condition = versioning_conditions[method]
if self.versioning_condition not in (None, condition):
raise SphinxError(__('This environment is incompatible with the '
'selected builder, please choose another '