@autorest/python 5.13.0 → 5.16.0

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 (101) hide show
  1. package/ChangeLog.md +67 -0
  2. package/autorest/__init__.py +1 -2
  3. package/autorest/black/__init__.py +12 -5
  4. package/autorest/codegen/__init__.py +239 -105
  5. package/autorest/codegen/models/__init__.py +29 -18
  6. package/autorest/codegen/models/base_builder.py +48 -11
  7. package/autorest/codegen/models/base_model.py +6 -4
  8. package/autorest/codegen/models/base_schema.py +21 -24
  9. package/autorest/codegen/models/client.py +70 -20
  10. package/autorest/codegen/models/code_model.py +144 -129
  11. package/autorest/codegen/models/constant_schema.py +32 -16
  12. package/autorest/codegen/models/credential_model.py +55 -0
  13. package/autorest/codegen/models/credential_schema.py +21 -16
  14. package/autorest/codegen/models/credential_schema_policy.py +11 -15
  15. package/autorest/codegen/models/dictionary_schema.py +27 -24
  16. package/autorest/codegen/models/enum_schema.py +41 -62
  17. package/autorest/codegen/models/imports.py +72 -41
  18. package/autorest/codegen/models/list_schema.py +40 -18
  19. package/autorest/codegen/models/lro_operation.py +61 -25
  20. package/autorest/codegen/models/lro_paging_operation.py +5 -6
  21. package/autorest/codegen/models/object_schema.py +113 -59
  22. package/autorest/codegen/models/operation.py +251 -111
  23. package/autorest/codegen/models/operation_group.py +67 -32
  24. package/autorest/codegen/models/paging_operation.py +48 -21
  25. package/autorest/codegen/models/parameter.py +182 -90
  26. package/autorest/codegen/models/parameter_list.py +184 -163
  27. package/autorest/codegen/models/primitive_schemas.py +89 -70
  28. package/autorest/codegen/models/property.py +49 -31
  29. package/autorest/codegen/models/request_builder.py +67 -32
  30. package/autorest/codegen/models/request_builder_parameter.py +54 -23
  31. package/autorest/codegen/models/request_builder_parameter_list.py +77 -108
  32. package/autorest/codegen/models/schema_request.py +16 -6
  33. package/autorest/codegen/models/schema_response.py +35 -17
  34. package/autorest/codegen/models/utils.py +24 -1
  35. package/autorest/codegen/serializers/__init__.py +273 -89
  36. package/autorest/codegen/serializers/builder_serializer.py +711 -333
  37. package/autorest/codegen/serializers/client_serializer.py +114 -43
  38. package/autorest/codegen/serializers/general_serializer.py +84 -25
  39. package/autorest/codegen/serializers/import_serializer.py +93 -31
  40. package/autorest/codegen/serializers/metadata_serializer.py +73 -24
  41. package/autorest/codegen/serializers/model_base_serializer.py +42 -14
  42. package/autorest/codegen/serializers/model_generic_serializer.py +1 -4
  43. package/autorest/codegen/serializers/model_init_serializer.py +5 -1
  44. package/autorest/codegen/serializers/model_python3_serializer.py +9 -8
  45. package/autorest/codegen/serializers/operation_groups_serializer.py +20 -8
  46. package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
  47. package/autorest/codegen/serializers/patch_serializer.py +14 -2
  48. package/autorest/codegen/serializers/{rest_serializer.py → request_builders_serializer.py} +29 -12
  49. package/autorest/codegen/serializers/utils.py +60 -21
  50. package/autorest/codegen/templates/CHANGELOG.md.jinja2 +6 -0
  51. package/autorest/codegen/templates/LICENSE.jinja2 +21 -0
  52. package/autorest/codegen/templates/MANIFEST.in.jinja2 +7 -0
  53. package/autorest/codegen/templates/README.md.jinja2 +105 -0
  54. package/autorest/codegen/templates/config.py.jinja2 +4 -4
  55. package/autorest/codegen/templates/dev_requirements.txt.jinja2 +10 -0
  56. package/autorest/codegen/templates/enum.py.jinja2 +1 -1
  57. package/autorest/codegen/templates/enum_container.py.jinja2 +0 -1
  58. package/autorest/codegen/templates/init.py.jinja2 +9 -6
  59. package/autorest/codegen/templates/keywords.jinja2 +14 -1
  60. package/autorest/codegen/templates/lro_operation.py.jinja2 +5 -7
  61. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +5 -7
  62. package/autorest/codegen/templates/metadata.json.jinja2 +10 -9
  63. package/autorest/codegen/templates/model.py.jinja2 +1 -6
  64. package/autorest/codegen/templates/model_init.py.jinja2 +7 -4
  65. package/autorest/codegen/templates/operation.py.jinja2 +8 -11
  66. package/autorest/codegen/templates/operation_group.py.jinja2 +15 -18
  67. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
  68. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
  69. package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
  70. package/autorest/codegen/templates/patch.py.jinja2 +18 -29
  71. package/autorest/codegen/templates/request_builder.py.jinja2 +19 -14
  72. package/autorest/codegen/templates/setup.py.jinja2 +79 -20
  73. package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
  74. package/autorest/jsonrpc/__init__.py +7 -12
  75. package/autorest/jsonrpc/localapi.py +4 -3
  76. package/autorest/jsonrpc/server.py +13 -6
  77. package/autorest/jsonrpc/stdstream.py +13 -6
  78. package/autorest/m2r/__init__.py +5 -8
  79. package/autorest/multiapi/__init__.py +24 -14
  80. package/autorest/multiapi/models/client.py +21 -11
  81. package/autorest/multiapi/models/code_model.py +23 -10
  82. package/autorest/multiapi/models/config.py +4 -1
  83. package/autorest/multiapi/models/constant_global_parameter.py +1 -0
  84. package/autorest/multiapi/models/global_parameter.py +2 -1
  85. package/autorest/multiapi/models/global_parameters.py +14 -8
  86. package/autorest/multiapi/models/imports.py +35 -18
  87. package/autorest/multiapi/models/mixin_operation.py +5 -5
  88. package/autorest/multiapi/models/operation_group.py +2 -1
  89. package/autorest/multiapi/models/operation_mixin_group.py +21 -10
  90. package/autorest/multiapi/serializers/__init__.py +18 -23
  91. package/autorest/multiapi/serializers/import_serializer.py +47 -15
  92. package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
  93. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
  94. package/autorest/multiapi/utils.py +3 -3
  95. package/autorest/namer/__init__.py +2 -4
  96. package/autorest/namer/name_converter.py +200 -103
  97. package/autorest/namer/python_mappings.py +10 -22
  98. package/package.json +3 -3
  99. package/run-python3.js +2 -3
  100. package/venvtools.py +1 -1
  101. package/autorest/codegen/models/rest.py +0 -42
