@autorest/python 6.13.6 → 6.13.8

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.
@@ -38,6 +38,7 @@ class OptionsRetriever:
38
38
  "polymorphic-examples": 5,
39
39
  "generate-sample": False,
40
40
  "from-typespec": False,
41
+ "emit-cross-language-definition-file": False,
41
42
  }
42
43
 
43
44
  @property
@@ -333,6 +334,7 @@ class CodeGenerator(Plugin):
333
334
  "from_typespec",
334
335
  "flavor",
335
336
  "company_name",
337
+ "emit_cross_language_definition_file",
336
338
  ]
337
339
  return {f: getattr(self.options_retriever, f) for f in flags}
338
340
 
@@ -75,6 +75,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
75
75
  self.named_unions: List[CombinedType] = [
76
76
  t for t in self.types_map.values() if isinstance(t, CombinedType) and t.name
77
77
  ]
78
+ self.cross_language_package_id = self.yaml_data.get("crossLanguagePackageId")
78
79
 
79
80
  @property
80
81
  def has_form_data(self) -> bool:
@@ -134,6 +134,9 @@ class EnumType(BaseType):
134
134
  self.values = values
135
135
  self.value_type = value_type
136
136
  self.internal: bool = self.yaml_data.get("internal", False)
137
+ self.cross_language_definition_id: Optional[str] = self.yaml_data.get(
138
+ "crossLanguageDefinitionId"
139
+ )
137
140
 
138
141
  def __lt__(self, other):
139
142
  return self.name.lower() < other.name.lower()
