@autorest/python 5.15.0 → 5.18.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 (118) hide show
  1. package/ChangeLog.md +98 -4
  2. package/README.md +30 -4
  3. package/autorest/__init__.py +2 -3
  4. package/autorest/black/__init__.py +12 -5
  5. package/autorest/codegen/__init__.py +122 -211
  6. package/autorest/codegen/models/__init__.py +122 -78
  7. package/autorest/codegen/models/base_builder.py +70 -72
  8. package/autorest/codegen/models/base_model.py +7 -5
  9. package/autorest/codegen/models/{base_schema.py → base_type.py} +68 -45
  10. package/autorest/codegen/models/client.py +193 -40
  11. package/autorest/codegen/models/code_model.py +145 -245
  12. package/autorest/codegen/models/combined_type.py +107 -0
  13. package/autorest/codegen/models/constant_type.py +122 -0
  14. package/autorest/codegen/models/credential_types.py +224 -0
  15. package/autorest/codegen/models/dictionary_type.py +131 -0
  16. package/autorest/codegen/models/enum_type.py +195 -0
  17. package/autorest/codegen/models/imports.py +93 -41
  18. package/autorest/codegen/models/list_type.py +149 -0
  19. package/autorest/codegen/models/lro_operation.py +90 -133
  20. package/autorest/codegen/models/lro_paging_operation.py +28 -12
  21. package/autorest/codegen/models/model_type.py +262 -0
  22. package/autorest/codegen/models/operation.py +412 -259
  23. package/autorest/codegen/models/operation_group.py +80 -91
  24. package/autorest/codegen/models/paging_operation.py +101 -117
  25. package/autorest/codegen/models/parameter.py +302 -341
  26. package/autorest/codegen/models/parameter_list.py +373 -357
  27. package/autorest/codegen/models/primitive_types.py +544 -0
  28. package/autorest/codegen/models/property.py +136 -134
  29. package/autorest/codegen/models/request_builder.py +138 -86
  30. package/autorest/codegen/models/request_builder_parameter.py +122 -86
  31. package/autorest/codegen/models/response.py +325 -0
  32. package/autorest/codegen/models/utils.py +13 -17
  33. package/autorest/codegen/serializers/__init__.py +212 -112
  34. package/autorest/codegen/serializers/builder_serializer.py +931 -1040
  35. package/autorest/codegen/serializers/client_serializer.py +140 -84
  36. package/autorest/codegen/serializers/general_serializer.py +26 -50
  37. package/autorest/codegen/serializers/import_serializer.py +96 -31
  38. package/autorest/codegen/serializers/metadata_serializer.py +39 -79
  39. package/autorest/codegen/serializers/model_base_serializer.py +62 -34
  40. package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
  41. package/autorest/codegen/serializers/model_init_serializer.py +4 -2
  42. package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
  43. package/autorest/codegen/serializers/operation_groups_serializer.py +21 -19
  44. package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
  45. package/autorest/codegen/serializers/parameter_serializer.py +174 -0
  46. package/autorest/codegen/serializers/patch_serializer.py +4 -1
  47. package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
  48. package/autorest/codegen/serializers/utils.py +0 -126
  49. package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
  50. package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
  51. package/autorest/codegen/templates/config.py.jinja2 +13 -13
  52. package/autorest/codegen/templates/enum.py.jinja2 +4 -4
  53. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
  54. package/autorest/codegen/templates/init.py.jinja2 +3 -3
  55. package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
  56. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
  57. package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
  58. package/autorest/codegen/templates/model.py.jinja2 +23 -24
  59. package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
  60. package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
  61. package/autorest/codegen/templates/operation.py.jinja2 +10 -14
  62. package/autorest/codegen/templates/operation_group.py.jinja2 +9 -15
  63. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
  64. package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
  65. package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
  66. package/autorest/codegen/templates/request_builder.py.jinja2 +19 -10
  67. package/autorest/codegen/templates/setup.py.jinja2 +9 -3
  68. package/autorest/codegen/templates/vendor.py.jinja2 +1 -1
  69. package/autorest/jsonrpc/__init__.py +7 -12
  70. package/autorest/jsonrpc/localapi.py +4 -3
  71. package/autorest/jsonrpc/server.py +28 -9
  72. package/autorest/jsonrpc/stdstream.py +13 -6
  73. package/autorest/m2r/__init__.py +5 -8
  74. package/autorest/m4reformatter/__init__.py +1126 -0
  75. package/autorest/multiapi/__init__.py +24 -14
  76. package/autorest/multiapi/models/client.py +21 -11
  77. package/autorest/multiapi/models/code_model.py +23 -10
  78. package/autorest/multiapi/models/config.py +4 -1
  79. package/autorest/multiapi/models/constant_global_parameter.py +1 -0
  80. package/autorest/multiapi/models/global_parameter.py +2 -1
  81. package/autorest/multiapi/models/global_parameters.py +14 -8
  82. package/autorest/multiapi/models/imports.py +24 -17
  83. package/autorest/multiapi/models/mixin_operation.py +5 -5
  84. package/autorest/multiapi/models/operation_group.py +2 -1
  85. package/autorest/multiapi/models/operation_mixin_group.py +21 -10
  86. package/autorest/multiapi/serializers/__init__.py +20 -25
  87. package/autorest/multiapi/serializers/import_serializer.py +47 -17
  88. package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
  89. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
  90. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
  91. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
  92. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
  93. package/autorest/multiapi/utils.py +3 -3
  94. package/autorest/postprocess/__init__.py +202 -0
  95. package/autorest/postprocess/get_all.py +19 -0
  96. package/autorest/postprocess/venvtools.py +73 -0
  97. package/autorest/preprocess/__init__.py +210 -0
  98. package/autorest/preprocess/helpers.py +54 -0
  99. package/autorest/{namer → preprocess}/python_mappings.py +25 -32
  100. package/package.json +3 -3
  101. package/run-python3.js +2 -3
  102. package/venvtools.py +1 -1
  103. package/autorest/codegen/models/constant_schema.py +0 -101
  104. package/autorest/codegen/models/credential_model.py +0 -47
  105. package/autorest/codegen/models/credential_schema.py +0 -91
  106. package/autorest/codegen/models/credential_schema_policy.py +0 -77
  107. package/autorest/codegen/models/dictionary_schema.py +0 -103
  108. package/autorest/codegen/models/enum_schema.py +0 -215
  109. package/autorest/codegen/models/list_schema.py +0 -123
  110. package/autorest/codegen/models/object_schema.py +0 -253
  111. package/autorest/codegen/models/primitive_schemas.py +0 -466
  112. package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
  113. package/autorest/codegen/models/rest.py +0 -42
  114. package/autorest/codegen/models/schema_request.py +0 -45
  115. package/autorest/codegen/models/schema_response.py +0 -136
  116. package/autorest/codegen/serializers/rest_serializer.py +0 -57
  117. package/autorest/namer/__init__.py +0 -25
  118. package/autorest/namer/name_converter.py +0 -412
