From b1a9ce122f7886ea0f21eb018b5c9f83859733d7 Mon Sep 17 00:00:00 2001 From: Mathieu Boespflug Date: Sun, 11 Feb 2018 12:43:53 +0100 Subject: [PATCH] Support attribute documentation via doc argument. Fixes #59. --- skydoc/rule_extractor_test.py | 35 +++++++++++++++++++ skydoc/stubs/attr.py | 64 +++++++++++++++++++++-------------- 2 files changed, 73 insertions(+), 26 deletions(-) diff --git a/skydoc/rule_extractor_test.py b/skydoc/rule_extractor_test.py index 911179a..d5e0c27 100644 --- a/skydoc/rule_extractor_test.py +++ b/skydoc/rule_extractor_test.py @@ -612,6 +612,41 @@ def _impl(repository_ctx): } """) + def test_doc_arg(self): + src = textwrap.dedent("""\ + def _impl(ctx): + return struct() + + rule_with_doc = rule( + implementation = _impl, + attrs = { + "foo": attr.string(doc = "Attribute documentation.") + }, + ) + \"\"\"A rule. + \"\"\" + """) + + expected = textwrap.dedent("""\ + rule { + name: "rule_with_doc" + documentation: "A rule." + attribute { + name: "name" + type: UNKNOWN + mandatory: true + } + attribute { + name: "foo" + type: STRING + mandatory: false + documentation: "Attribute documentation." + default: "\'\'" + } + type: RULE + } + """) + self.check_protos(src, expected) if __name__ == '__main__': diff --git a/skydoc/stubs/attr.py b/skydoc/stubs/attr.py index 7948761..8b8c10d 100644 --- a/skydoc/stubs/attr.py +++ b/skydoc/stubs/attr.py @@ -79,18 +79,18 @@ def compare_priority(self): return 0 -def bool(default=False, mandatory=False): +def bool(default=False, mandatory=False, doc=""): return AttrDescriptor( - build_pb2.Attribute.BOOLEAN, default=repr(default), mandatory=mandatory) + build_pb2.Attribute.BOOLEAN, default=repr(default), mandatory=mandatory, doc=doc) -def int(default=0, mandatory=False, values=[]): - return AttrDescriptor(build_pb2.Attribute.INTEGER, repr(default), mandatory) +def int(default=0, mandatory=False, values=[], doc=""): + return AttrDescriptor(build_pb2.Attribute.INTEGER, repr(default), mandatory, doc=doc) -def int_list(default=[], mandatory=False, non_empty=False, allow_empty=True): +def int_list(default=[], mandatory=False, non_empty=False, allow_empty=True, doc=""): return AttrDescriptor(build_pb2.Attribute.INTEGER_LIST, repr(default), - mandatory) + mandatory, doc) def label(default=None, @@ -102,10 +102,11 @@ def label(default=None, allow_rules=None, single_file=False, cfg=None, - aspects=[]): + aspects=[], + doc=""): if default != None: default = repr(default) - return AttrDescriptor(build_pb2.Attribute.LABEL, default, mandatory) + return AttrDescriptor(build_pb2.Attribute.LABEL, default, mandatory, doc) def label_list(default=[], @@ -117,59 +118,70 @@ def label_list(default=[], non_empty=False, allow_empty=True, cfg=None, - aspects=[]): + aspects=[], + doc=""): default_val = [] for label in default: default_val.append(repr(label)) return AttrDescriptor(build_pb2.Attribute.LABEL_LIST, repr(default_val), - mandatory) + mandatory, doc) -def license(default=None, mandatory=False): +def license(default=None, mandatory=False, doc=""): if default != None: default = repr(default) - return AttrDescriptor(build_pb2.Attribute.LICENSE, default, mandatory) + return AttrDescriptor(build_pb2.Attribute.LICENSE, default, mandatory, doc) -def output(default=None, mandatory=False): +def output(default=None, mandatory=False, doc=""): if default != None: default = repr(default) - return AttrDescriptor(build_pb2.Attribute.OUTPUT, default, mandatory) + return AttrDescriptor(build_pb2.Attribute.OUTPUT, default, mandatory, doc) -def output_list(default=[], mandatory=False, non_empty=False, allow_empty=True): +def output_list(default=[], mandatory=False, non_empty=False, allow_empty=True, doc=""): default_val = [] for label in default: default_val.append(repr(label)) return AttrDescriptor(build_pb2.Attribute.OUTPUT_LIST, repr(default_val), - mandatory) + mandatory, doc) -def string(default="", mandatory=False, values=[]): - return AttrDescriptor(build_pb2.Attribute.STRING, repr(default), mandatory) +def string(default="", mandatory=False, values=[], doc=""): + return AttrDescriptor(build_pb2.Attribute.STRING, repr(default), mandatory, doc) -def string_dict(default={}, mandatory=False, non_empty=False, allow_empty=True): +def string_dict(default={}, + mandatory=False, + non_empty=False, + allow_empty=True, + doc=""): return AttrDescriptor(build_pb2.Attribute.STRING_DICT, repr(default), - mandatory) + mandatory, doc) -def string_list(default=[], mandatory=False, non_empty=False, allow_empty=True): +def string_list(default=[], + mandatory=False, + non_empty=False, + allow_empty=True, + doc=""): return AttrDescriptor(build_pb2.Attribute.STRING_LIST, repr(default), - mandatory) + mandatory, doc) def string_list_dict(default={}, mandatory=False, non_empty=False, - allow_empty=True): + allow_empty=True, + doc=""): return AttrDescriptor(build_pb2.Attribute.STRING_LIST_DICT, repr(default), - mandatory) + mandatory, doc) def label_keyed_string_dict(default={}, mandatory=False, allow_files=False, non_empty=False, - allow_empty=True): + allow_empty=True, + doc=""): return AttrDescriptor(build_pb2.Attribute.LABEL_KEYED_STRING_DICT, repr(default), - mandatory) + mandatory, doc)