@autorest/python 6.0.0 → 6.1.1

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.
Files changed (34) hide show
  1. package/ChangeLog.md +56 -0
  2. package/README.md +21 -2
  3. package/autorest/__init__.py +80 -14
  4. package/autorest/_utils.py +56 -0
  5. package/autorest/black/__init__.py +27 -14
  6. package/autorest/codegen/__init__.py +131 -90
  7. package/autorest/codegen/_utils.py +14 -0
  8. package/autorest/codegen/models/__init__.py +10 -1
  9. package/autorest/codegen/models/model_type.py +12 -1
  10. package/autorest/codegen/serializers/__init__.py +58 -58
  11. package/autorest/codegen/serializers/builder_serializer.py +1 -3
  12. package/autorest/codegen/serializers/client_serializer.py +6 -0
  13. package/autorest/codegen/templates/README.md.jinja2 +3 -3
  14. package/autorest/codegen/templates/setup.py.jinja2 +1 -2
  15. package/autorest/jsonrpc/server.py +13 -7
  16. package/autorest/m2r/__init__.py +18 -6
  17. package/autorest/m4reformatter/__init__.py +6 -3
  18. package/autorest/multiapi/__init__.py +57 -31
  19. package/autorest/multiapi/serializers/__init__.py +26 -24
  20. package/autorest/multiclient/__init__.py +50 -0
  21. package/autorest/multiclient/templates/init.py.jinja2 +8 -0
  22. package/autorest/multiclient/templates/version.py.jinja2 +8 -0
  23. package/autorest/postprocess/__init__.py +15 -12
  24. package/autorest/preprocess/__init__.py +24 -5
  25. package/autorest/preprocess/helpers.py +0 -30
  26. package/install.py +3 -3
  27. package/package.json +3 -2
  28. package/prepare.py +2 -2
  29. package/requirements.txt +8 -9
  30. package/run-python3.js +2 -2
  31. package/run_cadl.py +26 -0
  32. package/setup.py +2 -3
  33. package/start.py +2 -2
  34. package/autorest/multiapi/serializers/multiapi_serializer.py +0 -114
@@ -3,6 +3,7 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
+ import logging
6
7
  from typing import Any, Dict, Union
7
8
  from .base_model import BaseModel
8
9
  from .code_model import CodeModel
@@ -140,6 +141,7 @@ TYPE_TO_OBJECT = {
140
141
  "any-object": AnyObjectType,
141
142
  "unixtime": UnixTimeType,
142
143
  }
144
+ _LOGGER = logging.getLogger(__name__)
143
145
 
144
146
 
145
147
  def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
@@ -155,7 +157,14 @@ def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
155
157
  code_model.types_map[yaml_id] = response
156
158
  response.fill_instance_from_yaml(yaml_data, code_model)
157
159
  else:
158
- response = TYPE_TO_OBJECT[yaml_data["type"]].from_yaml(yaml_data, code_model) # type: ignore
160
+ object_type = yaml_data.get("type", None)
161
+ if object_type is None:
162
+ _LOGGER.warning(
163
+ 'Unrecognized definition type "%s" is found, falling back it as "string"! ',
164
+ yaml_data["type"],
165
+ )
166
+ object_type = "string"
167
+ response = TYPE_TO_OBJECT[object_type].from_yaml(yaml_data, code_model) # type: ignore
159
168
  code_model.types_map[yaml_id] = response
160
169
  return response
161
170
 
@@ -3,6 +3,7 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
+ from collections import OrderedDict
6
7
  from typing import Any, Dict, List, Optional, TYPE_CHECKING, cast
7
8
 
8
9
  from autorest.codegen.models.utils import add_to_pylint_disable
@@ -153,7 +154,17 @@ class ModelType(BaseType): # pylint: disable=too-many-instance-attributes
153
154
  # once we've finished, we want to reset created_json_template_representation to false
154
155
  # so we can call it again
155
156
  self._created_json_template_representation = False
