py2docfx 0.1.15.dev2025178__py3-none-any.whl → 0.1.15.dev2025736__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.
@@ -111,38 +111,27 @@ def _resolve_reference_in_module_summary(lines):
111
111
  new_lines.append(new_line)
112
112
  return new_lines
113
113
 
114
- def getParameterArgs(argspec):
114
+ def getParameterArgs(signature):
115
115
  args = []
116
- for arg in argspec.args:
117
- args.append({'id': arg})
118
- if argspec.defaults:
119
- for count, default in enumerate(argspec.defaults):
120
- cut_count = len(argspec.defaults)
121
- # Only add defaultValue when str(default) doesn't contain object address string
122
- # (object at 0x)(lambda at 0x)(function *** at 0x)
123
- # inspect.getargspec method will return wrong defaults which contain object address for some default values, like sys.stdout
124
- # Match the defaults with the count
125
- if ' at 0x' not in str(default):
126
- args[len(args) - cut_count +
127
- count]['defaultValue'] = str(default)
128
- else:
129
- args[len(args) - cut_count +
130
- count]['isRequired'] = False
116
+ for param in signature.parameters.values():
117
+ if param.kind in [param.POSITIONAL_OR_KEYWORD, param.POSITIONAL_ONLY]:
118
+ arg = {'id': param.name}
119
+ if param.default is not param.empty:
120
+ if ' at 0x' not in str(param.default):
121
+ arg['defaultValue'] = str(param.default)
122
+ else:
123
+ arg['isRequired'] = False
124
+ args.append(arg)
131
125
  return args
132
126
 
133
- def getKeywordOnlyParameters(argspec):
127
+ def getKeywordOnlyParameters(signature):
134
128
  keyword_only_args = []
135
- # check if there is keyword only args
136
- if argspec.kwonlyargs:
137
- count = 0
138
- for arg in argspec.kwonlyargs:
139
- keyword_only_args.append({'id': arg})
140
- # try get the default value for keyword only args
141
- if argspec.kwonlydefaults:
142
- kwarg_default = argspec.kwonlydefaults.get(arg, None)
143
- if kwarg_default:
144
- keyword_only_args[count]['defaultValue'] = str(kwarg_default)
145
- count += 1
129
+ for param in signature.parameters.values():
130
+ if param.kind == param.KEYWORD_ONLY:
131
+ kwarg = {'id': param.name}
132
+ if param.default is not param.empty:
133
+ kwarg['defaultValue'] = str(param.default)
134
+ keyword_only_args.append(kwarg)
146
135
  return keyword_only_args
147
136
 
148
137
  def getpositionalOnlyParameters(signature):
@@ -193,13 +182,10 @@ def _create_datam(app, cls, module, name, _type, obj, lines=None):
193
182
  if _type in [CLASS, METHOD, FUNCTION]:
194
183
  if not (_type == CLASS and isinstance(type(obj).__call__, type(EnumMeta.__call__))):
195
184
  signature = inspect.signature(obj)
196
- argspec = inspect.getfullargspec(obj)
197
-
198
- args = getParameterArgs(argspec)
199
- keyword_only_args = getKeywordOnlyParameters(argspec)
185
+ args = getParameterArgs(signature)
186
+ keyword_only_args = getKeywordOnlyParameters(signature)
200
187
  positional_only_params = getpositionalOnlyParameters(signature)
201
-
202
- # The args will contian both regular args and positional only params
188
+ # The args will contain both regular args and positional only params
203
189
  # so we need to remove the positional only args from params
204
190
  if positional_only_params:
205
191
  args = removePositonalOnlyFromArgs(args, positional_only_params)