@@ -1,22 +1,21 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools with context %}
2
2
  {# actual template starts here #}
3
- {% if code_model.options['tracing'] and operation.want_tracing %}
4
- @distributed_trace
5
- {% endif %}
6
- {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
3
+ {{ operation_serializer.method_signature_and_response_type_annotation(operation, async_mode) }}
7
4
  {% if operation.want_description_docstring %}
8
5
  {{ op_tools.description(operation, operation_serializer) | indent }}{% endif %}
9
- {% if operation.deprecated %}
6
+ {% if not operation.abstract %}
7
+ {% if operation.deprecated %}
10
8
  warnings.warn('Method {{operation.name}} is deprecated', DeprecationWarning)
11
- {% endif %}
12
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
9
+ {% endif %}
10
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
13
11
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
14
- {% endif %}
12
+ {% endif %}
15
13
  {{ op_tools.serialize(operation_serializer.set_up_params_for_pager(operation)) | indent }}
16
14
 
17
15
  return {{ operation.get_pager(async_mode) }}(
18
16
  get_next, extract_data
19
17
  )
18
+ {% endif %}
20
19
  {% if not code_model.options["version_tolerant"] %}
21
20
  {{ operation_serializer.get_metadata_url(operation) -}}
22
21
  {% endif %}
@@ -1,31 +1,20 @@
1
- # coding=utf-8
2
- # --------------------------------------------------------------------------
3
- #
4
- # Copyright (c) Microsoft Corporation. All rights reserved.
5
- #
6
- # The MIT License (MIT)
7
- #
8
- # Permission is hereby granted, free of charge, to any person obtaining a copy
9
- # of this software and associated documentation files (the ""Software""), to
10
- # deal in the Software without restriction, including without limitation the
11
- # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
- # sell copies of the Software, and to permit persons to whom the Software is
13
- # furnished to do so, subject to the following conditions:
14
- #
15
- # The above copyright notice and this permission notice shall be included in
16
- # all copies or substantial portions of the Software.
17
- #
18
- # THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
- # IN THE SOFTWARE.
25
- #
26
- # --------------------------------------------------------------------------
1
+ # ------------------------------------
2
+ # Copyright (c) Microsoft Corporation.
3
+ # Licensed under the MIT License.
4
+ # ------------------------------------
5
+ """Customize generated code here.
6
+
7
+ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
8
+ """
9
+ {{ imports }}
10
+
11
+ {% set type_annotation = ": List[str]" %}
12
+ __all__{{ type_annotation if is_python3_file else "" }} = []{{ "" if is_python3_file else (" # type" + type_annotation) }} # Add all objects you want publicly available to users at this package level
27
13
 
28
- # This file is used for handwritten extensions to the generated code. Example:
29
- # https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
30
14
  def patch_sdk():
31
- pass
15
+ """Do not remove from this file.
16
+
17
+ `patch_sdk` is a last resort escape hatch that allows you to do customizations
18
+ you can't accomplish using the techniques described in
19
+ https://aka.ms/azsdk/python/dpcodegen/python/customize
20
+ """
@@ -1,28 +1,33 @@
1
1
  {% import 'keywords.jinja2' as keywords with context %}
2
2
  {% import 'operation_tools.jinja2' as op_tools with context %}
3
- {{ request_builder_serializer.method_signature_and_response_type_annotation(request_builder) }}
3
+ {{ request_builder_serializer.method_signature_and_response_type_annotation(request_builder, False) }}
4
4
  {% if code_model.options["builders_visibility"] == "public" %}
5
5
  {{ op_tools.description(request_builder, request_builder_serializer) | indent }}
6
6
  {% endif %}
7
- {% if request_builder.parameters.kwargs_to_pop(is_python3_file) %}
7
+ {% if request_builder.abstract %}
8
+ raise NotImplementedError(
9
+ "You need to write a custom operation for '{{ request_builder.name }}'. "
10
+ "Please refer to https://aka.ms/azsdk/python/dpcodegen/python/customize to learn how to customize."
11
+ )
12
+ {% else %}
13
+ {% if request_builder_serializer.pop_kwargs_from_signature(request_builder) %}
8
14
  {{ op_tools.serialize(request_builder_serializer.pop_kwargs_from_signature(request_builder)) | indent }}
9
- {% endif %}
10
- {% if request_builder.parameters.constant|selectattr("original_parameter", "equalto", None)|selectattr("in_method_code")|selectattr("in_method_signature", "equalto", False) %}
11
- {% for constant_parameter in request_builder.parameters.constant|selectattr("original_parameter", "equalto", None)|selectattr("in_method_code")|selectattr("in_method_signature", "equalto", False) %}
12
- {{ constant_parameter.serialized_name }} = {{ constant_parameter.constant_declaration }}
13
- {% endfor %}
14
- {% endif %}
15
+ {%- endif -%}
16
+ {% if request_builder_serializer.declare_non_inputtable_constants(request_builder) %}
17
+ {{ op_tools.serialize(request_builder_serializer.declare_non_inputtable_constants(request_builder)) | indent }}
18
+ {% endif %}
15
19
  # Construct URL
16
20
  {{ request_builder_serializer.construct_url(request_builder) }}
17
- {% if request_builder.parameters.path %}
21
+ {% if request_builder.parameters.path %}
18
22
  {{ op_tools.serialize(request_builder_serializer.serialize_path(request_builder)) | indent }}
19
23
  _url = _format_url_section(_url, **path_format_arguments)
20
- {% endif %}
24
+ {% endif %}
21
25
 
22
- {% if request_builder.parameters.query %}
26
+ {% if request_builder.parameters.query %}
23
27
  {{ op_tools.serialize(request_builder_serializer.serialize_query(request_builder)) | indent }}
24
- {% endif %}
25
- {% if request_builder.parameters.headers %}
28
+ {% endif %}
29
+ {% if request_builder.parameters.headers %}
26
30
  {{ op_tools.serialize(request_builder_serializer.serialize_headers(request_builder)) | indent }}
27
- {% endif %}
31
+ {% endif %}
28
32
  {{ op_tools.serialize(request_builder_serializer.create_http_request(request_builder)) | indent }}
33
+ {% endif %}
@@ -1,34 +1,93 @@
1
- {% set name = code_model.options["package_name"] or code_model.class_name %}
2
- {% set azure_mgmt_core_import = ', "azure-mgmt-core<2.0.0,>=1.2.1"' if code_model.options["azure_arm"] else "" %}
3
1
  # coding=utf-8
4
- {{ code_model.options['license_header'] }}
2
+ {{ license_header }}
5
3
  # coding: utf-8
6
-
4
+ {% if package_mode %}
5
+ import os
6
+ import re
7
+ {% endif -%}
7
8
  from setuptools import setup, find_packages
8
9
 
9
- NAME = "{{ name|lower }}"
10
- VERSION = "{{ code_model.options.get('package_version', '0.0.0') }}"
10
+ {% set package_name_render = package_name or code_model.class_name %}
11
+
12
+ PACKAGE_NAME = "{{ package_name_render|lower }}"
13
+ {% if package_mode -%}
14
+ PACKAGE_PPRINT_NAME = "{{ package_pprint_name }}"
15
+
16
+ # a-b-c => a/b/c
17
+ package_folder_path = PACKAGE_NAME.replace("-", "/")
11
18
 
12
- # To install the library, run the following
13
- #
14
- # python setup.py install
15
- #
16
- # prerequisite: setuptools
17
- # http://pypi.python.org/pypi/setuptools
19
+ # Version extraction inspired from 'requests'
20
+ with open(os.path.join(package_folder_path, "_version.py"), "r") as fd:
21
+ version = re.search(
22
+ r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE
23
+ ).group(1)
18
24
 
19
- REQUIRES = ["msrest>=0.6.21", "azure-core<2.0.0,>=1.20.1"{{ azure_mgmt_core_import }}]
25
+ if not version:
26
+ raise RuntimeError("Cannot find version information")
27
+ {% set description = "Microsoft %s Client Library for Python"|format(package_pprint_name) %}
28
+ {% set author_email = "azpysdkhelp@microsoft.com" %}
29
+ {% set url = "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk" %}
30
+ {% else %}
31
+ version = "{{ code_model.options['package_version'] }}"
32
+ {% set description = "%s"|format(package_name_render) %}
33
+ {% set long_description = code_model.description %}
34
+ {% set author_email = "" %}
35
+ {% set url = "" %}
36
+ {% endif -%}
20
37
 
21
38
  setup(
22
- name=NAME,
23
- version=VERSION,
24
- description="{{ name }}",
25
- author_email="",
26
- url="",
27
- keywords=["Swagger", "{{ code_model.class_name }}"],
28
- install_requires=REQUIRES,
39
+ name=PACKAGE_NAME,
40
+ version=version,
41
+ description="{{ description }}",
42
+ {% if package_mode %}
43
+ long_description=open("README.md", "r").read(),
44
+ long_description_content_type="text/markdown",
45
+ license="MIT License",
46
+ author="Microsoft Corporation",
47
+ {% endif %}
48
+ author_email="{{ author_email }}",
49
+ url="{{ url }}",
50
+ keywords="azure, azure sdk",
51
+ {% if package_mode %}
52
+ classifiers=[
53
+ "Development Status :: {{ dev_status }}",
54
+ "Programming Language :: Python",
55
+ "Programming Language :: Python :: 3 :: Only",
56
+ "Programming Language :: Python :: 3",
57
+ "Programming Language :: Python :: 3.6",
58
+ "Programming Language :: Python :: 3.7",
59
+ "Programming Language :: Python :: 3.8",
60
+ "Programming Language :: Python :: 3.9",
61
+ "Programming Language :: Python :: 3.10",
62
+ "License :: OSI Approved :: MIT License",
63
+ ],
64
+ zip_safe=False,
65
+ packages=find_packages(
66
+ exclude=[
67
+ "tests",
68
+ # Exclude packages that will be covered by PEP420 or nspkg
69
+ {%- for pkgutil_name in pkgutil_names %}
70
+ "{{ pkgutil_name }}",
71
+ {%- endfor %}
72
+ ]
73
+ ),
74
+ {% else %}
29
75
  packages=find_packages(),
30
76
  include_package_data=True,
77
+ {% endif %}
78
+ install_requires=[
79
+ "{{ dependency_msrest }}",
80
+ {% if azure_arm %}
81
+ "{{ dependency_azure_mgmt_core }}",
82
+ {% else %}
83
+ "{{ dependency_azure_core }}",
84
+ {% endif %}
85
+ ],
86
+ {% if package_mode %}
87
+ python_requires=">=3.6",
88
+ {% else %}
31
89
  long_description="""\
32
90
  {{ code_model.description }}
33
91
  """
92
+ {% endif %}
34
93
  )
@@ -1,8 +1,9 @@
1
+ {% import 'keywords.jinja2' as keywords with context %}
1
2
  {{ code_model.options['license_header'] }}
2
3
 
3
4
  {{ imports }}
4
5
 
5
- {% if code_model.need_request_converter %}
6
+ {% if code_model.need_request_converter and not async_mode %}
6
7
  def _convert_request(request, files=None):
7
8
  data = request.content if not files else None
8
9
  request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data)
@@ -10,7 +11,7 @@ def _convert_request(request, files=None):
10
11
  request.set_formdata_body(files)
11
12
  return request
12
13
  {% endif %}
13
- {% if code_model.need_format_url %}
14
+ {% if code_model.need_format_url and not async_mode %}
14
15
 
15
16
  def _format_url_section(template, **kwargs):
16
17
  components = template.split("/")
@@ -24,3 +25,12 @@ def _format_url_section(template, **kwargs):
24
25
  ]
