diff --git a/autoapi/base.py b/autoapi/base.py index 84d4129..180e066 100644 --- a/autoapi/base.py +++ b/autoapi/base.py @@ -130,7 +130,8 @@ class AutoAPIDomain(object): data = self.read_file(path, format=format) if data: obj = self.create_class(data) - self.add_object(obj) + if obj is not None: + self.add_object(obj) def create_class(self, obj): ''' diff --git a/autoapi/domains/go.py b/autoapi/domains/go.py index c44cf93..3952f3f 100644 --- a/autoapi/domains/go.py +++ b/autoapi/domains/go.py @@ -35,7 +35,7 @@ class GoDomain(AutoAPIDomain): # print Warning('Error reading file: {0}'.format(path)) # return None - def create_class(self, data, _type=None): + def create_class(self, data): '''Return instance of class based on Go data Data keys handled here: @@ -47,54 +47,30 @@ class GoDomain(AutoAPIDomain): Recurse into :py:meth:`create_class` to create child object instances - :param data: dictionary data from Roslyn output artifact + :param data: dictionary data from godocjson output ''' # TODO replace this with a global mapping classes = [GoConstant, GoFunction, GoPackage, GoVariable, GoType, GoMethod] obj = None - if not _type: - _type = data.get('type', '').lower() + _type = data.get('type', None) + if _type is None or not _type: + self.app.warn('Missing type: %s' % data) for cls in classes: if _type == cls.type.lower(): obj = cls(data) - if not obj: - print "Unknown Type: %s" % data + if obj is None: + self.app.warn('Unknown Type: %s' % data) + return obj for child_type in ['consts', 'types', 'vars', 'funcs']: - # if child_type == 'consts' or child_type == 'vars': - # iter_data = [] - # for inner_data in data.get(child_type, []): - # for name in inner_data.get('name', []) - # del inner_data['doc'] - # iter_data.append({ - # 'name': name, - # **inner_data - # }) - # else: - iter_data = data.get(child_type, []) - for obj_data in iter_data: - child_obj = self.create_class(obj_data, _type=child_type.replace('consts', 'const').replace('types', 'type').replace('vars', 'variable').replace('funcs', 'func')) - obj.children.append(child_obj) - obj.item_map[child_obj.type].append(child_obj) + for child_data in data.get(child_type, []): + child_obj = self.create_class(child_data) + if child_obj is not None: + obj.children.append(child_obj) return obj - def organize_objects(self): - '''Organize objects and namespaces''' - - # Add all objects to the item_map - for obj in self.objects.values(): - for child in obj.children: - child_object = self.objects.get(child) - if child_object: - obj.children.append(child_object) - # for key in obj.item_map: - # obj.item_map[key].sort() - def full(self): - print "Reading" self.get_objects(self.get_config('autoapi_file_pattern'), format='json') - # self.organize_objects() - print "Writing" self.generate_output() self.write_indexes() @@ -134,16 +110,8 @@ class GoBase(AutoAPIBase): def __init__(self, obj): super(GoBase, self).__init__(obj) - # Always exist - #self.id = obj['import_path'] - try: - self.name = obj['name'] - except: - self.name = obj['packageName'] - try: - self.id = obj['packageImportPath'] - except: - self.id = self.name + self.name = obj.get('name') or obj.get('packageName') + self.id = obj.get('packageImportPath') or self.name # Second level self.imports = obj.get('imports', []) @@ -156,9 +124,6 @@ class GoBase(AutoAPIBase): self.filenames = obj.get('filenames', []) self.bugs = obj.get('bugs', []) - # For later - self.item_map = defaultdict(list) - def __str__(self): return '<{cls} {id}>'.format(cls=self.__class__.__name__, id=self.id) @@ -186,14 +151,20 @@ class GoBase(AutoAPIBase): def methods(self): return self.obj.get('methods', []) + def __lt__(self, other): + '''Sort object by name''' + if isinstance(other, GoBase): + return self.name.lower() < other.name.lower() + return self.name < other + class GoVariable(GoBase): - type = 'variable' - ref_type = 'var' + type = 'var' class GoMethod(GoBase): type = 'method' + ref_directive = 'meth' class GoConstant(GoBase): @@ -207,6 +178,7 @@ class GoFunction(GoBase): class GoPackage(GoBase): type = 'package' + ref_directive = 'pkg' class GoType(GoBase): diff --git a/autoapi/templates/go/base_member.rst b/autoapi/templates/go/base_member.rst index e481ab7..f7523db 100644 --- a/autoapi/templates/go/base_member.rst +++ b/autoapi/templates/go/base_member.rst @@ -1,8 +1,8 @@ .. go:{{ obj.ref_type }}:: {{ obj.name }} - {% macro render() %}{{ obj.docstring }}{% endmacro %} - {{ render()|indent(8) }} - + {% macro render() %}{{ obj.docstring }}{% endmacro %} + {{ render()|indent(4) }} + {%- for param in obj.parameters %} :param {{ param.name }}: {{ param.desc }} {%- if param.type %} diff --git a/autoapi/templates/go/func.rst b/autoapi/templates/go/func.rst deleted file mode 120000 index b641e61..0000000 --- a/autoapi/templates/go/func.rst +++ /dev/null @@ -1 +0,0 @@ -function.rst \ No newline at end of file diff --git a/autoapi/templates/go/func.rst b/autoapi/templates/go/func.rst new file mode 100644 index 0000000..0466355 --- /dev/null +++ b/autoapi/templates/go/func.rst @@ -0,0 +1 @@ +{% extends "go/base_member.rst" %} diff --git a/autoapi/templates/go/function.rst b/autoapi/templates/go/function.rst deleted file mode 100644 index 0466355..0000000 --- a/autoapi/templates/go/function.rst +++ /dev/null @@ -1 +0,0 @@ -{% extends "go/base_member.rst" %} diff --git a/autoapi/templates/go/package.rst b/autoapi/templates/go/package.rst index 67b82dd..f0dee41 100644 --- a/autoapi/templates/go/package.rst +++ b/autoapi/templates/go/package.rst @@ -6,12 +6,14 @@ {% block toc %} {%- if obj.children %} +{# TODO Make this work .. toctree:: :maxdepth: 4 {% for item in obj.children|sort %} /autoapi/{{ item.id.split('.')|join('/') }}/index {%- endfor %} +#} {%- endif %} {% endblock %} @@ -21,10 +23,10 @@ {% endif %} {% block content %} -{%- for obj_item in obj.children %} + {%- for obj_item in obj.children|sort %} {% macro render() %}{{ obj_item.render() }}{% endmacro %} {{ render()|indent(0) }} -{%- endfor %} + {%- endfor %} {% endblock %} diff --git a/autoapi/templates/go/variable.rst b/autoapi/templates/go/variable.rst deleted file mode 120000 index 62a4af0..0000000 --- a/autoapi/templates/go/variable.rst +++ /dev/null @@ -1 +0,0 @@ -var.rst \ No newline at end of file