@@ -391,6 +377,7 @@ def process_docstring(app, _type, name, obj, options, lines):
391
377
  """
392
378
  # Use exception as class
393
379
  py2docfx_logger = get_package_logger(__name__)
380
+
394
381
  def check_convert_package_type(obj, _type):
395
382
  if _type == MODULE:
396
383
  filename = getattr(obj, '__file__', None)
@@ -1,24 +1,18 @@
1
1
  import pytest
2
-
3
- from sphinx.testing import restructuredtext
4
- from sphinx.io import SphinxStandaloneReader
5
- from sphinx import addnodes
6
2
  from translator import translator
3
+ from .utils.test_utils import prepare_app_envs, load_rst_transform_to_doctree, do_autodoc
7
4
 
8
- from .utils.test_utils import prepare_app_envs,prepare_refered_objects,load_rst_transform_to_doctree, do_autodoc
9
5
  @pytest.mark.sphinx('dummy', testroot='method-arguments')
10
6
  def test_method_with_three_type_of_arguments(app):
11
7
  # Test data definition
12
8
  objectToGenXml = 'code_with_all_arg_types.TestClass'
13
9
  objectToGenXmlType = 'class'
14
-
15
10
  # Arrange
16
11
  prepare_app_envs(app, objectToGenXml)
17
12
  doctree = load_rst_transform_to_doctree(app, objectToGenXmlType, objectToGenXml)
18
13
 
19
14
  # Act
20
15
  translator(app, '', doctree)
21
-
22
16
  # Assert
23
17
  argumentsDetail = app.env.docfx_yaml_classes[objectToGenXml][1]['syntax']
24
18
  parameters = argumentsDetail.get('parameters', None)
@@ -0,0 +1,120 @@
1
+ import pytest
2
+ import inspect
3
+ from sphinx.config import Config
4
+ from docfx_yaml.process_doctree import (
5
+ getParameterArgs,
6
+ getKeywordOnlyParameters
7
+ )
8
+ from unittest.mock import Mock
9
+ from docfx_yaml.process_doctree import process_docstring
10
+ from sphinx.config import ENUM
11
+
12
+ # Test data for getParameterArgs
13
+ @pytest.mark.parametrize("func, expected_args", [
14
+ (lambda a, b=2, *, c=3, d=4: None, [
15
+ {'id': 'a', 'isRequired': True},
16
+ {'id': 'b', 'defaultValue': '2'}
17
+ ]),
18
+ (lambda x, y, z=5: None, [
19
+ {'id': 'x', 'isRequired': True},
20
+ {'id': 'y', 'isRequired': True},
21
+ {'id': 'z', 'defaultValue': '5'}
22
+ ])
23
+ ])
24
+ def test_getParameterArgs(func, expected_args):
25
+ signature = inspect.signature(func)
26
+ args = getParameterArgs(signature)
27
+ assert args == expected_args
28
+
29
+ # Test data for getKeywordOnlyParameters
30
+ @pytest.mark.parametrize("func, expected_kwonlyargs", [
31
+ (lambda a, b=2, *, c=3, d=4: None, [
32
+ {'id': 'c', 'defaultValue': '3'},
33
+ {'id': 'd', 'defaultValue': '4'}
34
+ ]),
35
+ (lambda x, y, *, z=5: None, [
36
+ {'id': 'z', 'defaultValue': '5'}
37
+ ])
38
+ ])
39
+ def test_getKeywordOnlyParameters(func, expected_kwonlyargs):
40
+ signature = inspect.signature(func)
41
+ kwonlyargs = getKeywordOnlyParameters(signature)
42
+ assert kwonlyargs == expected_kwonlyargs
43
+
44
+
45
+ @pytest.fixture
46
+ def app():
47
+ app = Mock()
48
+ app.config = Config()
49
+ app.config.autoclass_content = 'both'
50
+ app.config.autodoc_functions = True
51
+ app.env = Mock()
52
+ app.env.docfx_yaml_packages = {}
53
+ app.env.docfx_yaml_modules = {}
54
+ app.env.docfx_yaml_classes = {}
55
+ app.env.docfx_yaml_functions = {}
56
+ app.env.docfx_info_uid_types = {}
57
+ return app
58
+
59
+
60
+ def test_process_docstring_class(app):
61
+ class DummyClass:
62
+ """This is a dummy class."""
63
+ def method(self):
64
+ pass
65
+
66
+ process_docstring(app, 'class', 'test_module.DummyClass', DummyClass, {}, [])
67
+
68
+ assert 'test_module.DummyClass' in app.env.docfx_yaml_classes
69
+ assert len(app.env.docfx_yaml_classes['test_module.DummyClass']) == 1
70
+ datam = app.env.docfx_yaml_classes['test_module.DummyClass'][0]
71
+ assert datam['type'] == 'class'
72
+ assert datam['name'] == 'DummyClass'
73
+ assert datam['fullName'] == 'test_module.DummyClass'
74
+
75
+
76
+ def test_process_docstring_function(app):
77
+ def dummy_function():
78
+ """This is a dummy function."""
79
+ pass
80
+
81
+ process_docstring(app, 'function', 'test_module.dummy_function', dummy_function, {}, [])
82
+
83
+ assert 'test_module.dummy_function' in app.env.docfx_yaml_functions
84
+ assert len(app.env.docfx_yaml_functions['test_module.dummy_function']) == 1
85
+ datam = app.env.docfx_yaml_functions['test_module.dummy_function'][0]
86
+ assert datam['type'] == 'function'
87
+ assert datam['name'] == 'dummy_function'
88
+ assert datam['fullName'] == 'test_module.dummy_function'
89
+
90
+
91
+ def test_process_docstring_decorated_method(app):
92
+ class DecoratedClass:
93
+ """This is a decorated class."""
94
+ @staticmethod
95
+ def decorated_method(a, b=2, *, c=3):
96
+ """This is a decorated method."""
97
+ pass
98
+
99
+ process_docstring(app, 'class', 'test_module.DecoratedClass', DecoratedClass, {}, [])
100
+
101
+ assert 'test_module.DecoratedClass' in app.env.docfx_yaml_classes
102
+ assert len(app.env.docfx_yaml_classes['test_module.DecoratedClass']) == 1
103
+ datam = app.env.docfx_yaml_classes['test_module.DecoratedClass'][0]
104
+ assert datam['type'] == 'class'
105
+ assert datam['name'] == 'DecoratedClass'
106
+ assert datam['fullName'] == 'test_module.DecoratedClass'
107
+
108
+ process_docstring(app, 'method', 'test_module.DecoratedClass.decorated_method', DecoratedClass.decorated_method, {}, [])
109
+
110
+ method_syntax_list = [m for m in app.env.docfx_yaml_classes['test_module.DecoratedClass'] if m['name'] == 'decorated_method']
111
+ assert len(method_syntax_list) == 1
112
+ method_syntax = method_syntax_list[0]['syntax']
113
+ assert method_syntax['parameters'] == [
114
+ {'id': 'a', 'isRequired': True},
115
+ {'id': 'b', 'defaultValue': '2'}
116
+ ]
117
+ assert method_syntax['keywordOnlyParameters'] == [
118
+ {'id': 'c', 'defaultValue': '3'}
119
+ ]
120
+ assert 'positionalOnlyParameters' not in method_syntax
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2docfx
3
- Version: 0.1.15.dev2025178
3
+ Version: 0.1.15.dev2025736
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
@@ -69,7 +69,7 @@ py2docfx/docfx_yaml/logger.py,sha256=gz416vqSqmsD91qLOCLAzomczlCfWqGXFJFRzLlVbJE
69
69
  py2docfx/docfx_yaml/miss_reference.py,sha256=Btoj9wAvA4u_wU7JHH0Cei3910N8a7MS34OUqJvXAd4,2443
70
70
  py2docfx/docfx_yaml/nodes.py,sha256=tBDi35jLJArlobl07DKOkmH2qz7dudXLp_kTUfR_r2w,412
71
71
  py2docfx/docfx_yaml/parameter_utils.py,sha256=zGSIQrUfbXf9PUK-W_1K83Uo5Zk797Zlze6aMurbHIA,8706
72
- py2docfx/docfx_yaml/process_doctree.py,sha256=n2D-DCR7JmqVXm0oeuYZVnHIaHJZOegM8-kHXXx8IZ4,17857
72
+ py2docfx/docfx_yaml/process_doctree.py,sha256=RUbq2DkkKl-KjKiuQrZhuvi8Q_ZjUdW4oi6CTWpMkxc,17229
73
73
  py2docfx/docfx_yaml/return_type_utils.py,sha256=nmdCUOvwdYk2jF6RqmOvU6gjXmXUTPUeCqyHPdKZNUQ,7483
74
74
  py2docfx/docfx_yaml/settings.py,sha256=JQZNwFebczl-zn8Yk2taAGANRi-Hw8hywtDWxqXXFyQ,373
75
75
  py2docfx/docfx_yaml/translator.py,sha256=LSzNl4C-07bLbUZ5myfyWwh25cTNIIBih77Cp4tBWvo,25999
@@ -80,8 +80,9 @@ py2docfx/docfx_yaml/yaml_builder.py,sha256=S3xty_ILxEUsw1J9VCwUkSLLYAUfQDm3fYbci
80
80
  py2docfx/docfx_yaml/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
81
81
  py2docfx/docfx_yaml/tests/conftest.py,sha256=CykkZxaDZ-3a1EIQdGBieSmHL9FdyTE2xTJZe9QgKcg,1214
82
82
  py2docfx/docfx_yaml/tests/test_build_finished.py,sha256=PSyWuY_XWmNeSjQl4kBwHUWpEhQHuEXQCZPWtFZ7vb4,8433
83
- py2docfx/docfx_yaml/tests/test_method_arguments.py,sha256=Cvj9aoADtacKciVN8nempXW-KQL8nujSa9GNVuk6l_8,1578
83
+ py2docfx/docfx_yaml/tests/test_method_arguments.py,sha256=syfO626qaAh8pIy_ErzO5OeHR5FDlhGDvnBtUnZoU7k,1429
84
84
  py2docfx/docfx_yaml/tests/test_numpy_syntax.py,sha256=ssb3J_-Jzjybhh4eycCA_LkXbGflyZyIUAiTjlEYLiw,863
85
+ py2docfx/docfx_yaml/tests/test_process_doctree.py,sha256=1BdXLRB0lQA_NUqCJAW4h1xsK7sfZQdQw_8KAzTjjQM,4326
85
86
  py2docfx/docfx_yaml/tests/test_translator_attributes.py,sha256=qZCsQGffq31k3UzpXkJpycplOXIq9gi2SxY6vu0DTfw,5224
86
87
  py2docfx/docfx_yaml/tests/test_translator_contents.py,sha256=lVCWbBIQk2oPFqsKK9gIb-b5DixutMabWjP7x03oj4s,1746
87
88
  py2docfx/docfx_yaml/tests/test_translator_data.py,sha256=zSVs3AT_TeAx1mrEYNTpy3Xy-FPrwwi93ly2EFclw5U,984
@@ -4207,7 +4208,7 @@ py2docfx/venv/venv1/Lib/site-packages/win32comext/taskscheduler/test/test_addtas
4207
4208
  py2docfx/venv/venv1/Lib/site-packages/win32comext/taskscheduler/test/test_localsystem.py,sha256=08ojAS48W6RLsUbRD45j0SJhg_Y2NFHZT6qjT4Vrig0,75
4208
4209
  py2docfx/venv/venv1/Scripts/pywin32_postinstall.py,sha256=mx4WVp1hD_8xgkSXttNtto1BVDECZOc3FCClrR1SjFM,25736
4209
4210
  py2docfx/venv/venv1/Scripts/pywin32_testall.py,sha256=hyGLMKILn3_W0q-McP1VJnNFW_z5yk_gesTMQDlUocM,3847
4210
- py2docfx-0.1.15.dev2025178.dist-info/METADATA,sha256=D7CgqnEa-FAMgSBmDMkm-B5bCCKQ7Vw4hWWml2JZVwQ,550
4211
- py2docfx-0.1.15.dev2025178.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
4212
- py2docfx-0.1.15.dev2025178.dist-info/top_level.txt,sha256=5dH2uP81dczt_qQJ38wiZ-gzoVWasfiJALWRSjdbnYU,9
4213
- py2docfx-0.1.15.dev2025178.dist-info/RECORD,,
4211
+ py2docfx-0.1.15.dev2025736.dist-info/METADATA,sha256=opT_4AXLSQGPyL_bUDPAbfDDmWTi6K7oy9scD6AbLT4,550
4212
+ py2docfx-0.1.15.dev2025736.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
4213
+ py2docfx-0.1.15.dev2025736.dist-info/top_level.txt,sha256=5dH2uP81dczt_qQJ38wiZ-gzoVWasfiJALWRSjdbnYU,9
4214
+ py2docfx-0.1.15.dev2025736.dist-info/RECORD,,