25
26
  template = "/".join(components)
26
27
  {% endif %}
28
+ {% if code_model.need_mixin_abc %}
29
+
30
+ class MixinABC(ABC):
31
+ """DO NOT use this class. It is for internal typing use only."""
32
+ _client: "{{ keywords.async_class }}PipelineClient"
33
+ _config: {{ code_model.class_name }}Configuration
34
+ _serialize: "Serializer"
35
+ _deserialize: "Deserializer"
36
+ {% endif %}
@@ -7,7 +7,7 @@ from abc import ABC, abstractmethod
7
7
  from enum import Enum
8
8
  from typing import Any, List, Optional, Union
9
9
  import logging
10
- import logging.config # need to include this extra import so mypy doesn't throw logging module has no config
10
+ import logging.config # need to include this extra import so mypy doesn't throw logging module has no config
11
11
  from pathlib import Path
12
12
 
13
13
 
@@ -45,13 +45,12 @@ class AutorestHandler(logging.Handler):
45
45
  # Initialize this handler with the max loglevel, since
46
46
  # autorest is deciding what to show, not us
47
47
  # so we want to log everything and let autorest filters.
48
- super(AutorestHandler, self).__init__(logging.DEBUG)
48
+ super().__init__(logging.DEBUG)
49
49
  self._autorest_api = autorest_api
