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) self.settings.setdefault('smart_quotes', True)
def set_versioning_method(self, method, compare): 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. """This sets the doctree versioning method for this environment.
Versioning methods are a builder property; only builders with the same 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 raise an exception if the user tries to use an environment with an
incompatible versioning method. incompatible versioning method.
""" """
if method not in versioning_conditions: if callable(method):
raise ValueError('invalid versioning method: %r' % method) condition = method
condition = versioning_conditions[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): if self.versioning_condition not in (None, condition):
raise SphinxError(__('This environment is incompatible with the ' raise SphinxError(__('This environment is incompatible with the '
'selected builder, please choose another ' 'selected builder, please choose another '