@@ -4,23 +4,32 @@
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_serializer.pop_kwargs_from_signature(request_builder) %}
7
+ {% if not request_builder.is_overload %}
8
+ {% if request_builder.abstract %}
9
+ raise NotImplementedError(
10
+ "You need to write a custom operation for '{{ request_builder.name }}'. "
11
+ "Please refer to https://aka.ms/azsdk/python/dpcodegen/python/customize to learn how to customize."
12
+ )
13
+ {% else %}
14
+ {% if request_builder_serializer.pop_kwargs_from_signature(request_builder) %}
8
15
  {{ op_tools.serialize(request_builder_serializer.pop_kwargs_from_signature(request_builder)) | indent }}
9
- {%- endif -%}
10
- {% if request_builder_serializer.declare_non_inputtable_constants(request_builder) %}
16
+ {%- endif -%}
17
+ {% if request_builder_serializer.declare_non_inputtable_constants(request_builder) %}
11
18
  {{ op_tools.serialize(request_builder_serializer.declare_non_inputtable_constants(request_builder)) | indent }}
12
- {% endif %}
19
+ {% endif %}
13
20
  # Construct URL
14
21
  {{ request_builder_serializer.construct_url(request_builder) }}
15
- {% if request_builder.parameters.path %}
22
+ {% if request_builder.parameters.path %}
16
23
  {{ op_tools.serialize(request_builder_serializer.serialize_path(request_builder)) | indent }}
17
24
  _url = _format_url_section(_url, **path_format_arguments)
18
- {% endif %}
25
+ {% endif %}
19
26
 
20
- {% if request_builder.parameters.query %}
27
+ {% if request_builder.parameters.query %}
21
28
  {{ op_tools.serialize(request_builder_serializer.serialize_query(request_builder)) | indent }}
22
- {% endif %}
23
- {% if request_builder.parameters.headers %}
29
+ {% endif %}
30
+ {% if request_builder.parameters.headers %}
24
31
  {{ op_tools.serialize(request_builder_serializer.serialize_headers(request_builder)) | indent }}
25
- {% endif %}
32
+ {% endif %}
26
33
  {{ op_tools.serialize(request_builder_serializer.create_http_request(request_builder)) | indent }}
34
+ {% endif %}
35
+ {% endif %}
@@ -7,7 +7,7 @@ import re
7
7
  {% endif -%}
8
8
  from setuptools import setup, find_packages
9
9
 
10
- {% set package_name_render = package_name or code_model.class_name %}
10
+ {% set package_name_render = package_name or code_model.client.name %}
11
11
 
12
12
  PACKAGE_NAME = "{{ package_name_render|lower }}"
13
13
  {% if package_mode -%}
@@ -30,7 +30,7 @@ if not version:
30
30
  {% else %}
31
31
  version = "{{ code_model.options['package_version'] }}"
32
32
  {% set description = "%s"|format(package_name_render) %}
33
- {% set long_description = code_model.description %}
33
+ {% set long_description = code_model.client.description %}
34
34
  {% set author_email = "" %}