50
50
 
51
51
  @staticmethod
52
52
  def _get_log_level(level: int) -> Channel:
53
- """Convert Python log levels to Autorest Channel.
54
- """
53
+ """Convert Python log levels to Autorest Channel."""
55
54
  return _LEVEL_MAPPING.get(level, Channel.Warning)
56
55
 
57
56
  def emit(self, record: logging.LogRecord) -> None:
@@ -65,8 +64,7 @@ class AutorestHandler(logging.Handler):
65
64
 
66
65
 
67
66
  class AutorestAPI(ABC):
68
- """Defines the base interface of communication to Autorest from the plugin.
69
- """
67
+ """Defines the base interface of communication to Autorest from the plugin."""
70
68
 
71
69
  def __init__(self) -> None:
72
70
  if Path("logging.conf").exists():
@@ -106,18 +104,15 @@ class AutorestAPI(ABC):
106
104
 
107
105
  @abstractmethod
108
106
  def list_inputs(self) -> List[str]:
109
- """List possible inputs for this plugin.
110
- """
107
+ """List possible inputs for this plugin."""
111
108
 
112
109
  @abstractmethod
113
110
  def get_value(self, key: str) -> Any:
114
- """Get a value from configuration.
115
- """
111
+ """Get a value from configuration."""
116
112
 
