@autorest/python 5.12.6 → 5.15.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 (69) hide show
  1. package/ChangeLog.md +205 -125
  2. package/autorest/black/__init__.py +3 -0
  3. package/autorest/codegen/__init__.py +120 -48
  4. package/autorest/codegen/models/__init__.py +2 -1
  5. package/autorest/codegen/models/base_schema.py +2 -6
  6. package/autorest/codegen/models/client.py +6 -0
  7. package/autorest/codegen/models/code_model.py +43 -74
  8. package/autorest/codegen/models/constant_schema.py +7 -7
  9. package/autorest/codegen/models/credential_model.py +47 -0
  10. package/autorest/codegen/models/credential_schema.py +5 -4
  11. package/autorest/codegen/models/dictionary_schema.py +7 -7
  12. package/autorest/codegen/models/enum_schema.py +8 -39
  13. package/autorest/codegen/models/imports.py +3 -1
  14. package/autorest/codegen/models/list_schema.py +18 -8
  15. package/autorest/codegen/models/lro_operation.py +3 -3
  16. package/autorest/codegen/models/lro_paging_operation.py +3 -3
  17. package/autorest/codegen/models/object_schema.py +17 -13
  18. package/autorest/codegen/models/operation.py +38 -10
  19. package/autorest/codegen/models/operation_group.py +7 -2
  20. package/autorest/codegen/models/paging_operation.py +3 -3
  21. package/autorest/codegen/models/parameter.py +71 -22
  22. package/autorest/codegen/models/parameter_list.py +11 -5
  23. package/autorest/codegen/models/primitive_schemas.py +15 -25
  24. package/autorest/codegen/models/property.py +5 -5
  25. package/autorest/codegen/models/request_builder.py +4 -4
  26. package/autorest/codegen/models/request_builder_parameter.py +17 -5
  27. package/autorest/codegen/models/schema_response.py +23 -10
  28. package/autorest/codegen/models/utils.py +20 -0
  29. package/autorest/codegen/serializers/__init__.py +184 -87
  30. package/autorest/codegen/serializers/builder_serializer.py +113 -47
  31. package/autorest/codegen/serializers/client_serializer.py +16 -6
  32. package/autorest/codegen/serializers/general_serializer.py +28 -4
  33. package/autorest/codegen/serializers/import_serializer.py +1 -1
  34. package/autorest/codegen/serializers/metadata_serializer.py +1 -1
  35. package/autorest/codegen/serializers/model_base_serializer.py +8 -0
  36. package/autorest/codegen/serializers/model_python3_serializer.py +2 -2
  37. package/autorest/codegen/serializers/operation_groups_serializer.py +1 -0
  38. package/autorest/codegen/serializers/patch_serializer.py +12 -3
  39. package/autorest/codegen/serializers/utils.py +29 -4
  40. package/autorest/codegen/templates/CHANGELOG.md.jinja2 +6 -0
  41. package/autorest/codegen/templates/LICENSE.jinja2 +21 -0
  42. package/autorest/codegen/templates/MANIFEST.in.jinja2 +7 -0
  43. package/autorest/codegen/templates/README.md.jinja2 +105 -0
  44. package/autorest/codegen/templates/config.py.jinja2 +4 -4
  45. package/autorest/codegen/templates/dev_requirements.txt.jinja2 +10 -0
  46. package/autorest/codegen/templates/enum.py.jinja2 +1 -1
  47. package/autorest/codegen/templates/enum_container.py.jinja2 +0 -1
  48. package/autorest/codegen/templates/init.py.jinja2 +9 -6
  49. package/autorest/codegen/templates/keywords.jinja2 +14 -1
  50. package/autorest/codegen/templates/lro_operation.py.jinja2 +1 -1
  51. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +1 -1
  52. package/autorest/codegen/templates/metadata.json.jinja2 +3 -3
  53. package/autorest/codegen/templates/model.py.jinja2 +1 -6
  54. package/autorest/codegen/templates/model_init.py.jinja2 +7 -4
  55. package/autorest/codegen/templates/operation.py.jinja2 +2 -3
  56. package/autorest/codegen/templates/operation_group.py.jinja2 +20 -17
  57. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +0 -1
  58. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
  59. package/autorest/codegen/templates/paging_operation.py.jinja2 +1 -1
  60. package/autorest/codegen/templates/patch.py.jinja2 +18 -29
  61. package/autorest/codegen/templates/request_builder.py.jinja2 +4 -6
  62. package/autorest/codegen/templates/setup.py.jinja2 +79 -20
  63. package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
  64. package/autorest/multiapi/models/imports.py +21 -11
  65. package/autorest/multiapi/serializers/import_serializer.py +3 -1
  66. package/autorest/namer/name_converter.py +1 -1
  67. package/package.json +2 -2
  68. package/run-python3.js +1 -7
  69. package/venvtools.py +2 -2
