@autorest/python 6.3.1 → 6.4.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.
@@ -13,7 +13,7 @@ from black.report import NothingChanged
13
13
  from .. import Plugin, PluginAutorest
14
14
  from .._utils import parse_args
15
15
 
16
- logging.getLogger("blib2to3").setLevel(logging.ERROR)
16
+ _LOGGER = logging.getLogger("blib2to3")
17
17
 
18
18
  _BLACK_MODE = black.Mode() # pyright: ignore [reportPrivateImportUsage]
19
19
  _BLACK_MODE.line_length = 120
@@ -40,8 +40,16 @@ class BlackScriptPlugin(Plugin): # pylint: disable=abstract-method
40
40
  return True
41
41
 
42
42
  def format_file(self, file: Path) -> None:
43
- file_content = self.read_file(file)
44
- if not file.suffix == ".py":
43
+ try:
44
+ file_content = self.read_file(file)
45
+ except Exception as e: # pylint: disable=broad-except
46
+ if file.suffix != ".py":
47
+ _LOGGER.warning(
48
+ "Can not read file %s, not blacking this file", file.name
49
+ )
50
+ return
51
+ raise e # still want to raise if we fail reading a py file
52
+ if file.suffix != ".py":
45
53
  self.write_file(file, file_content)
46
54
  return
47
55
  try:
@@ -164,6 +164,7 @@ class CodeGenerator(Plugin):
164
164
  low_level_client or version_tolerant,
165
165
  ),
166
166
  "generate_sample": self.options.get("generate-sample", False),
167
+ "default_api_version": self.options.get("default-api-version"),
167
168
  }
168
169
 
169
170
  if options["builders_visibility"] is None:
@@ -276,6 +277,7 @@ class CodeGeneratorAutorest(CodeGenerator, PluginAutorest):
276
277
  "default-optional-constants-to-none"
277
278
  ),
278
279
  "generate-sample": self._autorestapi.get_boolean_value("generate-sample"),
280
+ "default-api-version": self._autorestapi.get_value("default-api-version"),
279
281
  }
280
282
  return {k: v for k, v in options.items() if v is not None}
281
283
 
@@ -125,7 +125,6 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
125
125
  self.code_model.options["show_operations"]
126
126
  and self.code_model.has_operations
127
127
  and self.code_model.options["generate_sample"]
128
- and not self.code_model.options["multiapi"]
129
128
  ):
130
129
  self._serialize_and_write_sample(env, namespace_path)
131
130
 
@@ -549,6 +548,12 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
549
548
  for client in self.code_model.clients:
550
549
  for op_group in client.operation_groups:
551
550
  for operation in op_group.operations:
551
+ if (
552
+ self.code_model.options["multiapi"]
553
+ and operation.api_versions[0]
554
+ != self.code_model.options["default_api_version"]
555
+ ):
556
+ continue
552
557
  samples = operation.yaml_data["samples"]
553
558
  if not samples or operation.name.startswith("_"):
554
559
  continue
@@ -473,7 +473,7 @@ class Model(_MyMutableMapping):
473
473
 
474
474
 
475
475
  def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-return-statements, too-many-statements
476
- annotation: typing.Any, module: typing.Optional[str], rf: "_RestField" = None
476
+ annotation: typing.Any, module: typing.Optional[str], rf: typing.Optional["_RestField"] = None
477
477
  ) -> typing.Optional[typing.Callable[[typing.Any], typing.Any]]:
478
478
  if not annotation or annotation in [int, float]:
479
479
  return None
@@ -624,8 +624,8 @@ def _deserialize_with_callable(deserializer: typing.Optional[typing.Callable[[ty
624
624
  # for unknown value, return raw value
625
625
  return value
626
626
  if isinstance(deserializer, type) and issubclass(deserializer, Model):
627
- return deserializer._deserialize(value) # type: ignore
628
- return deserializer(value)
627
+ return deserializer._deserialize(value)
628
+ return typing.cast(typing.Callable[[typing.Any], typing.Any], deserializer)(value)
629
629
  except Exception as e:
630
630
  raise DeserializationError() from e
631
631
 
@@ -178,9 +178,9 @@ def update_parameter(yaml_data: Dict[str, Any]) -> None:
178
178
  if yaml_data.get("propertyToParameterName"):
179
179
  # need to create a new one with padded keys and values
180
180
  yaml_data["propertyToParameterName"] = {
181
- pad_reserved_words(prop, PadType.PROPERTY): pad_reserved_words(
182
- param_name, PadType.PARAMETER
183
- )
181
+ pad_reserved_words(prop, PadType.PROPERTY)
182
+ .lower(): pad_reserved_words(param_name, PadType.PARAMETER)
183
+ .lower()
184
184
  for prop, param_name in yaml_data["propertyToParameterName"].items()
185
185
  }
186
186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.3.1",
3
+ "version": "6.4.0",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {
package/requirements.txt CHANGED
@@ -6,8 +6,7 @@ json-rpc==1.14.0
6
6
  m2r2==0.3.3
7
7
  MarkupSafe==2.1.2
8
8
  mistune==0.8.4
9
- mypy-extensions==0.4.3
10
- pathspec==0.10.3
9
+ pathspec==0.11.0
11
10
  platformdirs==2.6.2
12
11
  PyYAML==6.0
13
12
  tomli==2.0.1