Merge pull request #5911 from tk0miya/refactor_versioning_method

env.set_versioning_method() allows callable object as a method
This commit is contained in:
Takeshi KOMIYA 2019-01-13 16:03:26 +09:00 committed by GitHub
commit efd5328c34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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 '