py2docfx 0.1.0.dev1524902__py3-none-any.whl → 0.1.0.dev1529344__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py2docfx/convert_prepare/git.py +1 -1
- py2docfx/docfx_yaml/parameter_utils.py +0 -24
- py2docfx/docfx_yaml/translator.py +22 -16
- {py2docfx-0.1.0.dev1524902.dist-info → py2docfx-0.1.0.dev1529344.dist-info}/METADATA +1 -1
- {py2docfx-0.1.0.dev1524902.dist-info → py2docfx-0.1.0.dev1529344.dist-info}/RECORD +7 -14
- py2docfx/docfx_yaml/return_type_utils.py +0 -165
- py2docfx/docfx_yaml/tests/roots/test-translator-returns/code_with_returns_numpy.py +0 -37
- py2docfx/docfx_yaml/tests/roots/test-translator-returns/code_with_returns_rst.py +0 -29
- py2docfx/docfx_yaml/tests/roots/test-translator-returns/conf.py +0 -24
- py2docfx/docfx_yaml/tests/roots/test-translator-returns/refered_objects.py +0 -5
- py2docfx/docfx_yaml/tests/test_translator_numpy_returns.py +0 -81
- py2docfx/docfx_yaml/tests/test_translator_rst_returns.py +0 -81
- {py2docfx-0.1.0.dev1524902.dist-info → py2docfx-0.1.0.dev1529344.dist-info}/WHEEL +0 -0
- {py2docfx-0.1.0.dev1524902.dist-info → py2docfx-0.1.0.dev1529344.dist-info}/top_level.txt +0 -0
py2docfx/convert_prepare/git.py
CHANGED
@@ -7,30 +7,6 @@ from inspect import isclass
|
|
7
7
|
TYPE_SEP_PATTERN = '(\[|\]|, |\(|\))'
|
8
8
|
PARAMETER_NAME = "[*][*](.*?)[*][*]"
|
9
9
|
PARAMETER_TYPE = "[(]((?:.|\n)*)[)]"
|
10
|
-
SYSTEM_TYPE = "system type"
|
11
|
-
TYPING_TYPE = "typing type"
|
12
|
-
SUPPLEMENT_TYPE = "supplement type"
|
13
|
-
|
14
|
-
def get_builtin_type_dict():
|
15
|
-
system_type_list = []
|
16
|
-
# loop through the attributes of the builtins module to get builtin types list
|
17
|
-
for attr in dir(builtins):
|
18
|
-
value = getattr(builtins, attr)
|
19
|
-
if isinstance(value, type):
|
20
|
-
system_type_list.append(value.__name__)
|
21
|
-
|
22
|
-
# get typing types list
|
23
|
-
typing_type_list = typing.__all__
|
24
|
-
|
25
|
-
type_dict = {}
|
26
|
-
for item in system_type_list:
|
27
|
-
type_dict[item] = SYSTEM_TYPE
|
28
|
-
for item in typing_type_list:
|
29
|
-
type_dict[item] = TYPING_TYPE
|
30
|
-
|
31
|
-
return type_dict
|
32
|
-
|
33
|
-
builtin_type_dict = get_builtin_type_dict()
|
34
10
|
|
35
11
|
def make_param(_id, _description, _type=None, _default_value=None, _required=None):
|
36
12
|
ret = {}
|
@@ -6,7 +6,6 @@
|
|
6
6
|
|
7
7
|
import re
|
8
8
|
import parameter_utils
|
9
|
-
import return_type_utils
|
10
9
|
|
11
10
|
from docutils import nodes
|
12
11
|
from sphinx import addnodes
|
@@ -29,8 +28,6 @@ def translator(app, docname, doctree):
|
|
29
28
|
|
30
29
|
transform_node = app.docfx_transform_node
|
31
30
|
|
32
|
-
class_obj_cache = app.env.domains['py'].objects
|
33
|
-
|
34
31
|
def _remove_exception_xref_tag(exception_type):
|
35
32
|
exception_type = exception_type.replace('<xref:', '')
|
36
33
|
exception_type = exception_type.replace('>', '')
|
@@ -70,7 +67,7 @@ def translator(app, docname, doctree):
|
|
70
67
|
|
71
68
|
uid = '{module}.{full_name}'.format(module=module, full_name=full_name)
|
72
69
|
type = node.get('desctype')
|
73
|
-
return (uid,
|
70
|
+
return (uid, type)
|
74
71
|
|
75
72
|
def _is_desc_of_enum_class(content_child):
|
76
73
|
assert content_child.tagname == 'desc_content'
|
@@ -120,7 +117,7 @@ def translator(app, docname, doctree):
|
|
120
117
|
exception['description'] = exception['description'].strip(" ")
|
121
118
|
return extractedExceptions
|
122
119
|
|
123
|
-
def _get_full_data(node
|
120
|
+
def _get_full_data(node):
|
124
121
|
data = {
|
125
122
|
'parameters': [],
|
126
123
|
'variables': [],
|
@@ -157,9 +154,18 @@ def translator(app, docname, doctree):
|
|
157
154
|
|
158
155
|
if fieldtype in ['Return']:
|
159
156
|
for returntype_node in content:
|
160
|
-
|
161
|
-
|
162
|
-
|
157
|
+
returntype_ret = transform_node(returntype_node)
|
158
|
+
if returntype_ret:
|
159
|
+
for returntype in re.split('[ \n]or[ \n]', returntype_ret):
|
160
|
+
returntype = returntype.strip(" \n\r\t")
|
161
|
+
_type_without_xref = returntype.replace('<xref:', '')
|
162
|
+
_type_without_xref = _type_without_xref.replace('>', '')
|
163
|
+
_type_without_xref, _added_reference = parameter_utils.resolve_type(_type_without_xref)
|
164
|
+
if _added_reference:
|
165
|
+
returntype = parameter_utils.resolve_xref_type(_added_reference)
|
166
|
+
if returntype.find('<xref:') == -1:
|
167
|
+
returntype = '<xref:' + returntype + '>'
|
168
|
+
data['return'].setdefault('type', []).append(returntype)
|
163
169
|
|
164
170
|
if fieldtype in ['Parameters', 'Variables', 'Keyword']:
|
165
171
|
if _is_single_paragraph(fieldbody):
|
@@ -215,7 +221,7 @@ def translator(app, docname, doctree):
|
|
215
221
|
raise Exception('First child of attribute node isn\'t content, node: {0}'.format(node.astext()))
|
216
222
|
return content_child
|
217
223
|
|
218
|
-
def extract_attribute(node, class_nodes
|
224
|
+
def extract_attribute(node, class_nodes):
|
219
225
|
def find_ancestor_class_content_node(node_class, node_module, node_ids, class_nodes):
|
220
226
|
for class_node in class_nodes:
|
221
227
|
if isinstance(class_node.children[0], desc_signature):
|
@@ -291,7 +297,7 @@ def translator(app, docname, doctree):
|
|
291
297
|
# if we need to change other attribute generator logic,
|
292
298
|
# better to get from extracted_content_data below too
|
293
299
|
|
294
|
-
extracted_content_data = extract_content(content_child, ATTRIBUTE_TYPE
|
300
|
+
extracted_content_data = extract_content(content_child, ATTRIBUTE_TYPE)
|
295
301
|
if not addedData:
|
296
302
|
# If current attribute doesn't have correct signature child, fill in basic information
|
297
303
|
# TODO: append fullName here, currently when fallback to here,
|
@@ -362,7 +368,7 @@ def translator(app, docname, doctree):
|
|
362
368
|
signature += '()'
|
363
369
|
return signature
|
364
370
|
|
365
|
-
def extract_content(node, api_type
|
371
|
+
def extract_content(node, api_type):
|
366
372
|
def merge_field_list_data(api_type, current_data, field_list_data):
|
367
373
|
# If node is a class node and autoclass=both, class docstring params are first, __init__ docstring params come second.
|
368
374
|
# If class hasn't init, the second param list will come from inherit base class
|
@@ -384,7 +390,7 @@ def translator(app, docname, doctree):
|
|
384
390
|
remarks_string = transform_node(child)
|
385
391
|
data['remarks'] = remarks_string
|
386
392
|
elif isinstance(child, nodes.field_list):
|
387
|
-
merge_field_list_data(api_type, data, _get_full_data(child
|
393
|
+
merge_field_list_data(api_type, data, _get_full_data(child))
|
388
394
|
elif isinstance(child, addnodes.seealso):
|
389
395
|
data['seealso'] = transform_node(child)
|
390
396
|
elif isinstance(child, nodes.admonition) and 'Example' in child[0].astext():
|
@@ -430,8 +436,8 @@ def translator(app, docname, doctree):
|
|
430
436
|
class_nodes = extract_class_nodes_from_doctree(doctree)
|
431
437
|
class_added_attributes = {}
|
432
438
|
class_data = {}
|
433
|
-
for node in doctree.traverse(addnodes.desc):
|
434
|
-
(uid,
|
439
|
+
for node in doctree.traverse(addnodes.desc):
|
440
|
+
(uid, node_type) = _get_uid_and_type_from_desc(node)
|
435
441
|
data = {}
|
436
442
|
signature_child = node.children[node.first_child_matching_class(addnodes.desc_signature)]
|
437
443
|
content_child = node.children[node.first_child_matching_class(addnodes.desc_content)]
|
@@ -447,7 +453,7 @@ def translator(app, docname, doctree):
|
|
447
453
|
attribute_class = attribute_sig_child['module'] + '.' + attribute_sig_child['class']
|
448
454
|
class_added_attributes.setdefault(attribute_class, OrderedDict())
|
449
455
|
# TODO: Merge attribute_data if same uid
|
450
|
-
attribute_data = extract_attribute(node, class_nodes
|
456
|
+
attribute_data = extract_attribute(node, class_nodes)
|
451
457
|
|
452
458
|
#Check if attribute information is already added
|
453
459
|
if attribute_data['uid'] in class_added_attributes[attribute_class].keys():
|
@@ -463,7 +469,7 @@ def translator(app, docname, doctree):
|
|
463
469
|
raise Exception('Attribute doesn\'t have class information. Attribute_name: {0}'.format(attribute_sig_child['fullname']))
|
464
470
|
continue
|
465
471
|
|
466
|
-
data.update(extract_content(content_child, node_type
|
472
|
+
data.update(extract_content(content_child, node_type))
|
467
473
|
data['content'] = extract_signature(signature_child)
|
468
474
|
|
469
475
|
data['type'] = type_mapping(node_type) if node_type else 'unknown'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: py2docfx
|
3
|
-
Version: 0.1.0.
|
3
|
+
Version: 0.1.0.dev1529344
|
4
4
|
Summary: A package built based on Sphinx which download source code package and generate yaml files supported by docfx.
|
5
5
|
Author: Microsoft Corporation
|
6
6
|
License: MIT License
|
@@ -5,7 +5,7 @@ py2docfx/convert_prepare/environment.py,sha256=AwS4c4OSwVdxlExBLVo310HrVhFMhWQ2W
|
|
5
5
|
py2docfx/convert_prepare/generate_conf.py,sha256=wqs6iyElzJarH-20_qEL9zvZvt5xfBMsGXSXPSZy6wg,2295
|
6
6
|
py2docfx/convert_prepare/generate_document.py,sha256=sppAAAgpZVtsXvO5M5EEOR39JeRyJk5ie3Kh9z27PrA,2350
|
7
7
|
py2docfx/convert_prepare/get_source.py,sha256=1XOdFABdzhmSld8-w72gaOQv8_xaUX7_VnFiSmvh3cc,4592
|
8
|
-
py2docfx/convert_prepare/git.py,sha256=
|
8
|
+
py2docfx/convert_prepare/git.py,sha256=t79gy_XyC3dwWbCi-YpZOQWwCbrim46yHL_-Z_Og38w,5640
|
9
9
|
py2docfx/convert_prepare/install_package.py,sha256=hATmgazcSX7k2n4jQXh9sQMyNUc1k1YqHv5K5UMALq4,262
|
10
10
|
py2docfx/convert_prepare/pack.py,sha256=vZS67_GzEhUmZWHU1dxm8gnWyRBs-kB6-KjX1d_FdOU,1260
|
11
11
|
py2docfx/convert_prepare/package_info.py,sha256=RCN3enfwXeU_9H8xBHLalvbhUrGxMtmlX0F9omGoPjU,6856
|
@@ -62,11 +62,10 @@ py2docfx/docfx_yaml/convert_package.py,sha256=R8dTHQXjoztHQ3bkBBchPx0k179IVr_e71
|
|
62
62
|
py2docfx/docfx_yaml/directives.py,sha256=zVVuNM_6AU9G6sbqL1UAyHHgPe7bkBWbthXI-PO5ez0,879
|
63
63
|
py2docfx/docfx_yaml/miss_reference.py,sha256=Btoj9wAvA4u_wU7JHH0Cei3910N8a7MS34OUqJvXAd4,2443
|
64
64
|
py2docfx/docfx_yaml/nodes.py,sha256=tBDi35jLJArlobl07DKOkmH2qz7dudXLp_kTUfR_r2w,412
|
65
|
-
py2docfx/docfx_yaml/parameter_utils.py,sha256=
|
65
|
+
py2docfx/docfx_yaml/parameter_utils.py,sha256=jj1TE-SbZt5KS-8WMzqysfXGDFX-WnSZOT3Ia_2dklQ,8025
|
66
66
|
py2docfx/docfx_yaml/process_doctree.py,sha256=iKs1fsyo-1_P3RzpZBzD8G9hcOTGO78esWNZLXvSx2g,14866
|
67
|
-
py2docfx/docfx_yaml/return_type_utils.py,sha256=nmdCUOvwdYk2jF6RqmOvU6gjXmXUTPUeCqyHPdKZNUQ,7483
|
68
67
|
py2docfx/docfx_yaml/settings.py,sha256=JQZNwFebczl-zn8Yk2taAGANRi-Hw8hywtDWxqXXFyQ,373
|
69
|
-
py2docfx/docfx_yaml/translator.py,sha256=
|
68
|
+
py2docfx/docfx_yaml/translator.py,sha256=k5D80ulmgm3QB-aLfk7dbeeO1iYxxhBkVJn8-cafMzg,25863
|
70
69
|
py2docfx/docfx_yaml/utils.py,sha256=m5jC_qP2NKqzUx_z0zgZ-HAmxQdNTpJYKkL_F9vGeII,1555
|
71
70
|
py2docfx/docfx_yaml/writer.py,sha256=0ZqyVGDHa4Cr3NsuOPRf4pGUStl6g6IBxpSgIZeDT9I,34683
|
72
71
|
py2docfx/docfx_yaml/yaml_builder.py,sha256=qSxXVS4iFCc1ZdL5QzLrv8hy3LHIQCrhO4WcTp01vag,2575
|
@@ -78,8 +77,6 @@ py2docfx/docfx_yaml/tests/test_translator_contents.py,sha256=lVCWbBIQk2oPFqsKK9g
|
|
78
77
|
py2docfx/docfx_yaml/tests/test_translator_data.py,sha256=zSVs3AT_TeAx1mrEYNTpy3Xy-FPrwwi93ly2EFclw5U,984
|
79
78
|
py2docfx/docfx_yaml/tests/test_translator_exceptions.py,sha256=A2zAcJOBGchDBNIDr15uD3lzLfVldJKYSAl0e1CD5Ds,10481
|
80
79
|
py2docfx/docfx_yaml/tests/test_translator_fieldlists.py,sha256=tDJ1l0c16oYfAlEIcidqEMwaXcX83Fg-rajpLtb2Wnk,1198
|
81
|
-
py2docfx/docfx_yaml/tests/test_translator_numpy_returns.py,sha256=nmC70WUqCRcB1tkRG9iq8mBuIcZKwGhK09StEvq0zf8,2970
|
82
|
-
py2docfx/docfx_yaml/tests/test_translator_rst_returns.py,sha256=BL3nOMMTPzNPJk-P9oMANiXnJ7ocuiecbFHH4DU1n40,2942
|
83
80
|
py2docfx/docfx_yaml/tests/test_translator_signatures.py,sha256=DM51EOb4UXLkrO1-4cQQQvvX210goAsnxKJH-4A2U2Q,1537
|
84
81
|
py2docfx/docfx_yaml/tests/test_writer_table.py,sha256=UnGYXQ-QVxin_e-HGZAHdg1LSFV0qc480ZNsqPN9OYc,1444
|
85
82
|
py2docfx/docfx_yaml/tests/test_writer_uri.py,sha256=L9eFHZndD6H7nkznJ9Bw0v8xh9IegDlhhGFHBz9EHmM,1745
|
@@ -100,10 +97,6 @@ py2docfx/docfx_yaml/tests/roots/test-translator-exceptions/conf.py,sha256=avcbnI
|
|
100
97
|
py2docfx/docfx_yaml/tests/roots/test-translator-exceptions/refered_objects.py,sha256=zTnP-R7nxTxZr2yHurKKQSPFSY9gz3_vmFI0OotI3_U,124
|
101
98
|
py2docfx/docfx_yaml/tests/roots/test-translator-fieldlists/code_with_multiple_fieldlists.py,sha256=llu95FRqwjtwrMdR1enMB1Lso59CYJBmUPQy6LvGGAA,502
|
102
99
|
py2docfx/docfx_yaml/tests/roots/test-translator-fieldlists/conf.py,sha256=KrvMHOj1LCdodwNwUsdCI_OMM-Bf_lpiUREk4egQWms,388
|
103
|
-
py2docfx/docfx_yaml/tests/roots/test-translator-returns/code_with_returns_numpy.py,sha256=OGHOCBmRENAp4_MLYgyUsU2z7cm_hQx6Jtb8PSIs1Uo,748
|
104
|
-
py2docfx/docfx_yaml/tests/roots/test-translator-returns/code_with_returns_rst.py,sha256=sQ1gV9lN33NjXFetGrUNLD6qCJF9v7BMYBQnDLa2Kdo,644
|
105
|
-
py2docfx/docfx_yaml/tests/roots/test-translator-returns/conf.py,sha256=A-QZx8-7Zg3_6X42F3LSyG5Nx0AoYkbKB2QbnM33PB0,402
|
106
|
-
py2docfx/docfx_yaml/tests/roots/test-translator-returns/refered_objects.py,sha256=IBbbX_O91I9SSZvM0Tw7UQDk3EosMbl_91R932swp4U,53
|
107
100
|
py2docfx/docfx_yaml/tests/roots/test-translator-signatures/code_with_docstring.py,sha256=ZHqPbmGiTBy_y852lQzKYaRlxGATM-OfPVmjAvLcP_E,471
|
108
101
|
py2docfx/docfx_yaml/tests/roots/test-translator-signatures/conf.py,sha256=avcbnIOV2mlGQwhMQJZC4W6UGRBRhnq1QBxjPWlySxQ,260
|
109
102
|
py2docfx/docfx_yaml/tests/roots/test-translator-signatures/refered_objects.py,sha256=DJaX52mnHw9W3GSqKh75CYK87g4CczXNNjFO496Ai2U,79
|
@@ -112,7 +105,7 @@ py2docfx/docfx_yaml/tests/roots/test-writer-table/conf.py,sha256=avcbnIOV2mlGQwh
|
|
112
105
|
py2docfx/docfx_yaml/tests/roots/test-writer-uri/code_with_uri.py,sha256=bzWTZpY2yf_By2bOSl1GFaY3BsZpkAvwQuGztlcHKkQ,537
|
113
106
|
py2docfx/docfx_yaml/tests/roots/test-writer-uri/conf.py,sha256=avcbnIOV2mlGQwhMQJZC4W6UGRBRhnq1QBxjPWlySxQ,260
|
114
107
|
py2docfx/docfx_yaml/tests/utils/test_utils.py,sha256=d0OYSUQ6NyoZx5mlLdNGGNhiNmmQhjVT4hQ6jY3VE_M,3383
|
115
|
-
py2docfx-0.1.0.
|
116
|
-
py2docfx-0.1.0.
|
117
|
-
py2docfx-0.1.0.
|
118
|
-
py2docfx-0.1.0.
|
108
|
+
py2docfx-0.1.0.dev1529344.dist-info/METADATA,sha256=2Z3RFLMpfABFhOX-8ipH78fSpyWZ6J9b1VlbYlDGSYw,601
|
109
|
+
py2docfx-0.1.0.dev1529344.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
|
110
|
+
py2docfx-0.1.0.dev1529344.dist-info/top_level.txt,sha256=5dH2uP81dczt_qQJ38wiZ-gzoVWasfiJALWRSjdbnYU,9
|
111
|
+
py2docfx-0.1.0.dev1529344.dist-info/RECORD,,
|
@@ -1,165 +0,0 @@
|
|
1
|
-
import sys
|
2
|
-
import parameter_utils
|
3
|
-
|
4
|
-
def split_by(symbol, text):
|
5
|
-
return [item.strip() for item in text.split(symbol)]
|
6
|
-
|
7
|
-
def is_part_of_name(character) -> bool:
|
8
|
-
# an upper or lower case letter and an underscore would be a valid type name
|
9
|
-
return character.isalpha() or character.isnumeric() or character == '_' or character == '.'
|
10
|
-
|
11
|
-
def endswith_mathching(class_obj_cache, type_name, refuri):
|
12
|
-
|
13
|
-
matches = [item for item in class_obj_cache if item.endswith('.' + type_name)]
|
14
|
-
|
15
|
-
# if there is no match, return the refuri if it ends with type_name
|
16
|
-
if len(matches) == 0:
|
17
|
-
if refuri.endswith("." + type_name):
|
18
|
-
return refuri
|
19
|
-
else:
|
20
|
-
return type_name
|
21
|
-
|
22
|
-
# if there is only one match, return the match
|
23
|
-
if len(matches) == 1:
|
24
|
-
return matches[0]
|
25
|
-
|
26
|
-
# if there are multiple matches, get a list of canonicals, return the first one
|
27
|
-
if len(matches) > 1:
|
28
|
-
canonicals = [m for m in matches if not class_obj_cache[m].aliased]
|
29
|
-
return canonicals[0]
|
30
|
-
|
31
|
-
def full_text_matching(match_string, class_obj_cache, type_dict):
|
32
|
-
# check for class_obj_cache first, because we want user defined type to be prioritized
|
33
|
-
if match_string in class_obj_cache:
|
34
|
-
return f'<xref:{match_string}>'
|
35
|
-
if match_string in type_dict:
|
36
|
-
if type_dict[match_string] == parameter_utils.TYPING_TYPE:
|
37
|
-
return f'<xref:typing.{match_string}>'
|
38
|
-
else:
|
39
|
-
return f'<xref:{match_string}>'
|
40
|
-
return None
|
41
|
-
|
42
|
-
def proceed_type_name(class_obj_cache, type_name, module_name, refuri):
|
43
|
-
"""
|
44
|
-
Priority Ranking:
|
45
|
-
1. refuri full text matching
|
46
|
-
2. refuri sys.modules matching
|
47
|
-
3. type name full text matching
|
48
|
-
4. module name + type name full text matching
|
49
|
-
5. type name endswith matching
|
50
|
-
|
51
|
-
The reason why we always want to use refuri to be top priority is because
|
52
|
-
refuri will mostly have more information.
|
53
|
-
For example, ~some_module.SomeClass
|
54
|
-
Refuri will be some_module.SomeClass, while type name will only be SomeClass
|
55
|
-
|
56
|
-
Sometimes, there will be empty refuri or error refuri, in that case, we will 1 and 2 would find no match
|
57
|
-
and type name matching would be the fallback option.
|
58
|
-
For example, in numpy style docstring
|
59
|
-
Refuri could be some_module.SomeClass.Any]] and type name is Any
|
60
|
-
|
61
|
-
4, module name + type name full text matching, is a reasonalbe guess that the user is trying to reference
|
62
|
-
a type that is user defined in the same module, but the user did not use the full name.
|
63
|
-
|
64
|
-
If all 1 to 4 fails, we will use endswith matching as the final fallback option.
|
65
|
-
"""
|
66
|
-
|
67
|
-
if type_name in ["", "or"]:
|
68
|
-
return type_name
|
69
|
-
|
70
|
-
# if # in refuri, it means that sphinx has resolved the type name
|
71
|
-
# take the part after # as the type name
|
72
|
-
if len(refuri.split('#')) > 1:
|
73
|
-
type_name = refuri.split('#')[-1]
|
74
|
-
return f'<xref:{type_name}>'
|
75
|
-
|
76
|
-
type_dict = parameter_utils.builtin_type_dict
|
77
|
-
|
78
|
-
# try get the match using refuri
|
79
|
-
refuri_matching_result = full_text_matching(refuri, class_obj_cache, type_dict)
|
80
|
-
|
81
|
-
# if the module name of refuri is not the same as module name of the current file
|
82
|
-
# and the module name of refuri can be found in sys.modules (means it is imported in source code)
|
83
|
-
# we can assume that writer was intenionally crossreferencing to another module
|
84
|
-
# return the refuri
|
85
|
-
refuri_module_name = refuri[0:refuri.rfind('.')] if '.' in refuri else None
|
86
|
-
if refuri_module_name:
|
87
|
-
if refuri_module_name != module_name and refuri_module_name in sys.modules:
|
88
|
-
return f'<xref:{refuri}>'
|
89
|
-
|
90
|
-
# try get the match using type name
|
91
|
-
type_name_matching_result = full_text_matching(type_name, class_obj_cache, type_dict)
|
92
|
-
|
93
|
-
# if both type name and refuri have a match, return the one from refuri
|
94
|
-
# because we want user defined type to be prioritized
|
95
|
-
if type_name_matching_result and refuri_matching_result:
|
96
|
-
return refuri_matching_result
|
97
|
-
elif type_name_matching_result:
|
98
|
-
return type_name_matching_result
|
99
|
-
elif refuri_matching_result:
|
100
|
-
return refuri_matching_result
|
101
|
-
|
102
|
-
# try get the match using module name + type name
|
103
|
-
fullname_matching_result = full_text_matching(module_name + "." + type_name, class_obj_cache, type_dict)
|
104
|
-
if fullname_matching_result is not None:
|
105
|
-
return fullname_matching_result
|
106
|
-
|
107
|
-
# try get the match using endswith matching mode
|
108
|
-
endwith_matching_result = endswith_mathching(class_obj_cache, type_name, refuri)
|
109
|
-
if endwith_matching_result is not None:
|
110
|
-
return f'<xref:{endwith_matching_result}>'
|
111
|
-
|
112
|
-
return f'<xref:{type_name}>'
|
113
|
-
|
114
|
-
def proceed_return_type(class_obj_cache, return_node, module_name):
|
115
|
-
node_text = return_node.astext()
|
116
|
-
symbol_index_list = [] # symbols are "[" and "]" etc.
|
117
|
-
|
118
|
-
# record the full reference name from sphinx
|
119
|
-
# primirily from refuri, some nodes do not have refuri but have reftarget instead
|
120
|
-
# if there is no refuri or reftarget, leave resolved_type_from_sphinx to be an empty string
|
121
|
-
resolved_type_from_sphinx = ""
|
122
|
-
if return_node.tagname == 'reference':
|
123
|
-
if "reftarget" in return_node.attributes:
|
124
|
-
resolved_type_from_sphinx = return_node.attributes["reftarget"]
|
125
|
-
elif "refid" in return_node.attributes:
|
126
|
-
resolved_type_from_sphinx = return_node.attributes["refid"]
|
127
|
-
elif "refuri" in return_node.attributes:
|
128
|
-
resolved_type_from_sphinx = return_node.attributes["refuri"]
|
129
|
-
|
130
|
-
# find all the symbols in the node text
|
131
|
-
for i, character in enumerate(node_text):
|
132
|
-
if not is_part_of_name(character):
|
133
|
-
symbol_index_list.append(i)
|
134
|
-
|
135
|
-
# if there is just one symbol or empty in the node text, return the node text
|
136
|
-
if node_text.strip() in ["[", "]", "(", ")", ",", "", "or"]:
|
137
|
-
return node_text
|
138
|
-
|
139
|
-
# if there is no symbol in the node text, which means it is a simple type name
|
140
|
-
# return proceeded type name
|
141
|
-
if len(symbol_index_list) == 0:
|
142
|
-
return proceed_type_name(class_obj_cache, node_text, module_name, resolved_type_from_sphinx)
|
143
|
-
|
144
|
-
# if there is a symbol in the node text, which means it is a complex type name
|
145
|
-
# use index list to split the node text into several parts and proceed each part
|
146
|
-
type_name = ""
|
147
|
-
for i,symbol_index in enumerate(symbol_index_list):
|
148
|
-
if i == 0:
|
149
|
-
temp_type_name = proceed_type_name(class_obj_cache, node_text[:symbol_index], module_name, resolved_type_from_sphinx) + node_text[symbol_index]
|
150
|
-
else:
|
151
|
-
temp_type_name = proceed_type_name(class_obj_cache, node_text[symbol_index_list[i-1]+1:symbol_index], module_name, resolved_type_from_sphinx) + node_text[symbol_index]
|
152
|
-
type_name += temp_type_name
|
153
|
-
|
154
|
-
# the last symbol index might not be at the end of the node text srting
|
155
|
-
# so we need to proceed the rest of the node text
|
156
|
-
if symbol_index_list[-1] < len(node_text) - 1:
|
157
|
-
type_name += proceed_type_name(class_obj_cache, node_text[symbol_index_list[-1] + 1:], module_name, resolved_type_from_sphinx)
|
158
|
-
|
159
|
-
return type_name
|
160
|
-
|
161
|
-
def get_return_type(class_obj_cache ,return_node, module_name):
|
162
|
-
type_string = ""
|
163
|
-
for child_node in return_node:
|
164
|
-
type_string += proceed_return_type(class_obj_cache, child_node, module_name)
|
165
|
-
return type_string.lstrip("~").replace("\n", " ").split(" or ")
|
@@ -1,37 +0,0 @@
|
|
1
|
-
from refered_objects import referee
|
2
|
-
from refered_objects import List
|
3
|
-
from collections.abc import MutableMapping
|
4
|
-
|
5
|
-
class dummyClass():
|
6
|
-
|
7
|
-
def complex_type(self):
|
8
|
-
"""
|
9
|
-
Returns
|
10
|
-
-------
|
11
|
-
Any[Dict[str, Any]]
|
12
|
-
"""
|
13
|
-
pass
|
14
|
-
|
15
|
-
def user_designated_builtin_type(self):
|
16
|
-
"""
|
17
|
-
Returns
|
18
|
-
-------
|
19
|
-
~collections.abc.MutableMapping
|
20
|
-
"""
|
21
|
-
pass
|
22
|
-
|
23
|
-
def user_defined_type_with_same_name_as_builtin_type(self):
|
24
|
-
"""
|
25
|
-
Returns
|
26
|
-
-------
|
27
|
-
~refered_objects.List
|
28
|
-
"""
|
29
|
-
pass
|
30
|
-
|
31
|
-
def user_defined_type(self):
|
32
|
-
"""
|
33
|
-
Returns
|
34
|
-
-------
|
35
|
-
~refered_objects.referee
|
36
|
-
"""
|
37
|
-
pass
|
@@ -1,29 +0,0 @@
|
|
1
|
-
from refered_objects import referee
|
2
|
-
from refered_objects import List
|
3
|
-
from collections.abc import MutableMapping
|
4
|
-
|
5
|
-
class dummyClass():
|
6
|
-
|
7
|
-
def complex_type(self):
|
8
|
-
"""
|
9
|
-
:rtype: Any[Dict[str, Any]]
|
10
|
-
"""
|
11
|
-
pass
|
12
|
-
|
13
|
-
def user_designated_builtin_type(self):
|
14
|
-
"""
|
15
|
-
:rtype: ~collections.abc.MutableMapping
|
16
|
-
"""
|
17
|
-
pass
|
18
|
-
|
19
|
-
def user_defined_type_with_same_name_as_builtin_type(self):
|
20
|
-
"""
|
21
|
-
:rtype: ~refered_objects.List
|
22
|
-
"""
|
23
|
-
pass
|
24
|
-
|
25
|
-
def user_defined_type(self):
|
26
|
-
"""
|
27
|
-
:rtype: ~refered_objects.referee
|
28
|
-
"""
|
29
|
-
pass
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import sys
|
3
|
-
|
4
|
-
sys.path.insert(0, os.path.abspath('.'))
|
5
|
-
|
6
|
-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.napoleon', 'yaml_builder']
|
7
|
-
|
8
|
-
class includeTest:
|
9
|
-
pass
|
10
|
-
|
11
|
-
# The suffix of source filenames.
|
12
|
-
source_suffix = '.rst'
|
13
|
-
|
14
|
-
autodoc_mock_imports = [
|
15
|
-
'dummy'
|
16
|
-
]
|
17
|
-
|
18
|
-
nitpicky = True
|
19
|
-
|
20
|
-
autodoc_default_options = {
|
21
|
-
'inherited-members': True
|
22
|
-
}
|
23
|
-
|
24
|
-
napoleon_preprocess_types = True
|
@@ -1,81 +0,0 @@
|
|
1
|
-
import pytest
|
2
|
-
|
3
|
-
from translator import translator
|
4
|
-
|
5
|
-
from .utils.test_utils import prepare_app_envs,prepare_refered_objects,load_rst_transform_to_doctree, do_autodoc
|
6
|
-
|
7
|
-
@pytest.mark.sphinx('dummy', testroot='translator-returns')
|
8
|
-
def test_numpy_return_complex_type(app):
|
9
|
-
# Test data definition
|
10
|
-
objectToGenXml = 'code_with_returns_numpy.dummyClass.complex_type'
|
11
|
-
objectToGenXmlType = 'function'
|
12
|
-
|
13
|
-
# Arrange
|
14
|
-
prepare_app_envs(app, objectToGenXml)
|
15
|
-
doctree = load_rst_transform_to_doctree(app, objectToGenXmlType, objectToGenXml)
|
16
|
-
|
17
|
-
# Act
|
18
|
-
translator(app, '', doctree)
|
19
|
-
|
20
|
-
# Assert
|
21
|
-
return_type = app.env.docfx_info_field_data[objectToGenXml]['return']['type'][0]
|
22
|
-
assert(return_type == "<xref:typing.Any>[<xref:typing.Dict>[<xref:str>, <xref:typing.Any>]]")
|
23
|
-
|
24
|
-
@pytest.mark.sphinx('yaml', testroot='translator-returns')
|
25
|
-
def test_numpy_return_user_designated_builtin_type(app):
|
26
|
-
# Test data definition
|
27
|
-
objectToGenXml = 'code_with_returns_numpy.dummyClass.user_designated_builtin_type'
|
28
|
-
objectToGenXmlType = 'function'
|
29
|
-
|
30
|
-
# Arrange
|
31
|
-
prepare_app_envs(app, objectToGenXml)
|
32
|
-
doctree = load_rst_transform_to_doctree(app, objectToGenXmlType, objectToGenXml)
|
33
|
-
|
34
|
-
# Act
|
35
|
-
translator(app, '', doctree)
|
36
|
-
|
37
|
-
# Assert
|
38
|
-
return_type = app.env.docfx_info_field_data[objectToGenXml]['return']['type'][0]
|
39
|
-
assert(return_type == "<xref:collections.abc.MutableMapping>")
|
40
|
-
|
41
|
-
@pytest.mark.sphinx('dummy', testroot='translator-returns')
|
42
|
-
def test_numpy_return_user_defined_type_with_same_name_as_builtin_type(app):
|
43
|
-
# Test data definition
|
44
|
-
objectToGenXml = 'code_with_returns_numpy.dummyClass.user_defined_type_with_same_name_as_builtin_type'
|
45
|
-
objectToGenXmlType = 'function'
|
46
|
-
referedApis = [
|
47
|
-
('refered_objects.List', 'class')
|
48
|
-
]
|
49
|
-
|
50
|
-
# Arrange
|
51
|
-
prepare_app_envs(app, objectToGenXml)
|
52
|
-
prepare_refered_objects(app, referedApis)
|
53
|
-
doctree = load_rst_transform_to_doctree(app, objectToGenXmlType, objectToGenXml)
|
54
|
-
|
55
|
-
# Act
|
56
|
-
translator(app, '', doctree)
|
57
|
-
|
58
|
-
# Assert
|
59
|
-
return_type = app.env.docfx_info_field_data[objectToGenXml]['return']['type'][0]
|
60
|
-
assert(return_type == "<xref:refered_objects.List>")
|
61
|
-
|
62
|
-
@pytest.mark.sphinx('yaml', testroot='translator-returns')
|
63
|
-
def test_numpy_return_user_defined_type(app):
|
64
|
-
# Test data definition
|
65
|
-
objectToGenXml = 'code_with_returns_numpy.dummyClass.user_defined_type'
|
66
|
-
objectToGenXmlType = 'function'
|
67
|
-
referedApis = [
|
68
|
-
('refered_objects.List', 'class')
|
69
|
-
]
|
70
|
-
|
71
|
-
# Arrange
|
72
|
-
prepare_app_envs(app, objectToGenXml)
|
73
|
-
prepare_refered_objects(app, referedApis)
|
74
|
-
doctree = load_rst_transform_to_doctree(app, objectToGenXmlType, objectToGenXml)
|
75
|
-
|
76
|
-
# Act
|
77
|
-
translator(app, '', doctree)
|
78
|
-
|
79
|
-
# Assert
|
80
|
-
return_type = app.env.docfx_info_field_data[objectToGenXml]['return']['type'][0]
|
81
|
-
assert(return_type == "<xref:refered_objects.referee>")
|
@@ -1,81 +0,0 @@
|
|
1
|
-
import pytest
|
2
|
-
|
3
|
-
from translator import translator
|
4
|
-
|
5
|
-
from .utils.test_utils import prepare_app_envs,prepare_refered_objects,load_rst_transform_to_doctree
|
6
|
-
|
7
|
-
@pytest.mark.sphinx('dummy', testroot='translator-returns')
|
8
|
-
def test_rst_return_complex_type(app):
|
9
|
-
# Test data definition
|
10
|
-
objectToGenXml = 'code_with_returns_rst.dummyClass.complex_type'
|
11
|
-
objectToGenXmlType = 'function'
|
12
|
-
|
13
|
-
# Arrange
|
14
|
-
prepare_app_envs(app, objectToGenXml)
|
15
|
-
doctree = load_rst_transform_to_doctree(app, objectToGenXmlType, objectToGenXml)
|
16
|
-
|
17
|
-
# Act
|
18
|
-
translator(app, '', doctree)
|
19
|
-
|
20
|
-
# Assert
|
21
|
-
return_type = app.env.docfx_info_field_data[objectToGenXml]['return']['type'][0]
|
22
|
-
assert(return_type == "<xref:typing.Any>[<xref:typing.Dict>[<xref:str>, <xref:typing.Any>]]")
|
23
|
-
|
24
|
-
@pytest.mark.sphinx('yaml', testroot='translator-returns')
|
25
|
-
def test_rst_return_user_designated_builtin_type(app):
|
26
|
-
# Test data definition
|
27
|
-
objectToGenXml = 'code_with_returns_rst.dummyClass.user_designated_builtin_type'
|
28
|
-
objectToGenXmlType = 'function'
|
29
|
-
|
30
|
-
# Arrange
|
31
|
-
prepare_app_envs(app, objectToGenXml)
|
32
|
-
doctree = load_rst_transform_to_doctree(app, objectToGenXmlType, objectToGenXml)
|
33
|
-
|
34
|
-
# Act
|
35
|
-
translator(app, '', doctree)
|
36
|
-
|
37
|
-
# Assert
|
38
|
-
return_type = app.env.docfx_info_field_data[objectToGenXml]['return']['type'][0]
|
39
|
-
assert(return_type == "<xref:collections.abc.MutableMapping>")
|
40
|
-
|
41
|
-
@pytest.mark.sphinx('dummy', testroot='translator-returns')
|
42
|
-
def test_rst_return_user_defined_type_with_same_name_as_builtin_type(app):
|
43
|
-
# Test data definition
|
44
|
-
objectToGenXml = 'code_with_returns_rst.dummyClass.user_defined_type_with_same_name_as_builtin_type'
|
45
|
-
objectToGenXmlType = 'function'
|
46
|
-
referedApis = [
|
47
|
-
('refered_objects.List', 'class')
|
48
|
-
]
|
49
|
-
|
50
|
-
# Arrange
|
51
|
-
prepare_app_envs(app, objectToGenXml)
|
52
|
-
prepare_refered_objects(app, referedApis)
|
53
|
-
doctree = load_rst_transform_to_doctree(app, objectToGenXmlType, objectToGenXml)
|
54
|
-
|
55
|
-
# Act
|
56
|
-
translator(app, '', doctree)
|
57
|
-
|
58
|
-
# Assert
|
59
|
-
return_type = app.env.docfx_info_field_data[objectToGenXml]['return']['type'][0]
|
60
|
-
assert(return_type == "<xref:refered_objects.List>")
|
61
|
-
|
62
|
-
@pytest.mark.sphinx('yaml', testroot='translator-returns')
|
63
|
-
def test_rst_return_user_defined_type(app):
|
64
|
-
# Test data definition
|
65
|
-
objectToGenXml = 'code_with_returns_rst.dummyClass.user_defined_type'
|
66
|
-
objectToGenXmlType = 'function'
|
67
|
-
referedApis = [
|
68
|
-
('refered_objects.List', 'class')
|
69
|
-
]
|
70
|
-
|
71
|
-
# Arrange
|
72
|
-
prepare_app_envs(app, objectToGenXml)
|
73
|
-
prepare_refered_objects(app, referedApis)
|
74
|
-
doctree = load_rst_transform_to_doctree(app, objectToGenXmlType, objectToGenXml)
|
75
|
-
|
76
|
-
# Act
|
77
|
-
translator(app, '', doctree)
|
78
|
-
|
79
|
-
# Assert
|
80
|
-
return_type = app.env.docfx_info_field_data[objectToGenXml]['return']['type'][0]
|
81
|
-
assert(return_type == "<xref:refered_objects.referee>")
|
File without changes
|
File without changes
|