117
113
  @abstractmethod
118
114
  def message(self, channel: Channel, text: str) -> None:
119
- """Send a log message to autorest.
120
- """
115
+ """Send a log message to autorest."""
121
116
 
122
117
  def get_boolean_value(self, key: str, default: bool = None) -> Optional[bool]:
123
118
  """Check if value is present on the line, and interpret it as bool if it was.
@@ -14,10 +14,11 @@ _LOGGER = logging.getLogger(__name__)
14
14
 
15
15
 
16
16
  class LocalAutorestAPI(AutorestAPI):
17
- """A local API that will write on local disk.
18
- """
17
+ """A local API that will write on local disk."""
19
18
 
20
- def __init__(self, reachable_files: List[str] = None, output_folder: str = "generated") -> None:
19
+ def __init__(
20
+ self, reachable_files: List[str] = None, output_folder: str = "generated"
21
+ ) -> None:
21
22
  super().__init__()
22
23
  if reachable_files is None:
23
24
  reachable_files = []
@@ -24,13 +24,16 @@ def GetPluginNames():
24
24
  @dispatcher.add_method
25
25
  def Process(plugin_name: str, session_id: str) -> bool:
26
26
  # pylint: disable=import-outside-toplevel
27
- """JSON-RPC process call.
28
- """
27
+ """JSON-RPC process call."""
29
28
  from .stdstream import StdStreamAutorestAPI
30
29
 
31
30
  with contextlib.closing(StdStreamAutorestAPI(session_id)) as stdstream_connection:
32
31
 
33
- _LOGGER.debug("Autorest called process with plugin_name '%s' and session_id: '%s'", plugin_name, session_id)
32
+ _LOGGER.debug(
33
+ "Autorest called process with plugin_name '%s' and session_id: '%s'",
34
+ plugin_name,
35
+ session_id,
36
+ )
34
37
  if plugin_name == "m2r":
35
38
  from ..m2r import M2R as PluginToLoad
36
39
  elif plugin_name == "namer":
@@ -38,7 +41,7 @@ def Process(plugin_name: str, session_id: str) -> bool:
38
41
  elif plugin_name == "codegen":
39
42
  from ..codegen import CodeGenerator as PluginToLoad # type: ignore
40
43
  elif plugin_name == "black":
41
- from ..black import BlackScriptPlugin as PluginToLoad # type: ignore
44
+ from ..black import BlackScriptPlugin as PluginToLoad # type: ignore
42
45
  elif plugin_name == "multiapiscript":
43
46
  from ..multiapi import MultiApiScriptPlugin as PluginToLoad # type: ignore
44
47
  else:
@@ -58,11 +61,15 @@ def Process(plugin_name: str, session_id: str) -> bool:
58
61
  def main() -> None:
59
62
  # If --python.debugger is specified on the command line, we call the server.py file internally
60
63
  # with flag --debug.
61
- if '--debug' in sys.argv or os.environ.get("AUTOREST_PYTHON_ATTACH_VSCODE_DEBUG", False):
64
+ if "--debug" in sys.argv or os.environ.get(
65
+ "AUTOREST_PYTHON_ATTACH_VSCODE_DEBUG", False
66
+ ):
62
67
  try:
63
68
  import ptvsd # pylint: disable=import-outside-toplevel
64
69
  except ImportError:
65
- raise SystemExit("Please pip install ptvsd in order to use VSCode debugging")
70
+ raise SystemExit(
71
+ "Please pip install ptvsd in order to use VSCode debugging"
72
+ )
66
73
 
67
74
  # 5678 is the default attach port in the VS Code debug configurations
68
75
  ptvsd.enable_attach(address=("localhost", 5678), redirect_output=True)
@@ -53,8 +53,7 @@ def write_message(message: str, stream: BinaryIO = sys.stdout.buffer) -> None:
53
53
 
54
54
 
55
55
  class StdStreamAutorestAPI(AutorestAPI):
56
- """The stream API with Autorest
57
- """
56
+ """The stream API with Autorest"""
58
57
 
59
58
  def __init__(self, session_id: str) -> None:
60
59
  super().__init__()
@@ -73,19 +72,25 @@ class StdStreamAutorestAPI(AutorestAPI):
73
72
  def read_file(self, filename: Union[str, Path]) -> str:
74
73
  _LOGGER.debug("Asking content for file %s", filename)
75
74
  filename = os.fspath(filename)
76
- request = JSONRPC20Request(method="ReadFile", params=[self.session_id, filename], _id=42)
75
+ request = JSONRPC20Request(
76
+ method="ReadFile", params=[self.session_id, filename], _id=42
77
+ )
77
78
  write_message(request.json)
78
79
  return json.loads(read_message())["result"]
79
80
 
80
81
  def list_inputs(self) -> List[str]:
81
82
  _LOGGER.debug("Calling list inputs to Autorest")
82
- request = JSONRPC20Request(method="ListInputs", params=[self.session_id, None], _id=42)
83
+ request = JSONRPC20Request(
84
+ method="ListInputs", params=[self.session_id, None], _id=42
85
+ )
83
86
  write_message(request.json)
84
87
  return json.loads(read_message())["result"]
85
88
 
86
89
  def get_value(self, key: str) -> Any:
87
90
  _LOGGER.debug("Calling get value to Autorest: %s", key)
88
- request = JSONRPC20Request(method="GetValue", params=[self.session_id, key], _id=42)
91
+ request = JSONRPC20Request(
92
+ method="GetValue", params=[self.session_id, key], _id=42
93
+ )
89
94
  write_message(request.json)
90
95
  return json.loads(read_message())["result"]
91
96
 
@@ -96,5 +101,7 @@ class StdStreamAutorestAPI(AutorestAPI):
96
101
  "Channel": channel.value,
97
102
  "Text": text,
98
103
  }
99
- request = JSONRPC20Request(method="Message", params=[self.session_id, message], is_notification=True)
104
+ request = JSONRPC20Request(
105
+ method="Message", params=[self.session_id, message], is_notification=True
106
+ )
100
107
  write_message(request.json)
@@ -27,18 +27,16 @@ class AutorestRender(m2r.RestRenderer):
27
27
 
28
28
 
29
29
  class M2R(YamlUpdatePlugin):
30
- """A plugin to convert any description and summary from MD to RST.
31
- """
30
+ """A plugin to convert any description and summary from MD to RST."""
31
+
32
32
  def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
33
- """Convert in place the YAML str.
34
- """
33
+ """Convert in place the YAML str."""
35
34
  self._convert_docstring_no_cycles(yaml_data, set())
36
35
 
37
36
  def _convert_docstring_no_cycles(
38
37
  self, yaml_data: Dict[str, Any], node_list: Set[int]
39
38
  ) -> None:
40
- """Walk the YAML tree to convert MD to RST.
41
- """
39
+ """Walk the YAML tree to convert MD to RST."""
42
40
  if id(yaml_data) in node_list:
43
41
  return
44
42
  node_list.add(id(yaml_data))
@@ -55,8 +53,7 @@ class M2R(YamlUpdatePlugin):
55
53
 
56
54
  @staticmethod
57
55
  def convert_to_rst(string_to_convert: str) -> str:
58
- """Convert that string from MD to RST.
59
- """
56
+ """Convert that string from MD to RST."""
60
57
  try:
61
58
  return m2r.convert(string_to_convert, renderer=AutorestRender()).strip()
62
59
  except Exception: # pylint: disable=broad-except
@@ -32,7 +32,7 @@ class MultiApiScriptPlugin(Plugin):
32
32
  output_folder,
33
33
  self._autorestapi,
34
34
  no_async,
35
- user_specified_default_api
35
+ user_specified_default_api,
36
36
  )
37
37
  return generator.process()
38
38
 
@@ -44,10 +44,12 @@ class MultiAPI:
44
44
  output_folder: str,
45
45
  autorestapi: AutorestAPI,
46
46
  no_async: Optional[bool] = False,
47
- user_specified_default_api: Optional[str] = None
47
+ user_specified_default_api: Optional[str] = None,
48
48
  ) -> None:
49
49
  if input_package_name is None:
50
- raise ValueError("package-name is required, either provide it as args or check your readme configuration")
50
+ raise ValueError(
51
+ "package-name is required, either provide it as args or check your readme configuration"
52
+ )
51
53
  self.input_package_name = input_package_name
52
54
  _LOGGER.debug("Received package name %s", input_package_name)
53
55
 
@@ -64,7 +66,7 @@ class MultiAPI:
64
66
  self.mod_to_api_version,
65
67
  [p.name for p in self.paths_to_versions],
66
68
  self.preview_mode,
67
- self.user_specified_default_api
69
+ self.user_specified_default_api,
68
70
  )
69
71
 
70
72
  @property
@@ -75,7 +77,9 @@ class MultiAPI:
75
77
  if self.default_api_version.replace("-", "_") == path_to_version.stem:
76
78
  path_to_default_version = path_to_version
77
79
  break
78
- return json.loads(self._autorestapi.read_file(path_to_default_version / "_metadata.json"))
80
+ return json.loads(
81
+ self._autorestapi.read_file(path_to_default_version / "_metadata.json")
82
+ )
79
83
 
80
84
  @property
81
85
  def module_name(self) -> str:
@@ -96,7 +100,11 @@ class MultiAPI:
96
100
  def preview_mode(self) -> bool:
97
101
  # If True, means the auto-profile will consider preview versions.
98
102
  # If not, if it exists a stable API version for a global or RT, will always be used
99
- return cast(bool, self.user_specified_default_api and "preview" in self.user_specified_default_api)
103
+ return cast(
104
+ bool,
105
+ self.user_specified_default_api
106
+ and "preview" in self.user_specified_default_api,
107
+ )
100
108
 
101
109
  @property
102
110
  def paths_to_versions(self) -> List[Path]:
@@ -105,14 +113,16 @@ class MultiAPI:
105
113
  directory.sort()
106
114
  for child in directory:
107
115
  child_dir = (self.output_folder / child).resolve()
108
- if Path(child_dir / '_metadata.json') in child_dir.iterdir():
116
+ if Path(child_dir / "_metadata.json") in child_dir.iterdir():
109
117
  paths_to_versions.append(Path(child.stem))
110
118
  return paths_to_versions
111
119
 
112
120
  @property
113
121
  def version_path_to_metadata(self) -> Dict[Path, Dict[str, Any]]:
114
122
  return {
115
- version_path: json.loads(self._autorestapi.read_file(version_path / "_metadata.json"))
123
+ version_path: json.loads(
124
+ self._autorestapi.read_file(version_path / "_metadata.json")
125
+ )
116
126
  for version_path in self.paths_to_versions
117
127
  }
118
128
 
@@ -120,18 +130,18 @@ class MultiAPI:
120
130
  def mod_to_api_version(self) -> Dict[str, str]:
121
131
  mod_to_api_version: Dict[str, str] = defaultdict(str)
122
132
  for version_path in self.paths_to_versions:
123
- metadata_json = json.loads(self._autorestapi.read_file(version_path / "_metadata.json"))
124
- version = metadata_json['chosen_version']
125
- total_api_version_list = metadata_json['total_api_version_list']
133
+ metadata_json = json.loads(
134
+ self._autorestapi.read_file(version_path / "_metadata.json")
135
+ )
136
+ version = metadata_json["chosen_version"]
137
+ total_api_version_list = metadata_json["total_api_version_list"]
126
138
  if not version:
127
139
  if total_api_version_list:
128
140
  sys.exit(
129
141
  f"Unable to match {total_api_version_list} to label {version_path.stem}"
130
142
  )
131
143
  else:
132
- sys.exit(
133
- f"Unable to extract api version of {version_path.stem}"
134
- )
144
+ sys.exit(f"Unable to extract api version of {version_path.stem}")
135
145
  mod_to_api_version[version_path.name] = version
136
146
  return mod_to_api_version
137
147
 
@@ -9,54 +9,64 @@ from typing import Any, Dict, List
9
9
  from pathlib import Path
10
10
  from .imports import FileImport
11
11
 
12
+
12
13
  def _extract_version(metadata_json: Dict[str, Any], version_path: Path) -> str:
13
- version = metadata_json['chosen_version']
14
- total_api_version_list = metadata_json['total_api_version_list']
14
+ version = metadata_json["chosen_version"]
15
+ total_api_version_list = metadata_json["total_api_version_list"]
15
16
  if not version:
16
17
  if total_api_version_list:
17
18
  sys.exit(
18
19
  f"Unable to match {total_api_version_list} to label {version_path.stem}"
19
20
  )
20
21
  else:
21
- sys.exit(
22
- f"Unable to extract api version of {version_path.stem}"
23
- )
22
+ sys.exit(f"Unable to extract api version of {version_path.stem}")
24
23
  return version
25
24
 
25
+
26
26
  class Client:
27
27
  def __init__(
28
28
  self,
29
29
  azure_arm: bool,
30
30
  default_version_metadata: Dict[str, Any],
31
- version_path_to_metadata: Dict[Path, Dict[str, Any]]
31
+ version_path_to_metadata: Dict[Path, Dict[str, Any]],
32
32
  ):
33
33
  self.name = default_version_metadata["client"]["name"]
34
34
  self.pipeline_client = "ARMPipelineClient" if azure_arm else "PipelineClient"
35
35
  self.filename = default_version_metadata["client"]["filename"]
36
36
  self.host_value = default_version_metadata["client"]["host_value"]
37
37
  self.description = default_version_metadata["client"]["description"]
38
- self.client_side_validation = default_version_metadata["client"]["client_side_validation"]
38
+ self.client_side_validation = default_version_metadata["client"][
39
+ "client_side_validation"
40
+ ]
39
41
  self.default_version_metadata = default_version_metadata
40
42
  self.version_path_to_metadata = version_path_to_metadata
41
43
 
42
44
  def imports(self, async_mode: bool) -> FileImport:
43
45
  imports_to_load = "async_imports" if async_mode else "sync_imports"
44
- return FileImport(json.loads(self.default_version_metadata['client'][imports_to_load]))
46
+ return FileImport(
47
+ json.loads(self.default_version_metadata["client"][imports_to_load])
48
+ )
45
49
 
46
50
  @property
47
51
  def parameterized_host_template_to_api_version(self) -> Dict[str, List[str]]:
48
52
  parameterized_host_template_to_api_version: Dict[str, List[str]] = {}
49
53
  for version_path, metadata_json in self.version_path_to_metadata.items():
50
- parameterized_host_template = metadata_json["client"]["parameterized_host_template"]
54
+ parameterized_host_template = metadata_json["client"][
55
+ "parameterized_host_template"
56
+ ]
51
57
  version = _extract_version(metadata_json, version_path)
52
- parameterized_host_template_to_api_version.setdefault(parameterized_host_template, []).append(version)
58
+ parameterized_host_template_to_api_version.setdefault(
59
+ parameterized_host_template, []
60
+ ).append(version)
53
61
  return parameterized_host_template_to_api_version
54
62
 
55
63
  @property
56
64
  def has_lro_operations(self) -> bool:
57
65
  has_lro_operations = False
58
66
  for _, metadata_json in self.version_path_to_metadata.items():
59
- current_client_has_lro_operations = metadata_json["client"]["has_lro_operations"]
67
+ current_client_has_lro_operations = metadata_json["client"][
68
+ "has_lro_operations"
69
+ ]
60
70
  if current_client_has_lro_operations:
61
71
  has_lro_operations = True
62
72
  return has_lro_operations