@autorest/python 5.18.0 → 5.19.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 (30) hide show
  1. package/ChangeLog.md +17 -16
  2. package/autorest/codegen/__init__.py +7 -2
  3. package/autorest/codegen/models/client.py +8 -5
  4. package/autorest/codegen/models/code_model.py +15 -4
  5. package/autorest/codegen/models/imports.py +57 -2
  6. package/autorest/codegen/models/lro_operation.py +2 -0
  7. package/autorest/codegen/models/operation.py +44 -45
  8. package/autorest/codegen/models/operation_group.py +6 -2
  9. package/autorest/codegen/models/paging_operation.py +2 -0
  10. package/autorest/codegen/models/request_builder.py +31 -20
  11. package/autorest/codegen/serializers/__init__.py +9 -0
  12. package/autorest/codegen/serializers/builder_serializer.py +0 -4
  13. package/autorest/codegen/serializers/client_serializer.py +8 -0
  14. package/autorest/codegen/serializers/general_serializer.py +10 -5
  15. package/autorest/codegen/serializers/model_base_serializer.py +10 -5
  16. package/autorest/codegen/serializers/operation_groups_serializer.py +3 -0
  17. package/autorest/codegen/serializers/request_builders_serializer.py +1 -1
  18. package/autorest/codegen/templates/client.py.jinja2 +3 -0
  19. package/autorest/codegen/templates/operation_group.py.jinja2 +15 -2
  20. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +2 -2
  21. package/autorest/codegen/templates/operation_tools.jinja2 +3 -1
  22. package/autorest/codegen/templates/request_builder.py.jinja2 +0 -7
  23. package/autorest/codegen/templates/request_builders.py.jinja2 +1 -1
  24. package/autorest/codegen/templates/serialization.py.jinja2 +2006 -0
  25. package/autorest/codegen/templates/setup.py.jinja2 +4 -0
  26. package/autorest/codegen/templates/vendor.py.jinja2 +10 -0
  27. package/autorest/multiapi/models/client.py +12 -2
  28. package/autorest/multiapi/serializers/__init__.py +14 -0
  29. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
  30. package/package.json +1 -1
@@ -82,7 +82,11 @@ setup(
82
82
  include_package_data=True,
83
83
  {% endif %}
84
84
  install_requires=[
85
+ {% if code_model.is_legacy %}
85
86
  "{{ dependency_msrest }}",
87
+ {% else %}
88
+ "isodate>=0.6.1",
89
+ {% endif %}
86
90
  {% if azure_arm %}
87
91
  "{{ dependency_azure_mgmt_core }}",
88
92
  {% else %}
@@ -34,3 +34,13 @@ class MixinABC(ABC):
34
34
  _serialize: "Serializer"
35
35
  _deserialize: "Deserializer"
36
36
  {% endif %}
37
+ {% if code_model.has_abstract_operations %}
38
+
39
+ def raise_if_not_implemented(cls, abstract_methods):
40
+ not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))]
41
+ if not_implemented:
42
+ raise NotImplementedError("The following methods on operation group '{}' are not implemented: '{}'."
43
+ " Please refer to https://aka.ms/azsdk/python/dpcodegen/python/customize to learn how to customize.".format(
44
+ cls.__name__, '\', \''.join(not_implemented))
45
+ )
46
+ {% endif %}
@@ -5,9 +5,10 @@
5
5
  # --------------------------------------------------------------------------
6
6
  import sys
7
7
  import json
8
+ import re
8
9
  from typing import Any, Dict, List
9
10
  from pathlib import Path
10
- from .imports import FileImport
11
+ from .imports import FileImport, TypingSection, ImportType
11
12
 
12
13
 
13
14
  def _extract_version(metadata_json: Dict[str, Any], version_path: Path) -> str:
@@ -43,9 +44,18 @@ class Client:
43
44
 
44
45
  def imports(self, async_mode: bool) -> FileImport:
45
46
  imports_to_load = "async_imports" if async_mode else "sync_imports"
46
- return FileImport(
47
+ file_import = FileImport(
47
48
  json.loads(self.default_version_metadata["client"][imports_to_load])
48
49
  )
50
+ local_imports = file_import.imports.get(TypingSection.REGULAR, {}).get(
51
+ ImportType.LOCAL, {}
52
+ )
53
+ for key in local_imports:
54
+ if re.search("^\\.*_serialization$", key):
55
+ relative_path = ".." if async_mode else "."
56
+ local_imports[f"{relative_path}_serialization"] = local_imports.pop(key)
57
+ break
58
+ return file_import
49
59
 
50
60
  @property
51
61
  def parameterized_host_template_to_api_version(self) -> Dict[str, List[str]]:
@@ -115,3 +115,17 @@ class MultiAPISerializer(object):
115
115
  )
116
116
 
117
117
  self._autorestapi.write_file(Path("py.typed"), "# Marker file for PEP 561.")
118
+
119
+ if not code_model.client.client_side_validation:
120
+ codegen_env = Environment(
121
+ loader=PackageLoader("autorest.codegen", "templates"),
122
+ keep_trailing_newline=True,
123
+ line_statement_prefix="##",
124
+ line_comment_prefix="###",
125
+ trim_blocks=True,
126
+ lstrip_blocks=True,
127
+ )
128
+ self._autorestapi.write_file(
129
+ Path("_serialization.py"),
130
+ codegen_env.get_template("serialization.py.jinja2").render(),
131
+ )
@@ -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 msrest import Serializer, Deserializer
11
+ from {{ ".." if async_mode else "." }}_serialization import Serializer, Deserializer
12
12
  {% if imports %}
13
13
  {{ imports }}
14
14
  {% endif %}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "5.18.0",
3
+ "version": "5.19.0",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "scripts": {
6
6
  "prepare": "node run-python3.js prepare.py",