@autorest/python 6.34.2 → 6.35.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.
@@ -43,7 +43,7 @@ class Client:
43
43
  file_import = FileImport(json.loads(self.default_version_metadata["client"][imports_to_load]))
44
44
  local_imports = file_import.imports.get(TypingSection.REGULAR, {}).get(ImportType.LOCAL, {})
45
45
  for key in local_imports:
46
- if re.search("^\\.*_serialization$", key):
46
+ if re.search("^\\.*_utils.serialization$", key):
47
47
  relative_path = ".." if async_mode else "."
48
48
  local_imports[f"{relative_path}_serialization"] = local_imports.pop(key)
49
49
  break
@@ -133,11 +133,7 @@ class MultiAPISerializer(ReaderAndWriter): # pylint: disable=abstract-method
133
133
  lstrip_blocks=True,
134
134
  )
135
135
  self.write_file(
136
- Path("_utils/__init__.py"),
137
- self.env.get_template("multiapi_utils_init.py.jinja2").render(),
138
- )
139
- self.write_file(
140
- Path("_utils/serialization.py"),
136
+ Path("_serialization.py"),
141
137
  codegen_env.get_template("serialization.py.jinja2").render(
142
138
  code_model=code_model,
143
139
  ),
@@ -8,7 +8,7 @@
8
8
  # Changes may cause incorrect behavior and will be lost if the code is
9
9
  # regenerated.
10
10
  # --------------------------------------------------------------------------
11
- from {{ ".." if async_mode else "." }}_utils.serialization import Serializer, Deserializer
11
+ from {{ ".." if async_mode else "." }}_serialization import Serializer, Deserializer
12
12
  {% if imports %}
13
13
  {{ imports }}
14
14
  {% endif %}
@@ -98,6 +98,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
98
98
  self.has_subnamespace = False
99
99
  self._operations_folder_name: Dict[str, str] = {}
100
100
  self._relative_import_path: Dict[str, str] = {}
101
+ self.metadata: Dict[str, Any] = yaml_data.get("metadata", {})
101
102
 
102
103
  @staticmethod
103
104
  def get_imported_namespace_for_client(imported_namespace: str, async_mode: bool = False) -> str:
@@ -122,9 +122,17 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
122
122
  def _imports_shared(self, async_mode: bool, **kwargs: Any) -> FileImport:
123
123
  file_import = super()._imports_shared(async_mode, **kwargs)
124
124
  if async_mode:
125
- file_import.add_submodule_import("typing", "AsyncIterable", ImportType.STDLIB, TypingSection.CONDITIONAL)
125
+ default_paging_submodule = f"{'async_' if self.code_model.is_azure_flavor else ''}paging"
126
+ file_import.add_submodule_import(
127
+ f"{self.code_model.core_library}.{default_paging_submodule}",
128
+ "AsyncItemPaged",
129
+ ImportType.SDKCORE,
130
+ TypingSection.CONDITIONAL,
131
+ )
126
132
  else:
127
- file_import.add_submodule_import("typing", "Iterable", ImportType.STDLIB, TypingSection.CONDITIONAL)
133
+ file_import.add_submodule_import(
134
+ f"{self.code_model.core_library}.paging", "ItemPaged", ImportType.SDKCORE, TypingSection.CONDITIONAL
135
+ )
128
136
  if (
129
137
  self.next_request_builder
130
138
  and self.code_model.options["builders_visibility"] == "embedded"
@@ -186,7 +186,7 @@ class PagingResponse(Response):
186
186
  return self.get_pager_path(async_mode).split(".")[-1]
187
187
 
188
188
  def type_annotation(self, **kwargs: Any) -> str:
189
- iterable = "AsyncIterable" if kwargs["async_mode"] else "Iterable"
189
+ iterable = "AsyncItemPaged" if kwargs["async_mode"] else "ItemPaged"
190
190
  return f"{iterable}[{self.item_type.type_annotation(**kwargs)}]"
191
191
 
192
192
  def docstring_text(self, **kwargs: Any) -> str:
@@ -4,6 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  import logging
7
+ import json
7
8
  from collections import namedtuple
8
9
  import re
9
10
  from typing import List, Any, Union
@@ -143,6 +144,13 @@ class JinjaSerializer(ReaderAndWriter):
143
144
  self._serialize_and_write_sample(env, namespace=client_namespace)
144
145
  if self.code_model.options["generate_test"]:
145
146
  self._serialize_and_write_test(env, namespace=client_namespace)
147
+
148
+ # add _metadata.json
149
+ if self.code_model.metadata:
150
+ self.write_file(
151
+ exec_path / Path("_metadata.json"),
152
+ json.dumps(self.code_model.metadata, indent=2),
153
+ )
146
154
  elif client_namespace_type.clients:
147
155
  # add clients folder if there are clients in this namespace
148
156
  self._serialize_client_and_config_files(client_namespace, client_namespace_type.clients, env)
@@ -63,7 +63,7 @@ class GeneralSerializer(BaseSerializer):
63
63
  "token_credential": token_credential,
64
64
  "pkgutil_names": [".".join(package_parts[: i + 1]) for i in range(len(package_parts))],
65
65
  "init_names": ["/".join(package_parts[: i + 1]) + "/__init__.py" for i in range(len(package_parts))],
66
- "client_name": self.code_model.clients[0].name,
66
+ "client_name": self.code_model.clients[0].name if self.code_model.clients else "",
67
67
  "VERSION_MAP": VERSION_MAP,
68
68
  "MIN_PYTHON_VERSION": MIN_PYTHON_VERSION,
69
69
  "MAX_PYTHON_VERSION": MAX_PYTHON_VERSION,
@@ -40,7 +40,7 @@ python -m pip install {{ package_name }}
40
40
  - You need an [Azure subscription][azure_sub] to use this package.
41
41
  - An existing {{ package_pprint_name }} instance.
42
42
 
43
- {% if token_credential %}
43
+ {% if token_credential and client_name %}
44
44
  #### Create with an Azure Active Directory Credential
45
45
  To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
46
46
  provide an instance of the desired credential type obtained from the
@@ -4,11 +4,11 @@
4
4
  "install": [
5
5
  {
6
6
  "download_info": {
7
- "url": "https://files.pythonhosted.org/packages/53/7e/5d8af3317ddbf9519b687bd1c39d8737fde07d97f54df65553faca5cffb1/setuptools-80.3.1-py3-none-any.whl",
7
+ "url": "https://files.pythonhosted.org/packages/a1/18/0e835c3a557dc5faffc8f91092f62fc337c1dab1066715842e7a4b318ec4/setuptools-80.7.1-py3-none-any.whl",
8
8
  "archive_info": {
9
- "hash": "sha256=ea8e00d7992054c4c592aeb892f6ad51fe1b4d90cc6947cc45c45717c40ec537",
9
+ "hash": "sha256=ca5cc1069b85dc23070a6628e6bcecb3292acac802399c7f8edc0100619f9009",
10
10
  "hashes": {
11
- "sha256": "ea8e00d7992054c4c592aeb892f6ad51fe1b4d90cc6947cc45c45717c40ec537"
11
+ "sha256": "ca5cc1069b85dc23070a6628e6bcecb3292acac802399c7f8edc0100619f9009"
12
12
  }
13
13
  }
14
14
  },
@@ -18,7 +18,10 @@
18
18
  "metadata": {
19
19
  "metadata_version": "2.4",
20
20
  "name": "setuptools",
21
- "version": "80.3.1",
21
+ "version": "80.7.1",
22
+ "dynamic": [
23
+ "license-file"
24
+ ],
22
25
  "summary": "Easily download, build, install, upgrade, and uninstall Python packages",
23
26
  "description_content_type": "text/x-rst",
24
27
  "keywords": [
@@ -31,6 +34,9 @@
31
34
  ],
32
35
  "author_email": "Python Packaging Authority <distutils-sig@python.org>",
33
36
  "license_expression": "MIT",
37
+ "license_file": [
38
+ "LICENSE"
39
+ ],
34
40
  "classifier": [
35
41
  "Development Status :: 5 - Production/Stable",
36
42
  "Intended Audience :: Developers",
@@ -98,6 +98,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
98
98
  self.has_subnamespace = False
99
99
  self._operations_folder_name: Dict[str, str] = {}
100
100
  self._relative_import_path: Dict[str, str] = {}
101
+ self.metadata: Dict[str, Any] = yaml_data.get("metadata", {})
101
102
 
102
103
  @staticmethod
103
104
  def get_imported_namespace_for_client(imported_namespace: str, async_mode: bool = False) -> str:
@@ -122,9 +122,17 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
122
122
  def _imports_shared(self, async_mode: bool, **kwargs: Any) -> FileImport:
123
123
  file_import = super()._imports_shared(async_mode, **kwargs)
124
124
  if async_mode:
125
- file_import.add_submodule_import("typing", "AsyncIterable", ImportType.STDLIB, TypingSection.CONDITIONAL)
125
+ default_paging_submodule = f"{'async_' if self.code_model.is_azure_flavor else ''}paging"
126
+ file_import.add_submodule_import(
127
+ f"{self.code_model.core_library}.{default_paging_submodule}",
128
+ "AsyncItemPaged",
129
+ ImportType.SDKCORE,
130
+ TypingSection.CONDITIONAL,
131
+ )
126
132
  else:
127
- file_import.add_submodule_import("typing", "Iterable", ImportType.STDLIB, TypingSection.CONDITIONAL)
133
+ file_import.add_submodule_import(
134
+ f"{self.code_model.core_library}.paging", "ItemPaged", ImportType.SDKCORE, TypingSection.CONDITIONAL
135
+ )
128
136
  if (
129
137
  self.next_request_builder
130
138
  and self.code_model.options["builders_visibility"] == "embedded"
@@ -186,7 +186,7 @@ class PagingResponse(Response):
186
186
  return self.get_pager_path(async_mode).split(".")[-1]
187
187
 
188
188
  def type_annotation(self, **kwargs: Any) -> str:
189
- iterable = "AsyncIterable" if kwargs["async_mode"] else "Iterable"
189
+ iterable = "AsyncItemPaged" if kwargs["async_mode"] else "ItemPaged"
190
190
  return f"{iterable}[{self.item_type.type_annotation(**kwargs)}]"
191
191
 
192
192
  def docstring_text(self, **kwargs: Any) -> str:
@@ -4,6 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  import logging
7
+ import json
7
8
  from collections import namedtuple
8
9
  import re
9
10
  from typing import List, Any, Union
@@ -143,6 +144,13 @@ class JinjaSerializer(ReaderAndWriter):
143
144
  self._serialize_and_write_sample(env, namespace=client_namespace)
144
145
  if self.code_model.options["generate_test"]:
145
146
  self._serialize_and_write_test(env, namespace=client_namespace)
147
+
148
+ # add _metadata.json
149
+ if self.code_model.metadata:
150
+ self.write_file(
151
+ exec_path / Path("_metadata.json"),
152
+ json.dumps(self.code_model.metadata, indent=2),
153
+ )
146
154
  elif client_namespace_type.clients:
147
155
  # add clients folder if there are clients in this namespace
148
156
  self._serialize_client_and_config_files(client_namespace, client_namespace_type.clients, env)
@@ -63,7 +63,7 @@ class GeneralSerializer(BaseSerializer):
63
63
  "token_credential": token_credential,
64
64
  "pkgutil_names": [".".join(package_parts[: i + 1]) for i in range(len(package_parts))],
65
65
  "init_names": ["/".join(package_parts[: i + 1]) + "/__init__.py" for i in range(len(package_parts))],
66
- "client_name": self.code_model.clients[0].name,
66
+ "client_name": self.code_model.clients[0].name if self.code_model.clients else "",
67
67
  "VERSION_MAP": VERSION_MAP,
68
68
  "MIN_PYTHON_VERSION": MIN_PYTHON_VERSION,
69
69
  "MAX_PYTHON_VERSION": MAX_PYTHON_VERSION,
@@ -40,7 +40,7 @@ python -m pip install {{ package_name }}
40
40
  - You need an [Azure subscription][azure_sub] to use this package.
41
41
  - An existing {{ package_pprint_name }} instance.
42
42
 
43
- {% if token_credential %}
43
+ {% if token_credential and client_name %}
44
44
  #### Create with an Azure Active Directory Credential
45
45
  To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
46
46
  provide an instance of the desired credential type obtained from the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.34.2",
3
+ "version": "6.35.0",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
21
21
  "dependencies": {
22
- "@typespec/http-client-python": "~0.11.3",
22
+ "@typespec/http-client-python": "~0.12.0",
23
23
  "@autorest/system-requirements": "~1.0.2",
24
24
  "fs-extra": "~11.2.0",
25
25
  "tsx": "~4.19.1"
@@ -1,10 +0,0 @@
1
- # coding=utf-8
2
- # --------------------------------------------------------------------------
3
- # Copyright (c) Microsoft Corporation. All rights reserved.
4
- # Licensed under the MIT License. See License.txt in the project root for
5
- # license information.
6
- #
7
- # Code generated by Microsoft (R) AutoRest Code Generator.
8
- # Changes may cause incorrect behavior and will be lost if the code is
9
- # regenerated.
10
- # --------------------------------------------------------------------------