Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Support attribute documentation via doc argument. #85

Merged
merged 1 commit into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions skydoc/rule_extractor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
64 changes: 38 additions & 26 deletions skydoc/stubs/attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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=[],
Expand All @@ -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)