@@ -75,6 +75,9 @@ class ModelType( # pylint: disable=abstract-method
75
75
  self.internal: bool = self.yaml_data.get("internal", False)
76
76
  self.snake_case_name: str = self.yaml_data["snakeCaseName"]
77
77
  self.page_result_model: bool = self.yaml_data.get("pageResultModel", False)
78
+ self.cross_language_definition_id: Optional[str] = self.yaml_data.get(
79
+ "crossLanguageDefinitionId"
80
+ )
78
81
 
79
82
  @property
80
83
  def flattened_property(self) -> Optional[Property]:
@@ -54,7 +54,7 @@ def is_internal(target: Optional[BaseType]) -> bool:
54
54
  return isinstance(target, ModelType) and target.base == "dpg" and target.internal
55
55
 
56
56
 
57
- class OperationBase( # pylint: disable=too-many-public-methods
57
+ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instance-attributes
58
58
  Generic[ResponseType], BaseBuilder[ParameterList, List["Operation"]]
59
59
  ):
60
60
  def __init__(
@@ -91,6 +91,9 @@ class OperationBase( # pylint: disable=too-many-public-methods
91
91
  if self.internal:
92
92
  self.name = "_" + self.name
93
93
  self.has_etag: bool = self.yaml_data.get("hasEtag", False)
94
+ self.cross_language_definition_id: Optional[str] = self.yaml_data.get(
95
+ "crossLanguageDefinitionId"
96
+ )
94
97
 
95
98
  @property
96
99
  def has_form_data_body(self):
@@ -522,6 +522,11 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
522
522
  namespace_path / Path("_validation.py"),
523
523
  general_serializer.serialize_validation_file(),
524
524
  )
525
+ if self.code_model.options.get("emit_cross_language_definition_file"):
526
+ self.write_file(
527
+ namespace_path / Path("apiview_mapping_python.json"),
528
+ general_serializer.serialize_cross_language_definition_file(),
529
+ )
525
530
 
526
531
  # Write the setup file
527
532
  if self.code_model.options["basic_setup_py"]:
@@ -1431,9 +1431,12 @@ class _PagingOperationSerializer(
1431
1431
  "})",
1432
1432
  ]
1433
1433
  )
1434
- retval.append(
1435
- f'_next_request_params["api-version"] = {api_version_param.full_client_name}'
1434
+ api_version = (
1435
+ "self._api_version"
1436
+ if self.code_model.options["multiapi"] and builder.group_name
1437
+ else api_version_param.full_client_name
1436
1438
  )
1439
+ retval.append(f'_next_request_params["api-version"] = {api_version}')
1437
1440
  query_str = ", params=_next_request_params"
1438
1441
  next_link_str = "urllib.parse.urljoin(next_link, _parsed_next_link.path)"
1439
1442
  except StopIteration:
@@ -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 json
6
7
  from typing import Any, List
7
8
  from jinja2 import Environment
8
9
  from .import_serializer import FileImportSerializer, TypingSection
@@ -196,3 +197,39 @@ class GeneralSerializer(BaseSerializer):
196
197
  def serialize_validation_file(self) -> str:
197
198
  template = self.env.get_template("validation.py.jinja2")
198
199
  return template.render(code_model=self.code_model)
200
+
201
+ def serialize_cross_language_definition_file(self) -> str:
202
+ cross_langauge_def_dict = {
203
+ f"{self.code_model.namespace}.models.{model.name}": model.cross_language_definition_id
204
+ for model in self.code_model.model_types
205
+ }
206
+ cross_langauge_def_dict.update(
207
+ {
208
+ f"{self.code_model.namespace}.models.{enum.name}": enum.cross_language_definition_id
209
+ for enum in self.code_model.enums
210
+ }
211
+ )
212
+ cross_langauge_def_dict.update(
213
+ {
214
+ (
215
+ f"{self.code_model.namespace}.{client.name}."
216
+ + (
217
+ ""
218
+ if operation_group.is_mixin
219
+ else f"{operation_group.property_name}."
220
+ )
221
+ + f"{operation.name}"
222
+ ): operation.cross_language_definition_id
223
+ for client in self.code_model.clients
224
+ for operation_group in client.operation_groups
225
+ for operation in operation_group.operations
226
+ if not operation.name.startswith("_")
227
+ }
228
+ )
229
+ return json.dumps(
230
+ {
231
+ "CrossLanguagePackageId": self.code_model.cross_language_package_id,
232
+ "CrossLanguageDefinitionId": cross_langauge_def_dict,
233
+ },
234
+ indent=4,
235
+ )
@@ -28,7 +28,7 @@ section of the project.
28
28
 
29
29
  ## Getting started
30
30
 
31
- ### Installating the package
31
+ ### Install the package
32
32
 
33
33
  ```bash
34
34
  python -m pip install {{ package_name }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.13.6",
3
+ "version": "6.13.8",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {
package/prepare.py CHANGED
@@ -6,7 +6,7 @@
6
6
  # license information.
7
7
  # --------------------------------------------------------------------------
8
8
  import sys
9
- if not sys.version_info >= (3, 7, 0):
9
+ if not sys.version_info >= (3, 8, 0):
10
10
  raise Exception("Autorest for Python extension requires Python 3.8 at least")
11
11
 
12
12
  from pathlib import Path
package/start.py CHANGED
@@ -6,7 +6,7 @@
6
6
  # license information.
7
7
  # --------------------------------------------------------------------------
8
8
  import sys
9
- if not sys.version_info >= (3, 7, 0):
9
+ if not sys.version_info >= (3, 8, 0):
10
10
  raise Exception("Autorest for Python extension requires Python 3.8 at least")
11
11
 
12
12
  from pathlib import Path
@@ -23,7 +23,10 @@ def main():
23
23
 
24
24
  assert venv_prexists # Otherwise install was not done
25
25
 
26
- env_builder = venv.EnvBuilder(with_pip=True, upgrade_deps=True)
26
+ if sys.version_info < (3, 9, 0):
27
+ env_builder = venv.EnvBuilder(with_pip=True)
28
+ else:
29
+ env_builder = venv.EnvBuilder(with_pip=True, upgrade_deps=True)
27
30
  venv_context = env_builder.ensure_directories(venv_path)
28
31
  python_run(venv_context, "autorest.jsonrpc.server", command=sys.argv[1:])
29
32