mirror of
https://github.com/readthedocs/sphinx-autoapi
synced 2024-11-19 15:25:31 +00:00
Clean up cruft and handle a few failures better
This commit is contained in:
parent
3653636673
commit
8819b46a2f
@ -130,6 +130,7 @@ class AutoAPIDomain(object):
|
|||||||
data = self.read_file(path, format=format)
|
data = self.read_file(path, format=format)
|
||||||
if data:
|
if data:
|
||||||
obj = self.create_class(data)
|
obj = self.create_class(data)
|
||||||
|
if obj is not None:
|
||||||
self.add_object(obj)
|
self.add_object(obj)
|
||||||
|
|
||||||
def create_class(self, obj):
|
def create_class(self, obj):
|
||||||
|
@ -35,7 +35,7 @@ class GoDomain(AutoAPIDomain):
|
|||||||
# print Warning('Error reading file: {0}'.format(path))
|
# print Warning('Error reading file: {0}'.format(path))
|
||||||
# return None
|
# return None
|
||||||
|
|
||||||
def create_class(self, data, _type=None):
|
def create_class(self, data):
|
||||||
'''Return instance of class based on Go data
|
'''Return instance of class based on Go data
|
||||||
|
|
||||||
Data keys handled here:
|
Data keys handled here:
|
||||||
@ -47,54 +47,30 @@ class GoDomain(AutoAPIDomain):
|
|||||||
Recurse into :py:meth:`create_class` to create child object
|
Recurse into :py:meth:`create_class` to create child object
|
||||||
instances
|
instances
|
||||||
|
|
||||||
:param data: dictionary data from Roslyn output artifact
|
:param data: dictionary data from godocjson output
|
||||||
'''
|
'''
|
||||||
# TODO replace this with a global mapping
|
# TODO replace this with a global mapping
|
||||||
classes = [GoConstant, GoFunction, GoPackage, GoVariable, GoType, GoMethod]
|
classes = [GoConstant, GoFunction, GoPackage, GoVariable, GoType, GoMethod]
|
||||||
obj = None
|
obj = None
|
||||||
if not _type:
|
_type = data.get('type', None)
|
||||||
_type = data.get('type', '').lower()
|
if _type is None or not _type:
|
||||||
|
self.app.warn('Missing type: %s' % data)
|
||||||
for cls in classes:
|
for cls in classes:
|
||||||
if _type == cls.type.lower():
|
if _type == cls.type.lower():
|
||||||
obj = cls(data)
|
obj = cls(data)
|
||||||
if not obj:
|
if obj is None:
|
||||||
print "Unknown Type: %s" % data
|
self.app.warn('Unknown Type: %s' % data)
|
||||||
|
|
||||||
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)
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def organize_objects(self):
|
for child_type in ['consts', 'types', 'vars', 'funcs']:
|
||||||
'''Organize objects and namespaces'''
|
for child_data in data.get(child_type, []):
|
||||||
|
child_obj = self.create_class(child_data)
|
||||||
# Add all objects to the item_map
|
if child_obj is not None:
|
||||||
for obj in self.objects.values():
|
obj.children.append(child_obj)
|
||||||
for child in obj.children:
|
return obj
|
||||||
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):
|
def full(self):
|
||||||
print "Reading"
|
|
||||||
self.get_objects(self.get_config('autoapi_file_pattern'), format='json')
|
self.get_objects(self.get_config('autoapi_file_pattern'), format='json')
|
||||||
# self.organize_objects()
|
|
||||||
print "Writing"
|
|
||||||
self.generate_output()
|
self.generate_output()
|
||||||
self.write_indexes()
|
self.write_indexes()
|
||||||
|
|
||||||
@ -134,16 +110,8 @@ class GoBase(AutoAPIBase):
|
|||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
super(GoBase, self).__init__(obj)
|
super(GoBase, self).__init__(obj)
|
||||||
# Always exist
|
self.name = obj.get('name') or obj.get('packageName')
|
||||||
#self.id = obj['import_path']
|
self.id = obj.get('packageImportPath') or self.name
|
||||||
try:
|
|
||||||
self.name = obj['name']
|
|
||||||
except:
|
|
||||||
self.name = obj['packageName']
|
|
||||||
try:
|
|
||||||
self.id = obj['packageImportPath']
|
|
||||||
except:
|
|
||||||
self.id = self.name
|
|
||||||
|
|
||||||
# Second level
|
# Second level
|
||||||
self.imports = obj.get('imports', [])
|
self.imports = obj.get('imports', [])
|
||||||
@ -156,9 +124,6 @@ class GoBase(AutoAPIBase):
|
|||||||
self.filenames = obj.get('filenames', [])
|
self.filenames = obj.get('filenames', [])
|
||||||
self.bugs = obj.get('bugs', [])
|
self.bugs = obj.get('bugs', [])
|
||||||
|
|
||||||
# For later
|
|
||||||
self.item_map = defaultdict(list)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '<{cls} {id}>'.format(cls=self.__class__.__name__,
|
return '<{cls} {id}>'.format(cls=self.__class__.__name__,
|
||||||
id=self.id)
|
id=self.id)
|
||||||
@ -186,14 +151,20 @@ class GoBase(AutoAPIBase):
|
|||||||
def methods(self):
|
def methods(self):
|
||||||
return self.obj.get('methods', [])
|
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):
|
class GoVariable(GoBase):
|
||||||
type = 'variable'
|
type = 'var'
|
||||||
ref_type = 'var'
|
|
||||||
|
|
||||||
|
|
||||||
class GoMethod(GoBase):
|
class GoMethod(GoBase):
|
||||||
type = 'method'
|
type = 'method'
|
||||||
|
ref_directive = 'meth'
|
||||||
|
|
||||||
|
|
||||||
class GoConstant(GoBase):
|
class GoConstant(GoBase):
|
||||||
@ -207,6 +178,7 @@ class GoFunction(GoBase):
|
|||||||
|
|
||||||
class GoPackage(GoBase):
|
class GoPackage(GoBase):
|
||||||
type = 'package'
|
type = 'package'
|
||||||
|
ref_directive = 'pkg'
|
||||||
|
|
||||||
|
|
||||||
class GoType(GoBase):
|
class GoType(GoBase):
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
.. go:{{ obj.ref_type }}:: {{ obj.name }}
|
.. go:{{ obj.ref_type }}:: {{ obj.name }}
|
||||||
|
|
||||||
{% macro render() %}{{ obj.docstring }}{% endmacro %}
|
{% macro render() %}{{ obj.docstring }}{% endmacro %}
|
||||||
{{ render()|indent(8) }}
|
{{ render()|indent(4) }}
|
||||||
|
|
||||||
{%- for param in obj.parameters %}
|
{%- for param in obj.parameters %}
|
||||||
:param {{ param.name }}: {{ param.desc }}
|
:param {{ param.name }}: {{ param.desc }}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
function.rst
|
|
1
autoapi/templates/go/func.rst
Normal file
1
autoapi/templates/go/func.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
{% extends "go/base_member.rst" %}
|
@ -1 +0,0 @@
|
|||||||
{% extends "go/base_member.rst" %}
|
|
@ -6,12 +6,14 @@
|
|||||||
{% block toc %}
|
{% block toc %}
|
||||||
{%- if obj.children %}
|
{%- if obj.children %}
|
||||||
|
|
||||||
|
{# TODO Make this work
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 4
|
:maxdepth: 4
|
||||||
|
|
||||||
{% for item in obj.children|sort %}
|
{% for item in obj.children|sort %}
|
||||||
/autoapi/{{ item.id.split('.')|join('/') }}/index
|
/autoapi/{{ item.id.split('.')|join('/') }}/index
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
#}
|
||||||
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -21,7 +23,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{%- for obj_item in obj.children %}
|
{%- for obj_item in obj.children|sort %}
|
||||||
|
|
||||||
{% macro render() %}{{ obj_item.render() }}{% endmacro %}
|
{% macro render() %}{{ obj_item.render() }}{% endmacro %}
|
||||||
{{ render()|indent(0) }}
|
{{ render()|indent(0) }}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
var.rst
|
|
Loading…
Reference in New Issue
Block a user