156
- return representation
157
+ optional_keys = [
158
+ f'"{p.rest_api_name}"'
159
+ for p in self.properties
160
+ if getattr(p, "optional", False)
161
+ ]
162
+ return OrderedDict(
163
+ sorted(
164
+ representation.items(),
165
+ key=lambda item: f"{1 if item[0] in optional_keys else 0}{item[0]}",
166
+ )
167
+ )
157
168
 
158
169
  def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
159
170
  is_polymorphic_subtype = (
@@ -3,12 +3,13 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Dict, List, Optional, Any, Union
6
+ from typing import Dict, List, Optional, Any, Union, cast
7
7
  from pathlib import Path
8
8
  from jinja2 import PackageLoader, Environment, FileSystemLoader, StrictUndefined
9
9
  from autorest.codegen.models.operation_group import OperationGroup
10
10
  from autorest.codegen.models.request_builder import OverloadedRequestBuilder
11
11
 
12
+ from ... import ReaderAndWriter, ReaderAndWriterAutorest
12
13
  from ...jsonrpc import AutorestAPI
13
14
  from ..models import CodeModel, OperationGroup, RequestBuilder
14
15
  from ..models import TokenCredentialType
@@ -38,9 +39,11 @@ _PACKAGE_FILES = [
38
39
  _REGENERATE_FILES = {"setup.py", "MANIFEST.in"}
39
40
 
40
41
 
41
- class JinjaSerializer:
42
- def __init__(self, autorestapi: AutorestAPI, code_model: CodeModel) -> None:
43
- self._autorestapi = autorestapi
42
+ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
43
+ def __init__(
44
+ self, code_model: CodeModel, *, output_folder: Union[str, Path], **kwargs: Any
45
+ ) -> None:
46
+ super().__init__(output_folder=output_folder, **kwargs)
44
47
  self.code_model = code_model
45
48
 
46
49
  @property
@@ -129,10 +132,10 @@ class JinjaSerializer:
129
132
  )
130
133
  if not self.code_model.options["models_mode"]:
131
134
  # keep models file if users ended up just writing a models file
132
- if self._autorestapi.read_file(namespace_path / Path("models.py")):
133
- self._autorestapi.write_file(
135
+ if self.read_file(namespace_path / Path("models.py")):
136
+ self.write_file(
134
137
  namespace_path / Path("models.py"),
135
- self._autorestapi.read_file(namespace_path / Path("models.py")),
138
+ cast(str, self.read_file(namespace_path / Path("models.py"))),
136
139
  )
137
140
 
138
141
  if self.code_model.options["package_mode"]:
@@ -143,16 +146,15 @@ class JinjaSerializer:
143
146
  for template_name in package_files:
144
147
  file = template_name.replace(".jinja2", "")
145
148
  output_name = out_path / file
146
- if (
147
- not self._autorestapi.read_file(output_name)
148
- or file in _REGENERATE_FILES
149
- ):
149
+ if not self.read_file(output_name) or file in _REGENERATE_FILES:
150
150
  template = env.get_template(template_name)
151
151
  render_result = template.render(**kwargs)
152
- self._autorestapi.write_file(output_name, render_result)
152
+ self.write_file(output_name, render_result)
153
153
 
154
154
  def _prepare_params() -> Dict[Any, Any]:
155
- package_parts = package_name.split("-")[:-1]
155
+ package_parts = (self.code_model.options["package_name"] or "").split("-")[
156
+ :-1
157
+ ]
156
158
  token_cred = isinstance(
157
159
  getattr(self.code_model.credential, "type", None), TokenCredentialType
158
160
  )
@@ -179,14 +181,7 @@ class JinjaSerializer:
179
181
  params.update(self.code_model.package_dependency)
180
182
  return params
181
183
 
182
- package_name = (
183
- self.code_model.options["package_name"]
184
- or self.code_model.client.name.lower()
185
- )
186
- count = package_name.count("-") + 1
187
- for _ in range(count):
188
- out_path = out_path / Path("..")
189
-
184
+ out_path = out_path / Path("../" * (self.code_model.namespace.count(".") + 1))
190
185
  if self.code_model.options["package_mode"] in ("dataplane", "mgmtplane"):
191
186
  env = Environment(
192
187
  loader=PackageLoader("autorest.codegen", "templates"),
@@ -207,12 +202,10 @@ class JinjaSerializer:
207
202
  _serialize_and_write_package_files_proc(**params)
208
203
 
209
204
  def _keep_patch_file(self, path_file: Path, env: Environment):
210
- if self._autorestapi.read_file(path_file):
211
- self._autorestapi.write_file(
212
- path_file, self._autorestapi.read_file(path_file)
213
- )
205
+ if self.read_file(path_file):
206
+ self.write_file(path_file, self.read_file(path_file))
214
207
  else:
215
- self._autorestapi.write_file(
208
+ self.write_file(
216
209
  path_file,
217
210
  PatchSerializer(env=env, code_model=self.code_model).serialize(),
218
211
  )
@@ -223,16 +216,16 @@ class JinjaSerializer:
223
216
  # Write the models folder
224
217
  models_path = namespace_path / Path("models")
225
218
  if self.code_model.model_types:
226
- self._autorestapi.write_file(
219
+ self.write_file(
227
220
  models_path / Path(f"{self.code_model.models_filename}.py"),
228
221
  ModelSerializer(code_model=self.code_model, env=env).serialize(),
229
222
  )
230
223
  if self.code_model.enums:
231
- self._autorestapi.write_file(
224
+ self.write_file(
232
225
  models_path / Path(f"{self.code_model.enums_filename}.py"),
233
226
  EnumSerializer(code_model=self.code_model, env=env).serialize(),
234
227
  )
235
- self._autorestapi.write_file(
228
+ self.write_file(
236
229
  models_path / Path("__init__.py"),
237
230
  ModelInitSerializer(code_model=self.code_model, env=env).serialize(),
238
231
  )
@@ -253,7 +246,7 @@ class JinjaSerializer:
253
246
  env, rest_path, request_builders
254
247
  )
255
248
  if not "" in group_names:
256
- self._autorestapi.write_file(
249
+ self.write_file(
257
250
  rest_path / Path("__init__.py"),
258
251
  self.code_model.options["license_header"],
259
252
  )
@@ -267,7 +260,7 @@ class JinjaSerializer:
267
260
  group_name = request_builders[0].group_name
268
261
  output_path = rest_path / Path(group_name) if group_name else rest_path
269
262
  # write generic request builders file
270
- self._autorestapi.write_file(
263
+ self.write_file(
271
264
  output_path / Path("_request_builders.py"),
272
265
  RequestBuildersSerializer(
273
266
  code_model=self.code_model,
@@ -277,7 +270,7 @@ class JinjaSerializer:
277
270
  )
278
271
 
279
272
  # write rest init file
280
- self._autorestapi.write_file(
273
+ self.write_file(
281
274
  output_path / Path("__init__.py"),
282
275
  RequestBuildersSerializer(
283
276
  code_model=self.code_model,
@@ -300,7 +293,7 @@ class JinjaSerializer:
300
293
  async_mode=False,
301
294
  operation_group=operation_group,
302
295
  )
303
- self._autorestapi.write_file(
296
+ self.write_file(
304
297
  namespace_path
305
298
  / Path(self.code_model.operations_folder_name)
306
299
  / Path(f"{filename}.py"),
@@ -315,7 +308,7 @@ class JinjaSerializer:
315
308
  async_mode=True,
316
309
  operation_group=operation_group,
317
310
  )
318
- self._autorestapi.write_file(
311
+ self.write_file(
319
312
  (
320
313
  namespace_path
321
314
  / Path("aio")
@@ -332,7 +325,7 @@ class JinjaSerializer:
332
325
  operations_init_serializer = OperationsInitSerializer(
333
326
  code_model=self.code_model, env=env, async_mode=False
334
327
  )
335
- self._autorestapi.write_file(
328
+ self.write_file(
336
329
  namespace_path
337
330
  / Path(self.code_model.operations_folder_name)
338
331
  / Path("__init__.py"),
@@ -344,7 +337,7 @@ class JinjaSerializer:
344
337
  operations_async_init_serializer = OperationsInitSerializer(
345
338
  code_model=self.code_model, env=env, async_mode=True
346
339
  )
347
- self._autorestapi.write_file(
340
+ self.write_file(
348
341
  namespace_path
349
342
  / Path("aio")
350
343
  / Path(self.code_model.operations_folder_name)
@@ -369,12 +362,10 @@ class JinjaSerializer:
369
362
  self, namespace_path: Path, general_serializer: GeneralSerializer
370
363
  ):
371
364
  def _read_version_file(original_version_file_name: str) -> str:
372
- return self._autorestapi.read_file(
373
- namespace_path / original_version_file_name
374
- )
365
+ return self.read_file(namespace_path / original_version_file_name)
375
366
 
376
367
  def _write_version_file(original_version_file_name: str) -> None:
377
- self._autorestapi.write_file(
368
+ self.write_file(
378
369
  namespace_path / Path("_version.py"),
379
370
  _read_version_file(original_version_file_name),
380
371
  )
@@ -385,7 +376,7 @@ class JinjaSerializer:
385
376
  elif keep_version_file and _read_version_file("version.py"):
386
377
  _write_version_file(original_version_file_name="version.py")
387
378
  elif self.code_model.options["package_version"]:
388
- self._autorestapi.write_file(
379
+ self.write_file(
389
380
  namespace_path / Path("_version.py"),
390
381
  general_serializer.serialize_version_file(),
391
382
  )
@@ -397,14 +388,14 @@ class JinjaSerializer:
397
388
  code_model=self.code_model, env=env, async_mode=False
398
389
  )
399
390
 
400
- self._autorestapi.write_file(
391
+ self.write_file(
401
392
  namespace_path / Path("__init__.py"),
402
393
  general_serializer.serialize_init_file(),
403
394
  )
404
395
  p = namespace_path.parent
405
396
  while p != Path("."):
406
397
  # write pkgutil init file
407
- self._autorestapi.write_file(
398
+ self.write_file(
408
399
  p / Path("__init__.py"),
409
400
  general_serializer.serialize_pkgutil_init_file(),
410
401
  )
@@ -412,13 +403,13 @@ class JinjaSerializer:
412
403
 
413
404
  # Write the service client
414
405
  if self.code_model.request_builders:
415
- self._autorestapi.write_file(
406
+ self.write_file(
416
407
  namespace_path / Path(f"{self.code_model.client.filename}.py"),
417
408
  general_serializer.serialize_service_client_file(),
418
409
  )
419
410
 
420
411
  if self.code_model.need_vendored_code(async_mode=False):
421
- self._autorestapi.write_file(
412
+ self.write_file(
422
413
  namespace_path / Path("_vendor.py"),
423
414
  general_serializer.serialize_vendor_file(),
424
415
  )
@@ -426,31 +417,27 @@ class JinjaSerializer:
426
417
  self._serialize_and_write_version_file(namespace_path, general_serializer)
427
418
 
428
419
  # write the empty py.typed file
429
- self._autorestapi.write_file(
430
- namespace_path / Path("py.typed"), "# Marker file for PEP 561."
431
- )
420
+ self.write_file(namespace_path / Path("py.typed"), "# Marker file for PEP 561.")
432
421
 
433
422
  if (
434
423
  not self.code_model.options["client_side_validation"]
435
424
  and not self.code_model.options["multiapi"]
436
425
  ):
437
- self._autorestapi.write_file(
426
+ self.write_file(
438
427
  namespace_path / Path("_serialization.py"),
439
428
  general_serializer.serialize_serialization_file(),
440
429
  )
441
430
 
442
431
  # Write the config file
443
432
  if self.code_model.request_builders:
444
- self._autorestapi.write_file(
433
+ self.write_file(
445
434
  namespace_path / Path("_configuration.py"),
446
435
  general_serializer.serialize_config_file(),
447
436
  )
448
437
 
449
438
  # Write the setup file
450
439
  if self.code_model.options["basic_setup_py"]:
451
- self._autorestapi.write_file(
452
- Path("setup.py"), general_serializer.serialize_setup_file()
453
- )
440
+ self.write_file(Path("setup.py"), general_serializer.serialize_setup_file())
454
441
 
455
442
  def _serialize_and_write_aio_top_level_folder(
456
443
  self, env: Environment, namespace_path: Path
@@ -462,24 +449,24 @@ class JinjaSerializer:
462
449
  aio_path = namespace_path / Path("aio")
463
450
 
464
451
  # Write the __init__ file
465
- self._autorestapi.write_file(
452
+ self.write_file(
466
453
  aio_path / Path("__init__.py"), aio_general_serializer.serialize_init_file()
467
454
  )
468
455
 
469
456
  # Write the service client
470
457
  if self.code_model.request_builders:
471
- self._autorestapi.write_file(
458
+ self.write_file(
472
459
  aio_path / Path(f"{self.code_model.client.filename}.py"),
473
460
  aio_general_serializer.serialize_service_client_file(),
474
461
  )
475
462
 
476
463
  # Write the config file
477
- self._autorestapi.write_file(
464
+ self.write_file(
478
465
  aio_path / Path("_configuration.py"),
479
466
  aio_general_serializer.serialize_config_file(),
480
467
  )
481
468
  if self.code_model.need_vendored_code(async_mode=True):
482
- self._autorestapi.write_file(
469
+ self.write_file(
483
470
  aio_path / Path("_vendor.py"),
484
471
  aio_general_serializer.serialize_vendor_file(),
485
472
  )
@@ -488,6 +475,19 @@ class JinjaSerializer:
488
475
  self, env: Environment, namespace_path: Path
489
476
  ) -> None:
490
477
  metadata_serializer = MetadataSerializer(self.code_model, env)
491
- self._autorestapi.write_file(
478
+ self.write_file(
492
479
  namespace_path / Path("_metadata.json"), metadata_serializer.serialize()
493
480
  )
481
+
482
+
483
+ class JinjaSerializerAutorest(JinjaSerializer, ReaderAndWriterAutorest):
484
+ def __init__(
485
+ self,
486
+ autorestapi: AutorestAPI,
487
+ code_model: CodeModel,
488
+ *,
489
+ output_folder: Union[str, Path],
490
+ ) -> None:
491
+ super().__init__(
492
+ autorestapi=autorestapi, code_model=code_model, output_folder=output_folder
493
+ )
@@ -79,9 +79,7 @@ def _improve_json_string(template_representation: str) -> Any:
79
79
 
80
80
  def _json_dumps_template(template_representation: Any) -> Any:
81
81
  # only for template use, since it wraps everything in strings
82
- return _improve_json_string(
83
- json.dumps(template_representation, sort_keys=True, indent=4)
84
- )
82
+ return _improve_json_string(json.dumps(template_representation, indent=4))
85
83
 
86
84
 
87
85
  def _get_polymorphic_subtype_template(polymorphic_subtype: ModelType) -> List[str]:
@@ -16,6 +16,11 @@ class ClientSerializer:
16
16
  self.parameter_serializer = ParameterSerializer()
17
17
 
18
18
  def _init_signature(self, async_mode: bool) -> str:
19
+ pylint_disable = ""
20
+ if not self.code_model.client.parameters.credential:
21
+ pylint_disable = (
22
+ " # pylint: disable=missing-client-constructor-parameter-credential"
23
+ )
19
24
  return self.parameter_serializer.serialize_method(
20
25
  function_def="def",
21
26
  method_name="__init__",
@@ -23,6 +28,7 @@ class ClientSerializer:
23
28
  method_param_signatures=self.code_model.client.parameters.method_signature(
24
29
  async_mode
25
30
  ),
31
+ pylint_disable=pylint_disable,
26
32
  )
27
33
 
28
34
  def init_signature_and_response_type_annotation(self, async_mode: bool) -> str:
@@ -2,7 +2,7 @@
2
2
  # Microsoft Azure SDK for Python
3
3
 
4
4
  This is the Microsoft {{package_pprint_name}} Client Library.
5
- This package has been tested with Python 3.6+.
5
+ This package has been tested with Python 3.7+.
6
6
  For a more complete view of Azure libraries, see the [azure sdk python release](https://aka.ms/azsdk/python/all).
7
7
 
8
8
  # Usage
@@ -17,7 +17,7 @@ Additional code samples for different Azure services are available at [Samples R
17
17
 
18
18
  If you encounter any bugs or have suggestions, please file an issue in the
19
19
  [Issues](https://github.com/Azure/azure-sdk-for-python/issues)
20
- section of the project.
20
+ section of the project.
21
21
 
22
22
 
23
23
  ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2F{{package_name}}%2FREADME.png)
@@ -35,7 +35,7 @@ python -m pip install {{ package_name }}
35
35
 
36
36
  #### Prequisites
37
37
 
38
- - Python 3.6 or later is required to use this package.
38
+ - Python 3.7 or later is required to use this package.
39
39
  - You need an [Azure subscription][azure_sub] to use this package.
40
40
  - An existing {{ package_pprint_name }} instance.
41
41
 
@@ -54,7 +54,6 @@ setup(
54
54
  "Programming Language :: Python",
55
55
  "Programming Language :: Python :: 3 :: Only",
56
56
  "Programming Language :: Python :: 3",
57
- "Programming Language :: Python :: 3.6",
58
57
  "Programming Language :: Python :: 3.7",
59
58
  "Programming Language :: Python :: 3.8",
60
59
  "Programming Language :: Python :: 3.9",
@@ -94,7 +93,7 @@ setup(
94
93
  {% endif %}
95
94
  ],
96
95
  {% if package_mode %}
97
- python_requires=">=3.6",
96
+ python_requires=">=3.7",
98
97
  {% else %}
99
98
  long_description="""\
100
99
  {{ code_model.client.description }}
@@ -26,6 +26,7 @@ def GetPluginNames():
26
26
  "black",
27
27
  "multiapiscript",
28
28
  "postprocess",
29
+ "multiclientscript",
29
30
  ]
30
31
 
31
32
 
@@ -43,24 +44,29 @@ def Process(plugin_name: str, session_id: str) -> bool:
43
44
  session_id,
44
45
  )
45
46
  if plugin_name == "m2r":
46
- from ..m2r import M2R as PluginToLoad
47
+ from ..m2r import M2RAutorest as PluginToLoad
47
48
  elif plugin_name == "preprocess":
48
- from ..preprocess import PreProcessPlugin as PluginToLoad # type: ignore
49
+ from ..preprocess import PreProcessPluginAutorest as PluginToLoad # type: ignore
49
50
  elif plugin_name == "m4reformatter":
50
51
  from ..m4reformatter import M4Reformatter as PluginToLoad # type: ignore
51
52
  elif plugin_name == "codegen":
52
- from ..codegen import CodeGenerator as PluginToLoad # type: ignore
53
+ from ..codegen import CodeGeneratorAutorest as PluginToLoad # type: ignore
53
54
  elif plugin_name == "postprocess":
54
- from ..postprocess import PostProcessPlugin as PluginToLoad # type: ignore
55
+ from ..postprocess import PostProcessPluginAutorest as PluginToLoad # type: ignore
55
56
  elif plugin_name == "black":
56
- from ..black import BlackScriptPlugin as PluginToLoad # type: ignore
57
+ from ..black import BlackScriptPluginAutorest as PluginToLoad # type: ignore
57
58
  elif plugin_name == "multiapiscript":
58
- from ..multiapi import MultiApiScriptPlugin as PluginToLoad # type: ignore
59
+ from ..multiapi import MultiApiScriptPluginAutorest as PluginToLoad # type: ignore
60
+ elif plugin_name == "multiclientscript":
61
+ from ..multiclient import MultiClientPluginAutorest as PluginToLoad # type: ignore
59
62
  else:
60
63
  _LOGGER.fatal("Unknown plugin name %s", plugin_name)
61
64
  raise RuntimeError(f"Unknown plugin name {plugin_name}")
62
65
 
63
- plugin = PluginToLoad(stdstream_connection)
66
+ plugin = PluginToLoad(
67
+ autorestapi=stdstream_connection,
68
+ output_folder=stdstream_connection.get_value("output-folder"),
69
+ )
64
70
 
65
71
  try:
66
72
  _LOGGER.debug("Starting plugin %s", PluginToLoad.__name__)
@@ -8,25 +8,26 @@
8
8
  import logging
9
9
  from typing import Any, Dict, Set
10
10
 
11
- import m2r
11
+ import m2r2
12
12
 
13
- from .. import YamlUpdatePlugin
13
+ from .. import YamlUpdatePluginAutorest, YamlUpdatePlugin
14
+ from .._utils import parse_args
14
15
 
15
16
 
16
17
  _LOGGER = logging.getLogger(__name__)
17
18
 
18
19
 
19
- class AutorestRender(m2r.RestRenderer):
20
+ class AutorestRender(m2r2.RestRenderer):
20
21
  """Redefine the concept of inline HTML in the renderer, we don't want to define a new format
21
22
  in the description/summary.
22
23
  """
23
24
 
24
- def inline_html(self, html: str) -> str:
25
+ def inline_html(self, html: str) -> str: # pylint: disable=no-self-use
25
26
  """Do not render inline HTML with a role definition."""
26
27
  return f":code:`{html}`"
27
28
 
28
29
 
29
- class M2R(YamlUpdatePlugin):
30
+ class M2R(YamlUpdatePlugin): # pylint: disable=abstract-method
30
31
  """A plugin to convert any description and summary from MD to RST."""
31
32
 
32
33
  def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
@@ -55,6 +56,17 @@ class M2R(YamlUpdatePlugin):
55
56
  def convert_to_rst(string_to_convert: str) -> str:
56
57
  """Convert that string from MD to RST."""
57
58
  try:
58
- return m2r.convert(string_to_convert, renderer=AutorestRender()).strip()
59
+ return m2r2.convert(string_to_convert, renderer=AutorestRender()).strip()
59
60
  except Exception: # pylint: disable=broad-except
60
61
  return string_to_convert
62
+
63
+
64
+ class M2RAutorest(YamlUpdatePluginAutorest, M2R):
65
+ def get_options(self) -> Dict[str, Any]:
66
+ return {}
67
+
68
+
69
+ if __name__ == "__main__":
70
+ # CADL pipeline will call this
71
+ args = parse_args()
72
+ M2R(output_folder=args.output_folder, cadl_file=args.cadl_file).process()
@@ -11,7 +11,8 @@ import copy
11
11
  import logging
12
12
  from typing import Callable, Dict, Any, Iterable, List, Optional, Set
13
13
 
14
- from .. import YamlUpdatePlugin
14
+ from .._utils import to_snake_case
15
+ from .. import YamlUpdatePluginAutorest
15
16
 
16
17
  JSON_REGEXP = re.compile(r"^(application|text)/(.+\+)?json$")
17
18
  ORIGINAL_ID_TO_UPDATED_TYPE: Dict[int, Dict[str, Any]] = {}
@@ -431,7 +432,9 @@ def update_client_url(yaml_data: Dict[str, Any]) -> str:
431
432
  ]["uri"]
432
433
 
433
434
 
434
- class M4Reformatter(YamlUpdatePlugin): # pylint: disable=too-many-public-methods
435
+ class M4Reformatter(
436
+ YamlUpdatePluginAutorest
437
+ ): # pylint: disable=too-many-public-methods
435
438
  """Add Python naming information."""
436
439
 
437
440
  @property
@@ -1098,7 +1101,7 @@ class M4Reformatter(YamlUpdatePlugin): # pylint: disable=too-many-public-method
1098
1101
  if yaml_data.get("globalParameters")
1099
1102
  else "",
1100
1103
  "namespace": self._autorestapi.get_value("namespace")
1101
- or yaml_data["language"]["default"]["name"],
1104
+ or to_snake_case(yaml_data["info"]["title"].replace(" ", "")),
1102
1105
  }
1103
1106
 
1104
1107
  def update_yaml(self, yaml_data: Dict[str, Any]) -> None: