@autorest/python 5.11.2 → 5.12.3

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 (50) hide show
  1. package/ChangeLog.md +69 -0
  2. package/autorest/codegen/__init__.py +5 -5
  3. package/autorest/codegen/models/__init__.py +3 -23
  4. package/autorest/codegen/models/base_builder.py +2 -5
  5. package/autorest/codegen/models/client.py +2 -2
  6. package/autorest/codegen/models/code_model.py +5 -1
  7. package/autorest/codegen/models/operation_group.py +5 -3
  8. package/autorest/codegen/models/parameter.py +7 -8
  9. package/autorest/codegen/models/parameter_list.py +32 -27
  10. package/autorest/codegen/models/request_builder.py +5 -1
  11. package/autorest/codegen/models/request_builder_parameter.py +4 -5
  12. package/autorest/codegen/models/request_builder_parameter_list.py +18 -11
  13. package/autorest/codegen/models/rest.py +3 -2
  14. package/autorest/codegen/models/utils.py +8 -0
  15. package/autorest/codegen/serializers/__init__.py +48 -48
  16. package/autorest/codegen/serializers/builder_serializer.py +150 -146
  17. package/autorest/codegen/serializers/client_serializer.py +37 -9
  18. package/autorest/codegen/serializers/general_serializer.py +7 -5
  19. package/autorest/codegen/serializers/import_serializer.py +6 -6
  20. package/autorest/codegen/serializers/metadata_serializer.py +2 -2
  21. package/autorest/codegen/serializers/model_base_serializer.py +3 -3
  22. package/autorest/codegen/serializers/model_generic_serializer.py +1 -1
  23. package/autorest/codegen/serializers/model_python3_serializer.py +1 -1
  24. package/autorest/codegen/serializers/{operation_group_serializer.py → operation_groups_serializer.py} +27 -29
  25. package/autorest/codegen/serializers/operations_init_serializer.py +34 -2
  26. package/autorest/codegen/serializers/patch_serializer.py +15 -0
  27. package/autorest/codegen/serializers/rest_serializer.py +9 -4
  28. package/autorest/codegen/serializers/utils.py +2 -2
  29. package/autorest/codegen/templates/config.py.jinja2 +1 -11
  30. package/autorest/codegen/templates/init.py.jinja2 +4 -5
  31. package/autorest/codegen/templates/metadata.json.jinja2 +5 -5
  32. package/autorest/codegen/templates/model_init.py.jinja2 +1 -1
  33. package/autorest/codegen/templates/{operations_class.py.jinja2 → operation_group.py.jinja2} +2 -0
  34. package/autorest/codegen/templates/{operations_container.py.jinja2 → operation_groups_container.py.jinja2} +7 -21
  35. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +13 -0
  36. package/autorest/codegen/templates/patch.py.jinja2 +31 -0
  37. package/autorest/codegen/templates/request_builder.py.jinja2 +7 -2
  38. package/autorest/codegen/templates/request_builders.py.jinja2 +1 -1
  39. package/autorest/codegen/templates/setup.py.jinja2 +1 -1
  40. package/autorest/multiapi/serializers/__init__.py +3 -3
  41. package/autorest/multiapi/serializers/import_serializer.py +5 -5
  42. package/autorest/namer/name_converter.py +3 -1
  43. package/install.py +1 -0
  44. package/package.json +4 -3
  45. package/requirements.txt +14 -0
  46. package/setup.py +1 -0
  47. package/autorest/codegen/templates/operations_class_mixin.py.jinja2 +0 -16
  48. package/autorest/codegen/templates/operations_container_init.py.jinja2 +0 -24
  49. package/autorest/codegen/templates/operations_container_mixin.py.jinja2 +0 -21
  50. package/autorest/codegen/templates/operations_init.py.jinja2 +0 -26
@@ -4,7 +4,7 @@
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.parameters.kwargs_to_pop(is_python_3_file) %}
7
+ {% if request_builder.parameters.kwargs_to_pop(is_python3_file) %}
8
8
  {{ op_tools.serialize(request_builder_serializer.pop_kwargs_from_signature(request_builder)) | indent }}
9
9
  {% endif %}
10
10
  {% if request_builder.parameters.constant|selectattr("original_parameter", "equalto", None)|selectattr("in_method_code")|selectattr("in_method_signature", "equalto", False) %}
@@ -13,7 +13,12 @@
13
13
  {% endfor %}
14
14
  {% endif %}
15
15
  # Construct URL
16
- url = kwargs.pop("template_url", {{ keywords.escape_str(request_builder.url) }})
16
+ {% if code_model.options["version_tolerant"] or code_model.options["low_level_client"] %}
17
+ {% set url_value = keywords.escape_str(request_builder.url) %}
18
+ {% else %}
19
+ {% set url_value = 'kwargs.pop("template_url", ' + keywords.escape_str(request_builder.url) + ')' %}
20
+ {% endif %}
21
+ url = {{ url_value }}
17
22
  {% if request_builder.parameters.path %}
18
23
  {{ op_tools.serialize(request_builder_serializer.serialize_path(request_builder)) | indent }}
19
24
  url = _format_url_section(url, **path_format_arguments)
@@ -4,7 +4,7 @@
4
4
  {{ imports }}
5
5
 
6
6
  {{ op_tools.declare_serializer(code_model) }}
7
- {% if not is_python_3_file %}
7
+ {% if not is_python3_file %}
8
8
  # fmt: off
9
9
  {% endif %}
10
10
  {% for request_builder in request_builders %}
@@ -16,7 +16,7 @@ VERSION = "{{ code_model.options.get('package_version', '0.0.0') }}"
16
16
  # prerequisite: setuptools
17
17
  # http://pypi.python.org/pypi/setuptools
18
18
 
19
- REQUIRES = ["msrest>=0.6.21", "azure-core<2.0.0,>=1.20.0"{{ azure_mgmt_core_import }}]
19
+ REQUIRES = ["msrest>=0.6.21", "azure-core<2.0.0,>=1.20.1"{{ azure_mgmt_core_import }}]
20
20
 
21
21
  setup(
22
22
  name=NAME,
@@ -55,7 +55,7 @@ class MultiAPISerializer(object):
55
55
  # serialize service client file
56
56
  imports = FileImportSerializer(
57
57
  code_model.service_client.imports(async_mode),
58
- is_python_3_file=async_mode
58
+ is_python3_file=async_mode
59
59
  )
60
60
  self._autorestapi.write_file(
61
61
  _get_file_path(code_model.service_client.filename, async_mode),
@@ -65,7 +65,7 @@ class MultiAPISerializer(object):
65
65
  # serialize config file
66
66
  imports = FileImportSerializer(
67
67
  code_model.config.imports(async_mode),
68
- is_python_3_file=async_mode
68
+ is_python3_file=async_mode
69
69
  )
70
70
  self._autorestapi.write_file(
71
71
  _get_file_path("_configuration", async_mode),
@@ -76,7 +76,7 @@ class MultiAPISerializer(object):
76
76
  if code_model.operation_mixin_group.mixin_operations:
77
77
  imports = FileImportSerializer(
78
78
  code_model.operation_mixin_group.imports(async_mode),
79
- is_python_3_file=async_mode
79
+ is_python3_file=async_mode
80
80
  )
81
81
  self._autorestapi.write_file(
82
82
  _get_file_path("_operations_mixin", async_mode),
@@ -36,9 +36,9 @@ def _get_import_clauses(imports: Dict[ImportType, Dict[str, Set[Optional[str]]]]
36
36
 
37
37
 
38
38
  class FileImportSerializer:
39
- def __init__(self, file_import: FileImport, is_python_3_file: bool) -> None:
39
+ def __init__(self, file_import: FileImport, is_python3_file: bool) -> None:
40
40
  self._file_import = file_import
41
- self.is_python_3_file = is_python_3_file
41
+ self.is_python3_file = is_python3_file
42
42
 
43
43
  def _switch_typing_section_key(self, new_key: TypingSection):
44
44
  switched_dictionary = {}
@@ -60,7 +60,7 @@ class FileImportSerializer:
60
60
  def _add_type_checking_import(self):
61
61
  if (
62
62
  self._file_import.imports.get(TypingSection.TYPING) or
63
- (not self.is_python_3_file and self._file_import.imports.get(TypingSection.CONDITIONAL))
63
+ (not self.is_python3_file and self._file_import.imports.get(TypingSection.CONDITIONAL))
64
64
  ):
65
65
  self._file_import.add_from_import("typing", "TYPE_CHECKING", ImportType.STDLIB)
66
66
 
@@ -68,7 +68,7 @@ class FileImportSerializer:
68
68
  self._add_type_checking_import()
69
69
  regular_imports = ""
70
70
  regular_imports_dict = self._get_imports_dict(
71
- baseline_typing_section=TypingSection.REGULAR, add_conditional_typing=self.is_python_3_file
71
+ baseline_typing_section=TypingSection.REGULAR, add_conditional_typing=self.is_python3_file
72
72
  )
73
73
 
74
74
  if regular_imports_dict:
@@ -78,7 +78,7 @@ class FileImportSerializer:
78
78
 
79
79
  typing_imports = ""
80
80
  typing_imports_dict = self._get_imports_dict(
81
- baseline_typing_section=TypingSection.TYPING, add_conditional_typing=not self.is_python_3_file
81
+ baseline_typing_section=TypingSection.TYPING, add_conditional_typing=not self.is_python3_file
82
82
  )
83
83
  if typing_imports_dict:
84
84
  typing_imports += "\n\nif TYPE_CHECKING:\n # pylint: disable=unused-import,ungrouped-imports\n "
@@ -7,6 +7,7 @@ import re
7
7
  import copy
8
8
  from typing import cast, Any, Dict, List, Match, Optional
9
9
  from .python_mappings import basic_latin_chars, reserved_words, PadType
10
+ from ..codegen.models.utils import JSON_REGEXP
10
11
 
11
12
  def _get_all_values(all_headers: List[Dict[str, Any]]) -> List[str]:
12
13
  content_types: List[str] = []
@@ -24,7 +25,7 @@ def _get_all_values(all_headers: List[Dict[str, Any]]) -> List[str]:
24
25
  return content_types
25
26
 
26
27
  def _get_default_value(all_values: List[str]) -> str:
27
- json_values = [v for v in all_values if "json" in v]
28
+ json_values = [v for v in all_values if JSON_REGEXP.match(v)]
28
29
  if json_values:
29
30
  if "application/json" in json_values:
30
31
  return "application/json"
@@ -71,6 +72,7 @@ class NameConverter:
71
72
  operation_group_name = operation_group['language']['default']['name']
72
73
  if not operation_group_name:
73
74
  operation_group['language']['python']['className'] = code_model_title + "OperationsMixin"
75
+ operation_group['language']['python']['name'] = ""
74
76
  elif operation_group_name == 'Operations':
75
77
  operation_group['language']['python']['className'] = operation_group_name
76
78
  else:
package/install.py CHANGED
@@ -43,6 +43,7 @@ def main():
43
43
  venv_context = env_builder.context
44
44
 
45
45
  python_run(venv_context, "pip", ["install", "-U", "pip"])
46
+ python_run(venv_context, "pip", ["install", "-r", "requirements.txt"])
46
47
  python_run(venv_context, "pip", ["install", "-e", str(_ROOT_DIR)])
47
48
 
48
49
  if __name__ == "__main__":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "5.11.2",
3
+ "version": "5.12.3",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "scripts": {
6
6
  "prepare": "node run-python3.js prepare.py",
@@ -27,7 +27,7 @@
27
27
  "@azure-tools/extension": "~3.2.1"
28
28
  },
29
29
  "devDependencies": {
30
- "@microsoft.azure/autorest.testserver": "^3.1.6"
30
+ "@microsoft.azure/autorest.testserver": "^3.1.11"
31
31
  },
32
32
  "files": [
33
33
  "autorest/**/*.py",
@@ -37,6 +37,7 @@
37
37
  "prepare.py",
38
38
  "start.py",
39
39
  "venvtools.py",
40
- "run-python3.js"
40
+ "run-python3.js",
41
+ "requirements.txt"
41
42
  ]
42
43
  }
@@ -0,0 +1,14 @@
1
+ black==21.12b0
2
+ click==8.0.3
3
+ docutils==0.18.1
4
+ Jinja2==3.0.3
5
+ json-rpc==1.13.0
6
+ m2r==0.2.1
7
+ MarkupSafe==2.0.1
8
+ mistune==0.8.4
9
+ mypy-extensions==0.4.3
10
+ pathspec==0.9.0
11
+ platformdirs==2.4.0
12
+ PyYAML==6.0
13
+ tomli==1.2.2
14
+ typing-extensions==4.0.1
package/setup.py CHANGED
@@ -48,6 +48,7 @@ setup(
48
48
  "json-rpc",
49
49
  "Jinja2 >= 2.11", # I need "include" and auto-context + blank line are not indented by default
50
50
  "pyyaml",
51
+ "mistune < 2.0.0", # Need to pin mistune's max version so m2r doesn't break
51
52
  "m2r",
52
53
  "black",
53
54
  ],
@@ -1,16 +0,0 @@
1
- class {{ operation_group.class_name }}{{ object_base_class }}:
2
- {% for operation in operation_group.operations %}
3
-
4
- {% set request_builder = operation.request_builder %}
5
- {% set operation_serializer = get_operation_serializer(operation) %}
6
- {% if is_lro(operation) and is_paging(operation) %}
7
- {%- macro someop() %}{% include "lro_paging_operation.py.jinja2" %}{% endmacro %}
8
- {% elif is_lro(operation) %}
9
- {%- macro someop() %}{% include "lro_operation.py.jinja2" %}{% endmacro %}
10
- {% elif is_paging(operation) %}
11
- {% macro someop() %}{% include "paging_operation.py.jinja2" %}{% endmacro %}
12
- {% else %}
13
- {% macro someop() %}{% include "operation.py.jinja2" %}{% endmacro %}
14
- {% endif %}
15
- {{ someop()|indent }}
16
- {% endfor %}
@@ -1,24 +0,0 @@
1
- {% macro operation_group_imports(filename_suffix="") %}
2
- {% for operation_group in operation_groups %}
3
- from .{{ ("_operations" if code_model.options['combine_operation_files'] else operation_group.filename) + filename_suffix }} import {{ operation_group.class_name }}
4
- {% endfor %}
5
- {% endmacro %}
6
- {# actual template starts here #}
7
- # coding=utf-8
8
- {{ code_model.options['license_header'] }}
9
-
10
- {% if not code_model.options["add_python_3_operation_files"] %}
11
- {{ operation_group_imports() }}
12
- {% elif code_model.options["add_python_3_operation_files"] and code_model.options["python_3_only"] %}
13
- {{ operation_group_imports("_py3") }}
14
- {% else %}
15
- try:
16
- {{ operation_group_imports("_py3") | indent }}
17
- except (SyntaxError, ImportError):
18
- {{ operation_group_imports() | indent }}
19
- {% endif %}
20
- __all__ = [
21
- {% for operation_group in operation_groups %}
22
- '{{ operation_group.class_name }}',
23
- {% endfor %}
24
- ]
@@ -1,21 +0,0 @@
1
- {% import 'operation_tools.jinja2' as op_tools %}
2
- {% set object_base_class = "" if async_mode else "(object)" %}
3
- {% set operation_group = operation_groups[0] %}
4
- # coding=utf-8
5
- {{ code_model.options['license_header'] }}
6
- {{ imports }}
7
-
8
- {% if code_model.options["builders_visibility"] == "embedded" and not async_mode %}
9
- {{ op_tools.declare_serializer(code_model) }}
10
- {%- if not is_python_3_file %}
11
- # fmt: off
12
- {% endif %}
13
- {% for request_builder in code_model.rest.request_builders | selectattr("builder_group_name", "equalto", "") %}
14
-
15
- {% include "request_builder.py.jinja2" %}
16
- {% endfor %}
17
- {% if not is_python_3_file %}
18
- # fmt: on
19
- {% endif %}
20
- {% endif %}
21
- {% include "operations_class_mixin.py.jinja2" %}
@@ -1,26 +0,0 @@
1
- {% macro operation_group_imports(filename_suffix="") %}
2
- {% for operation_group in operation_groups %}
3
- from .{{ operation_group.filename + filename_suffix }} import {{ operation_group.class_name }}
4
- {% endfor %}
5
- {% endmacro %}
6
- {# actual template starts here #}
7
- # coding=utf-8
8
- {{ code_model.options['license_header'] }}
9
-
10
- {% if not code_model.options["add_python_3_operation_files"] %}
11
- {{ operation_group_imports() }}
12
- {% elif code_model.options["add_python_3_operation_files"] and code_model.options["python_3_only"] %}
13
- {{ operation_group_imports("_py3") }}
14
- {% else %}
15
- try:
16
- {{ operation_group_imports("_py3") | indent }}
17
- except (SyntaxError, ImportError):
18
- {{ operation_group_imports() | indent }}
19
- {% endif %}
20
- {% if operation_groups %}
21
- __all__ = [
22
- {% for operation_group in operation_groups %}
23
- '{{ operation_group.class_name }}',
24
- {% endfor %}
25
- ]
26
- {% endif %}