@@ -0,0 +1,105 @@
1
+ {% if package_mode == "mgmtplane" -%}
2
+ # Microsoft Azure SDK for Python
3
+
4
+ This is the Microsoft {{package_pprint_name}} Client Library.
5
+ This package has been tested with Python 3.6+.
6
+ For a more complete view of Azure libraries, see the [azure sdk python release](https://aka.ms/azsdk/python/all).
7
+
8
+ # Usage
9
+
10
+ To learn how to use this package, see the [quickstart guide](https://aka.ms/azsdk/python/mgmt)
11
+
12
+ For docs and references, see [Python SDK References](https://docs.microsoft.com/python/api/overview/azure)
13
+ Code samples for this package can be found at [{{package_pprint_name}}](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20-%20Managing&terms=Getting%20started%20-%20Managing) on docs.microsoft.com.
14
+ Additional code samples for different Azure services are available at [Samples Repo](https://aka.ms/azsdk/python/mgmt/samples)
15
+
16
+ # Provide Feedback
17
+
18
+ If you encounter any bugs or have suggestions, please file an issue in the
19
+ [Issues](https://github.com/Azure/azure-sdk-for-python/issues)
20
+ section of the project.
21
+
22
+
23
+ ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2F{{package_name}}%2FREADME.png)
24
+ {% else %}
25
+ # {{ package_pprint_name }} client library for Python
26
+ <!-- write necessary description of service -->
27
+
28
+ ## Getting started
29
+
30
+ ### Installating the package
31
+
32
+ ```bash
33
+ python -m pip install {{ package_name }}
34
+ ```
35
+
36
+ #### Prequisites
37
+
38
+ - Python 3.6 or later is required to use this package.
39
+ - You need an [Azure subscription][azure_sub] to use this package.
40
+ - An existing {{ package_pprint_name }} instance.
41
+
42
+ {%- if token_credential %}
43
+ #### Create with an Azure Active Directory Credential
44
+ To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
45
+ provide an instance of the desired credential type obtained from the
46
+ [azure-identity][azure_identity_credentials] library.
47
+
48
+ To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip]
49
+
50
+ After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
51
+ As an example, [DefaultAzureCredential][default_azure_credential] can be used to authenticate the client:
52
+
53
+ Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
54
+ `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`
55
+
56
+ Use the returned token credential to authenticate the client:
57
+
58
+ ```python
59
+ >>> from {{ namespace }} import {{ client_name }}
60
+ >>> from azure.identity import DefaultAzureCredential
61
+ >>> client = {{ client_name }}(endpoint='<endpoint>', credential=DefaultAzureCredential())
62
+ ```
63
+
64
+ ## Examples
65
+
66
+ ```python
67
+ >>> from {{ namespace }} import {{ client_name }}
68
+ >>> from azure.identity import DefaultAzureCredential
69
+ >>> from azure.core.exceptions import HttpResponseError
70
+
71
+ >>> client = {{ client_name }}(endpoint='<endpoint>', credential=DefaultAzureCredential())
72
+ >>> try:
73
+ <!-- write test code here -->
74
+ except HttpResponseError as e:
75
+ print('service responds error: {}'.format(e.response.json()))
76
+
77
+ ```
78
+ {%- endif %}
79
+
80
+ ## Contributing
81
+
82
+ This project welcomes contributions and suggestions. Most contributions require
83
+ you to agree to a Contributor License Agreement (CLA) declaring that you have
84
+ the right to, and actually do, grant us the rights to use your contribution.
85
+ For details, visit https://cla.microsoft.com.
86
+
87
+ When you submit a pull request, a CLA-bot will automatically determine whether
88
+ you need to provide a CLA and decorate the PR appropriately (e.g., label,
89
+ comment). Simply follow the instructions provided by the bot. You will only
90
+ need to do this once across all repos using our CLA.
91
+
92
+ This project has adopted the
93
+ [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
94
+ see the Code of Conduct FAQ or contact opencode@microsoft.com with any
95
+ additional questions or comments.
96
+
97
+ <!-- LINKS -->
98
+ [code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
99
+ [authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
100
+ [azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
101
+ [azure_identity_pip]: https://pypi.org/project/azure-identity/
102
+ [default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
103
+ [pip]: https://pypi.org/project/pip/
104
+ [azure_sub]: https://azure.microsoft.com/free/
105
+ {% endif %}
@@ -35,8 +35,8 @@ class {{ code_model.class_name }}Configuration(Configuration): # pylint: disabl
35
35
  {% if serializer.set_constants() %}
36
36
  {{ op_tools.serialize(serializer.set_constants()) | indent(8) -}}
37
37
  {% endif %}
38
- {% if code_model.options['credential'] and code_model.credential_schema_policy.credential_scopes is defined %}
39
- self.credential_scopes = kwargs.pop('credential_scopes', {{ code_model.credential_schema_policy.credential_scopes }})
38
+ {% if code_model.options['credential'] and code_model.credential_model.credential_schema_policy.credential_scopes is defined %}
39
+ self.credential_scopes = kwargs.pop('credential_scopes', {{ code_model.credential_model.credential_schema_policy.credential_scopes }})
40
40
  {% endif %}
41
41
  kwargs.setdefault('sdk_moniker', '{{ sdk_moniker }}/{}'.format(VERSION))
42
42
  self._configure(**kwargs)
@@ -59,10 +59,10 @@ class {{ code_model.class_name }}Configuration(Configuration): # pylint: disabl
59
59
  self.authentication_policy = kwargs.get('authentication_policy')
60
60
  {% if code_model.options['credential'] %}
61
61
  {# only adding this if credential_scopes is not passed during code generation #}
62
- {% if code_model.credential_schema_policy.credential_scopes is defined and code_model.credential_schema_policy.credential_scopes|length == 0 %}
62
+ {% if code_model.credential_model.credential_schema_policy.credential_scopes is defined and code_model.credential_model.credential_schema_policy.credential_scopes|length == 0 %}
63
63
  if not self.credential_scopes and not self.authentication_policy:
64
64
  raise ValueError("You must provide either credential_scopes or authentication_policy as kwargs")
65
65
  {% endif %}
66
66
  if self.credential and not self.authentication_policy:
67
- self.authentication_policy = {{ code_model.credential_schema_policy.call(async_mode) }}
67
+ self.authentication_policy = {{ code_model.credential_model.credential_schema_policy.call(async_mode) }}
68
68
  {% endif %}
@@ -0,0 +1,10 @@
1
+ -e ../../../tools/azure-devtools
2
+ -e ../../../tools/azure-sdk-tools
3
+ ../../core/azure-core
4
+ {% if token_credential -%}
5
+ ../../identity/azure-identity
6
+ {% endif -%}
7
+ {% if azure_arm -%}
8
+ ../../core/azure-mgmt-core
9
+ {% endif -%}
10
+ aiohttp
@@ -1,5 +1,5 @@
1
1
 
2
- class {{ enum.name }}(with_metaclass(CaseInsensitiveEnumMeta, {{ enum.enum_type.type_annotation }}, Enum)):
2
+ class {{ enum.name }}({{ enum.enum_type.type_annotation() }}, Enum, metaclass=CaseInsensitiveEnumMeta):
3
3
  {% if enum.description %}
4
4
  """{{ enum.description | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
5
5
  """
@@ -2,7 +2,6 @@
2
2
  {{ code_model.options['license_header'] }}
3
3
 
4
4
  from enum import Enum
5
- from six import with_metaclass
6
5
  from azure.core import CaseInsensitiveEnumMeta
7
6
 
8
7
  {% for enum in code_model.enums.values() | sort %}
@@ -1,15 +1,18 @@
1
+ {% import 'keywords.jinja2' as keywords %}
1
2
  # coding=utf-8
2
3
  {{ code_model.options['license_header'] }}
3
4
 
4
- from ._{{ code_model.module_name }} import {{ code_model.class_name }}
5
+ {% if code_model.rest.request_builders %}
6
+ from .{{ code_model.service_client.filename }} import {{ code_model.class_name }}
7
+ {% endif %}
5
8
  {% if not async_mode and code_model.options['package_version']%}
6
9
  from ._version import VERSION
7
10
 
8
11
  __version__ = VERSION
9
12
  {% endif %}
10
- __all__ = ['{{ code_model.class_name }}']
11
13
 
12
- # `._patch.py` is used for handwritten extensions to the generated code
13
- # Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
14
- from ._patch import patch_sdk
15
- patch_sdk()
14
+ {{ keywords.patch_imports(try_except=True) }}
15
+ __all__ = [{{("'" + code_model.class_name + "'") if code_model.rest.request_builders else ""}}]
16
+ {{ keywords.extend_all }}
17
+
18
+ _patch_sdk()
@@ -3,4 +3,17 @@
3
3
  {% set await = "await " if async_mode else "" %}
4
4
  {% set async_class = "Async" if async_mode else "" %}
5
5
  {% macro escape_str(s) %}'{{ s|replace("'", "\\'") }}'{% endmacro %}
6
- {% set kwargs_declaration = "**kwargs: Any" if async_mode else "**kwargs # type: Any" %}
6
+ {% set kwargs_declaration = "**kwargs: Any" if async_mode else "**kwargs # type: Any" %}
7
+ {% set extend_all = "__all__.extend([p for p in _patch_all if p not in __all__])" %}
8
+ {% macro patch_imports(try_except=False) %}
9
+ {% set indentation = " " if try_except else "" %}
10
+ {% if try_except %}
11
+ try:
12
+ {% endif %}
13
+ {{ indentation }}from ._patch import __all__ as _patch_all
14
+ {{ indentation }}from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import
15
+ {% if try_except %}
16
+ except ImportError:
17
+ _patch_all = []
18
+ {% endif %}
19
+ from ._patch import patch_sdk as _patch_sdk{% endmacro %}
@@ -6,7 +6,7 @@
6
6
  {% endif %}
7
7
  {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
8
8
  {{ op_tools.description(operation, operation_serializer) | indent -}}
9
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
9
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
10
10
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
11
11
  {%- endif %}
12
12
  {{ op_tools.serialize(operation_serializer.initial_call(operation)) | indent }}
@@ -7,7 +7,7 @@
7
7
  {% endif %}
8
8
  {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
9
9
  {{ op_tools.description(operation, operation_serializer) | indent }}
10
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
10
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
11
11
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
12
12
  {% endif %}
13
13
  {{ op_tools.serialize(operation_serializer.set_up_params_for_pager(operation)) | indent }}
@@ -92,9 +92,9 @@
92
92
  },
93
93
  "config": {
94
94
  "credential": {{ code_model.options['credential'] | tojson }},
95
- "credential_scopes": {{ (code_model.credential_schema_policy.credential_scopes if code_model.options['credential'] and code_model.credential_schema_policy.credential_scopes is defined else None)| tojson}},
96
- "credential_call_sync": {{ (code_model.credential_schema_policy.call(async_mode=False) if code_model.options['credential'] else None) | tojson }},
97
- "credential_call_async": {{ (code_model.credential_schema_policy.call(async_mode=True) if code_model.options['credential'] else None) | tojson }},
95
+ "credential_scopes": {{ (code_model.credential_model.credential_schema_policy.credential_scopes if code_model.options['credential'] and code_model.credential_model.credential_schema_policy.credential_scopes is defined else None)| tojson}},
96
+ "credential_call_sync": {{ (code_model.credential_model.credential_schema_policy.call(async_mode=False) if code_model.options['credential'] else None) | tojson }},
97
+ "credential_call_async": {{ (code_model.credential_model.credential_schema_policy.call(async_mode=True) if code_model.options['credential'] else None) | tojson }},
98
98
  "sync_imports": {{ sync_config_imports | tojson }},
99
99
  "async_imports": {{ async_config_imports | tojson }}
100
100
  },
@@ -1,12 +1,7 @@
1
- {% set basename = model.base_models | join(', ', attribute='name') if model.base_models else "" %}
2
1
  {# actual template starts here #}
3
2
 
4
3
 
5
- {% if basename %}
6
- class {{ model.name }}({{ basename }}):
7
- {% else %}
8
- class {{ model.name }}(msrest.serialization.Model):
9
- {% endif %}
4
+ {{ declare_model(model) }}
10
5
  """{{ model.description }}
11
6
  {% if model.discriminator_name %}
12
7
 
@@ -1,8 +1,9 @@
1
+ {% import 'keywords.jinja2' as keywords %}
1
2
  # coding=utf-8
2
3
  {{ code_model.options['license_header'] }}
3
4
  {% macro iterate_models_py3() %}
4
5
  {% for schema in schemas %}
5
- from ._models_py3 import {{ schema }}
6
+ from .{{ code_model.get_models_filename(is_python3_file=True) }} import {{ schema }}
6
7
  {% endfor %}
7
8
  {% endmacro %}
8
9
 
@@ -14,19 +15,19 @@ try:
14
15
  {{ iterate_models_py3() | indent-}}
15
16
  except (SyntaxError, ImportError):
16
17
  {% for schema in schemas %}
17
- from ._models import {{ schema }} # type: ignore
18
+ from .{{ code_model.get_models_filename(is_python3_file=False) }} import {{ schema }} # type: ignore
18
19
  {% endfor %}
19
20
  {% endif %}
20
21
  {% endif %}
21
22
  {% if enums %}
22
23
 
23
- from ._{{ code_model.module_name }}_enums import (
24
+ from .{{ code_model.enums_filename }} import (
24
25
  {% for enum in enums %}
25
26
  {{ enum }},
26
27
  {% endfor %}
27
28
  )
28
29
  {% endif %}
29
-
30
+ {{ keywords.patch_imports() }}
30
31
  __all__ = [
31
32
  {% for schema in schemas %}
32
33
  '{{ schema }}',
@@ -37,3 +38,5 @@ __all__ = [
37
38
  {% endfor %}
38
39
  {% endif %}
39
40
  ]
41
+ {{ keywords.extend_all }}
42
+ _patch_sdk()
@@ -9,16 +9,15 @@
9
9
  {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
10
10
  {% if operation.want_description_docstring %}
11
11
  {{ op_tools.description(operation, operation_serializer) | indent }}{% endif %}
12
- cls = kwargs.pop('cls', None) {{ operation_serializer.cls_type_annotation(operation) }}
13
12
  {% if operation.deprecated %}
14
13
  warnings.warn('Method {{operation.name}} is deprecated', DeprecationWarning)
15
14
  {% endif %}
16
15
  {{ op_tools.serialize(operation_serializer.error_map(operation)) | indent }}
17
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
16
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
18
17
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
19
18
  {% endif %}
20
19
  {{ op_tools.serialize(operation_serializer.call_request_builder(operation)) | indent }}
21
- pipeline_response = {{ keywords.await }}self._client._pipeline.run( # pylint: disable=protected-access
20
+ pipeline_response = {{ keywords.await }}self._client._pipeline.run( # type: ignore # pylint: disable=protected-access
22
21
  request,
23
22
  {{ stream_request_parameter }},
24
23
  **kwargs
@@ -1,30 +1,33 @@
1
1
  {% set disable = " # pylint: disable=too-many-public-methods" if operation_group.operations | length > 20 else "" %}
2
+ {% if operation_group.is_empty_operation_group and code_model.need_mixin_abc %}
3
+ {% set object_base_class = "(MixinABC)" %}
4
+ {% elif not (async_mode or code_model.options["python3_only"]) %}
5
+ {% set object_base_class = "(object)" %}
6
+ {% else %}
7
+ {% set object_base_class = "" %}
8
+ {% endif %}
2
9
  class {{ operation_group.class_name }}{{ object_base_class }}:{{ disable }}
3
10
  {% if not operation_group.is_empty_operation_group %}
4
- """{{ operation_group.class_name }} {{ operations_description }}.
5
-
6
- You should not instantiate this class directly. Instead, you should create a Client instance that
7
- instantiates it for you and attaches it as an attribute.
11
+ """
12
+ .. warning::
13
+ **DO NOT** instantiate this class directly.
8
14
 
9
- {% if code_model.schemas and code_model.options["models_mode"] %}
10
- :ivar models: Alias to model classes used in this operation group.
11
- :type models: ~{{ code_model.namespace }}.models
12
- {% endif %}
13
- :param client: Client for service requests.
14
- :param config: Configuration of service client.
15
- :param serializer: An object model serializer.
16
- :param deserializer: An object model deserializer.
15
+ Instead, you should access the following operations through
16
+ :class:`{{ "~" + code_model.namespace + (".aio." if async_mode else ".") + code_model.class_name }}`'s
17
+ :attr:`{{ operation_group.name }}` attribute.
17
18
  """
18
19
 
19
20
  {% if code_model.schemas and code_model.options["models_mode"] %}
20
21
  models = _models
21
22
 
22
23
  {% endif %}
23
- def __init__(self, client, config, serializer, deserializer){{ return_none_type_annotation }}:
24
- self._client = client
25
- self._serialize = serializer
26
- self._deserialize = deserializer
27
- self._config = config
24
+ def __init__(self, *args, **kwargs){{ return_none_type_annotation }}:
25
+ input_args = list(args)
26
+ self._client = input_args.pop(0) if input_args else kwargs.pop("client")
27
+ self._config = input_args.pop(0) if input_args else kwargs.pop("config")
28
+ self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer")
29
+ self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer")
30
+
28
31
  {% endif %}
29
32
  {% for operation in operation_group.operations %}
30
33
 
@@ -1,5 +1,4 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
- {% set object_base_class = "" if async_mode else "(object)" %}
3
2
  {% set operations_description = "async operations" if async_mode else "operations" %}
4
3
  {% set return_none_type_annotation = " -> None" if async_mode else "" %}
5
4
  # pylint: disable=too-many-lines
@@ -1,9 +1,11 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
+ {% import 'keywords.jinja2' as keywords %}
2
3
  {# actual template starts here #}
3
4
  # coding=utf-8
4
5
  {{ code_model.options['license_header'] }}
5
6
 
6
7
  {{ op_tools.serialize(operation_group_imports()) }}
8
+ {{ keywords.patch_imports() }}
7
9
  {% if operation_groups %}
8
10
  __all__ = [
9
11
  {% for operation_group in operation_groups %}
@@ -11,3 +13,5 @@ __all__ = [
11
13
  {% endfor %}
12
14
  ]
13
15
  {% endif %}
16
+ {{ keywords.extend_all }}
17
+ _patch_sdk()
@@ -9,7 +9,7 @@
9
9
  {% if operation.deprecated %}
10
10
  warnings.warn('Method {{operation.name}} is deprecated', DeprecationWarning)
11
11
  {% endif %}
12
- {% if operation.parameters.kwargs_to_pop(async_mode) %}
12
+ {% if operation_serializer.pop_kwargs_from_signature(operation) %}
13
13
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
14
14
  {% endif %}
15
15
  {{ op_tools.serialize(operation_serializer.set_up_params_for_pager(operation)) | indent }}
@@ -1,31 +1,20 @@
1
- # coding=utf-8
2
- # --------------------------------------------------------------------------
3
- #
4
- # Copyright (c) Microsoft Corporation. All rights reserved.
5
- #
6
- # The MIT License (MIT)
7
- #
8
- # Permission is hereby granted, free of charge, to any person obtaining a copy
9
- # of this software and associated documentation files (the ""Software""), to
10
- # deal in the Software without restriction, including without limitation the
11
- # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
- # sell copies of the Software, and to permit persons to whom the Software is
13
- # furnished to do so, subject to the following conditions:
14
- #
15
- # The above copyright notice and this permission notice shall be included in
16
- # all copies or substantial portions of the Software.
17
- #
18
- # THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
- # IN THE SOFTWARE.
25
- #
26
- # --------------------------------------------------------------------------
1
+ # ------------------------------------
2
+ # Copyright (c) Microsoft Corporation.
3
+ # Licensed under the MIT License.
4
+ # ------------------------------------
5
+ """Customize generated code here.
6
+
7
+ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
8
+ """
9
+ {{ imports }}
10
+
11
+ {% set type_annotation = ": List[str]" %}
12
+ __all__{{ type_annotation if is_python3_file else "" }} = []{{ "" if is_python3_file else (" # type" + type_annotation) }} # Add all objects you want publicly available to users at this package level
27
13
 
28
- # This file is used for handwritten extensions to the generated code. Example:
29
- # https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
30
14
  def patch_sdk():
31
- pass
15
+ """Do not remove from this file.
16
+
17
+ `patch_sdk` is a last resort escape hatch that allows you to do customizations
18
+ you can't accomplish using the techniques described in
19
+ https://aka.ms/azsdk/python/dpcodegen/python/customize
20
+ """
@@ -4,13 +4,11 @@
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_python3_file) %}
7
+ {% if request_builder_serializer.pop_kwargs_from_signature(request_builder) %}
8
8
  {{ op_tools.serialize(request_builder_serializer.pop_kwargs_from_signature(request_builder)) | indent }}
9
- {% endif %}
10
- {% if request_builder.parameters.constant|selectattr("original_parameter", "equalto", None)|selectattr("in_method_code")|selectattr("in_method_signature", "equalto", False) %}
11
- {% for constant_parameter in request_builder.parameters.constant|selectattr("original_parameter", "equalto", None)|selectattr("in_method_code")|selectattr("in_method_signature", "equalto", False) %}
12
- {{ constant_parameter.serialized_name }} = {{ constant_parameter.constant_declaration }}
13
- {% endfor %}
9
+ {%- endif -%}
10
+ {% if request_builder_serializer.declare_non_inputtable_constants(request_builder) %}
11
+ {{ op_tools.serialize(request_builder_serializer.declare_non_inputtable_constants(request_builder)) | indent }}
14
12
  {% endif %}
15
13
  # Construct URL
16
14
  {{ request_builder_serializer.construct_url(request_builder) }}
@@ -1,34 +1,93 @@
1
- {% set name = code_model.options["package_name"] or code_model.class_name %}
2
- {% set azure_mgmt_core_import = ', "azure-mgmt-core<2.0.0,>=1.2.1"' if code_model.options["azure_arm"] else "" %}
3
1
  # coding=utf-8
4
- {{ code_model.options['license_header'] }}
2
+ {{ license_header }}
5
3
  # coding: utf-8
6
-
4
+ {% if package_mode %}
5
+ import os
6
+ import re
7
+ {% endif -%}
7
8
  from setuptools import setup, find_packages
8
9
 
9
- NAME = "{{ name|lower }}"
10
- VERSION = "{{ code_model.options.get('package_version', '0.0.0') }}"
10
+ {% set package_name_render = package_name or code_model.class_name %}
11
+
12
+ PACKAGE_NAME = "{{ package_name_render|lower }}"
13
+ {% if package_mode -%}
14
+ PACKAGE_PPRINT_NAME = "{{ package_pprint_name }}"
15
+
16
+ # a-b-c => a/b/c
17
+ package_folder_path = PACKAGE_NAME.replace("-", "/")
11
18
 
12
- # To install the library, run the following
13
- #
14
- # python setup.py install
15
- #
16
- # prerequisite: setuptools
17
- # http://pypi.python.org/pypi/setuptools
19
+ # Version extraction inspired from 'requests'
20
+ with open(os.path.join(package_folder_path, "_version.py"), "r") as fd:
21
+ version = re.search(
22
+ r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE
23
+ ).group(1)
18
24
 
19
- REQUIRES = ["msrest>=0.6.21", "azure-core<2.0.0,>=1.20.1"{{ azure_mgmt_core_import }}]
25
+ if not version:
26
+ raise RuntimeError("Cannot find version information")
27
+ {% set description = "Microsoft %s Client Library for Python"|format(package_pprint_name) %}
28
+ {% set author_email = "azpysdkhelp@microsoft.com" %}
29
+ {% set url = "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk" %}
30
+ {% else %}
31
+ version = "{{ code_model.options['package_version'] }}"
32
+ {% set description = "%s"|format(package_name_render) %}
33
+ {% set long_description = code_model.description %}
34
+ {% set author_email = "" %}
35
+ {% set url = "" %}
36
+ {% endif -%}
20
37
 
21
38
  setup(
22
- name=NAME,
23
- version=VERSION,
24
- description="{{ name }}",
25
- author_email="",
26
- url="",
27
- keywords=["Swagger", "{{ code_model.class_name }}"],
28
- install_requires=REQUIRES,
39
+ name=PACKAGE_NAME,
40
+ version=version,
41
+ description="{{ description }}",
42
+ {% if package_mode %}
43
+ long_description=open("README.md", "r").read(),
44
+ long_description_content_type="text/markdown",
45
+ license="MIT License",
46
+ author="Microsoft Corporation",
47
+ {% endif %}
48
+ author_email="{{ author_email }}",
49
+ url="{{ url }}",
50
+ keywords="azure, azure sdk",
51
+ {% if package_mode %}
52
+ classifiers=[
53
+ "Development Status :: {{ dev_status }}",
54
+ "Programming Language :: Python",
55
+ "Programming Language :: Python :: 3 :: Only",
56
+ "Programming Language :: Python :: 3",
57
+ "Programming Language :: Python :: 3.6",
58
+ "Programming Language :: Python :: 3.7",
59
+ "Programming Language :: Python :: 3.8",
60
+ "Programming Language :: Python :: 3.9",
61
+ "Programming Language :: Python :: 3.10",
62
+ "License :: OSI Approved :: MIT License",
63
+ ],
64
+ zip_safe=False,
65
+ packages=find_packages(
66
+ exclude=[
67
+ "tests",
68
+ # Exclude packages that will be covered by PEP420 or nspkg
69
+ {%- for pkgutil_name in pkgutil_names %}
70
+ "{{ pkgutil_name }}",
71
+ {%- endfor %}
72
+ ]
73
+ ),
74
+ {% else %}
29
75
  packages=find_packages(),
30
76
  include_package_data=True,
77
+ {% endif %}
78
+ install_requires=[
79
+ "{{ dependency_msrest }}",
80
+ {% if azure_arm %}
81
+ "{{ dependency_azure_mgmt_core }}",
82
+ {% else %}
83
+ "{{ dependency_azure_core }}",
84
+ {% endif %}
85
+ ],
86
+ {% if package_mode %}
87
+ python_requires=">=3.6",
88
+ {% else %}
31
89
  long_description="""\
32
90
  {{ code_model.description }}
33
91
  """
92
+ {% endif %}
34
93
  )
@@ -1,8 +1,9 @@
1
+ {% import 'keywords.jinja2' as keywords with context %}
1
2
  {{ code_model.options['license_header'] }}
2
3
 
3
4
  {{ imports }}
4
5
 
5
- {% if code_model.need_request_converter %}
6
+ {% if code_model.need_request_converter and not async_mode %}
6
7
  def _convert_request(request, files=None):
7
8
  data = request.content if not files else None
8
9
  request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data)
@@ -10,7 +11,7 @@ def _convert_request(request, files=None):
10
11
  request.set_formdata_body(files)
11
12
  return request
12
13
  {% endif %}
13
- {% if code_model.need_format_url %}
14
+ {% if code_model.need_format_url and not async_mode %}
14
15
 
15
16
  def _format_url_section(template, **kwargs):
16
17
  components = template.split("/")
@@ -24,3 +25,12 @@ def _format_url_section(template, **kwargs):
24
25
  ]
25
26
  template = "/".join(components)
26
27
  {% endif %}
28
+ {% if code_model.need_mixin_abc %}
29
+
30
+ class MixinABC(ABC):
31
+ """DO NOT use this class. It is for internal typing use only."""
32
+ _client: "{{ keywords.async_class }}PipelineClient"
33
+ _config: {{ code_model.class_name }}Configuration
34
+ _serialize: "Serializer"
35
+ _deserialize: "Deserializer"
36
+ {% endif %}