docs: add check_settings_consistency

This commit is contained in:
enkore 2015-06-05 13:24:08 +02:00
parent dbdf0a731b
commit 8a783004c5

View File

@ -29,6 +29,16 @@ def fail_on_missing_dependency_hints(obj, lines):
"> Requires the PyPI package ``colour``".format(obj.__name__)) "> Requires the PyPI package ``colour``".format(obj.__name__))
def check_settings_consistency(obj, settings):
errs = []
for setting in settings:
if not setting.required and setting.default is setting.sentinel:
errs.append("<" + setting.name + ">")
if errs:
raise ValueError(">>> Module <{}> has non-required setting(s) {} with no default! <<<\n"
.format(obj.__name__, ", ".join(errs)))
def process_docstring(app, what, name, obj, options, lines): def process_docstring(app, what, name, obj, options, lines):
class Setting: class Setting:
doc = "" doc = ""
@ -42,8 +52,7 @@ def process_docstring(app, what, name, obj, options, lines):
self.doc = setting[1] self.doc = setting[1]
else: else:
self.name = setting self.name = setting
if self.name in cls.required:
if setting in cls.required:
self.required = True self.required = True
elif hasattr(cls, self.name): elif hasattr(cls, self.name):
default = getattr(cls, self.name) default = getattr(cls, self.name)
@ -74,8 +83,11 @@ def process_docstring(app, what, name, obj, options, lines):
lines.append(".. rubric:: Settings") lines.append(".. rubric:: Settings")
lines.append("") lines.append("")
for setting in obj.settings: settings = [Setting(obj, setting) for setting in obj.settings]
lines.append(str(Setting(obj, setting)))
lines += map(str, settings)
check_settings_consistency(obj, settings)
lines.append("") lines.append("")