35
35
  {% set url = "" %}
36
36
  {% endif -%}
@@ -65,12 +65,18 @@ setup(
65
65
  packages=find_packages(
66
66
  exclude=[
67
67
  "tests",
68
+ {% if pkgutil_names %}
68
69
  # Exclude packages that will be covered by PEP420 or nspkg
70
+ {% endif %}
69
71
  {%- for pkgutil_name in pkgutil_names %}
70
72
  "{{ pkgutil_name }}",
71
73
  {%- endfor %}
72
74
  ]
73
75
  ),
76
+ include_package_data=True,
77
+ package_data={
78
+ 'pytyped': ['py.typed'],
79
+ },
74
80
  {% else %}
75
81
  packages=find_packages(),
76
82
  include_package_data=True,
@@ -87,7 +93,7 @@ setup(
87
93
  python_requires=">=3.6",
88
94
  {% else %}
89
95
  long_description="""\
90
- {{ code_model.description }}
96
+ {{ code_model.client.description }}
91
97
  """
92
98
  {% endif %}
93
99
  )
@@ -30,7 +30,7 @@ def _format_url_section(template, **kwargs):
30
30
  class MixinABC(ABC):
31
31
  """DO NOT use this class. It is for internal typing use only."""
32
32
  _client: "{{ keywords.async_class }}PipelineClient"
33
- _config: {{ code_model.class_name }}Configuration
33
+ _config: {{ code_model.client.name }}Configuration
34
34
  _serialize: "Serializer"
35
35
  _deserialize: "Deserializer"
36
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 = []
@@ -18,27 +18,42 @@ _LOGGER = logging.getLogger(__name__)
18
18
 
19
19
  @dispatcher.add_method
20
20
  def GetPluginNames():
21
- return ["codegen", "m2r", "namer", "black", "multiapiscript"]
21
+ return [
22
+ "codegen",
23
+ "m2r",
24
+ "preprocess",
25
+ "m4reformatter",
26
+ "black",
27
+ "multiapiscript",
28
+ "postprocess",
29
+ ]
22
30
 
23
31
 
24
32
  @dispatcher.add_method
25
33
  def Process(plugin_name: str, session_id: str) -> bool:
26
34
  # pylint: disable=import-outside-toplevel
27
- """JSON-RPC process call.
28
- """
35
+ """JSON-RPC process call."""
29
36
  from .stdstream import StdStreamAutorestAPI
30
37
 
31
38
  with contextlib.closing(StdStreamAutorestAPI(session_id)) as stdstream_connection:
32
39
 
33
- _LOGGER.debug("Autorest called process with plugin_name '%s' and session_id: '%s'", plugin_name, session_id)
40
+ _LOGGER.debug(
41
+ "Autorest called process with plugin_name '%s' and session_id: '%s'",
42
+ plugin_name,
43
+ session_id,
44
+ )
34
45
  if plugin_name == "m2r":
35
46
  from ..m2r import M2R as PluginToLoad
36
- elif plugin_name == "namer":
37
- from ..namer import Namer as PluginToLoad # type: ignore
47
+ elif plugin_name == "preprocess":
48
+ from ..preprocess import PreProcessPlugin as PluginToLoad # type: ignore
49
+ elif plugin_name == "m4reformatter":
50
+ from ..m4reformatter import M4Reformatter as PluginToLoad # type: ignore
38
51
  elif plugin_name == "codegen":
39
52
  from ..codegen import CodeGenerator as PluginToLoad # type: ignore
53
+ elif plugin_name == "postprocess":
54
+ from ..postprocess import PostProcessPlugin as PluginToLoad # type: ignore
40
55
  elif plugin_name == "black":
41
- from ..black import BlackScriptPlugin as PluginToLoad # type: ignore
56
+ from ..black import BlackScriptPlugin as PluginToLoad # type: ignore
42
57
  elif plugin_name == "multiapiscript":
43
58
  from ..multiapi import MultiApiScriptPlugin as PluginToLoad # type: ignore
44
59
  else:
@@ -58,11 +73,15 @@ def Process(plugin_name: str, session_id: str) -> bool:
58
73
  def main() -> None:
59
74
  # If --python.debugger is specified on the command line, we call the server.py file internally
60
75
  # with flag --debug.
61
- if '--debug' in sys.argv or os.environ.get("AUTOREST_PYTHON_ATTACH_VSCODE_DEBUG", False):
76
+ if "--debug" in sys.argv or os.environ.get(
77
+ "AUTOREST_PYTHON_ATTACH_VSCODE_DEBUG", False
78
+ ):
62
79
  try:
63
80
  import ptvsd # pylint: disable=import-outside-toplevel
64
81
  except ImportError:
65
- raise SystemExit("Please pip install ptvsd in order to use VSCode debugging")
82
+ raise SystemExit(
83
+ "Please pip install ptvsd in order to use VSCode debugging"
84
+ )
66
85
 
67
86
  # 5678 is the default attach port in the VS Code debug configurations
68
87
  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