@autorest/python 5.13.0 → 5.14.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.
- package/ChangeLog.md +18 -0
- package/autorest/codegen/__init__.py +22 -0
- package/autorest/codegen/models/code_model.py +3 -0
- package/autorest/codegen/serializers/__init__.py +71 -2
- package/autorest/codegen/serializers/general_serializer.py +4 -1
- package/autorest/codegen/templates/CHANGELOG.md.jinja2 +6 -0
- package/autorest/codegen/templates/LICENSE.jinja2 +21 -0
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +7 -0
- package/autorest/codegen/templates/README.md.jinja2 +105 -0
- package/autorest/codegen/templates/dev_requirements.txt.jinja2 +10 -0
- package/autorest/codegen/templates/operation_group.py.jinja2 +13 -17
- package/autorest/codegen/templates/setup.py.jinja2 +79 -20
- package/package.json +1 -1
package/ChangeLog.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
### 2022-03-08 - 5.14.0
|
|
4
|
+
|
|
5
|
+
| Library | Min Version |
|
|
6
|
+
| ----------------------------------------------------------------------- | ----------- |
|
|
7
|
+
| `@autorest/core` | `3.6.2` |
|
|
8
|
+
| `@autorest/modelerfour` | `4.19.1` |
|
|
9
|
+
| `azure-core` dep of generated code | `1.20.1` |
|
|
10
|
+
| `msrest` dep of generated code | `0.6.21` |
|
|
11
|
+
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0` |
|
|
12
|
+
|
|
13
|
+
**New Features**
|
|
14
|
+
|
|
15
|
+
- Add flag `--package-mode=mgmtplane|dataplane|<custom package template folder>` to generate necessary files for package #1154
|
|
16
|
+
|
|
17
|
+
**Bug Fixes**
|
|
18
|
+
|
|
19
|
+
- Improve operation group documentation to prevent users from initializing operation groups themselves #1179
|
|
20
|
+
|
|
3
21
|
### 2022-03-03 - 5.13.0
|
|
4
22
|
|
|
5
23
|
| Library | Min Version |
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import logging
|
|
7
7
|
import sys
|
|
8
8
|
from typing import Dict, Any, Set, Union, List, Type
|
|
9
|
+
from pathlib import Path
|
|
9
10
|
import yaml
|
|
10
11
|
|
|
11
12
|
from .. import Plugin
|
|
@@ -70,12 +71,21 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
|
|
|
70
71
|
if options["basic_setup_py"] and not options["package_version"]:
|
|
71
72
|
raise ValueError("--basic-setup-py must be used with --package-version")
|
|
72
73
|
|
|
74
|
+
if options["package_mode"] and not options["package_version"]:
|
|
75
|
+
raise ValueError("--package-mode must be used with --package-version")
|
|
76
|
+
|
|
73
77
|
if not options["show_operations"] and options["combine_operation_files"]:
|
|
74
78
|
raise ValueError(
|
|
75
79
|
"Can not combine operation files if you are not showing operations. "
|
|
76
80
|
"If you want operation files, pass in flag --show-operations"
|
|
77
81
|
)
|
|
78
82
|
|
|
83
|
+
if options["package_mode"]:
|
|
84
|
+
if options["package_mode"] not in ("mgmtplane", "dataplane") and not Path(options["package_mode"]).exists():
|
|
85
|
+
raise ValueError(
|
|
86
|
+
"--package-mode can only be 'mgmtplane' or 'dataplane' or directory which contains template files"
|
|
87
|
+
)
|
|
88
|
+
|
|
79
89
|
if options["reformat_next_link"] and options["version_tolerant"]:
|
|
80
90
|
raise ValueError(
|
|
81
91
|
"--reformat-next-link can not be true for version tolerant generations. "
|
|
@@ -117,6 +127,14 @@ class CodeGenerator(Plugin):
|
|
|
117
127
|
exceptions_set.add(id(exception["schema"]))
|
|
118
128
|
return exceptions_set
|
|
119
129
|
|
|
130
|
+
@staticmethod
|
|
131
|
+
def _build_package_dependency() -> Dict[str, str]:
|
|
132
|
+
return {
|
|
133
|
+
"dependency_azure_mgmt_core": "azure-mgmt-core<2.0.0,>=1.3.0",
|
|
134
|
+
"dependency_azure_core": "azure-core<2.0.0,>=1.20.1",
|
|
135
|
+
"dependency_msrest": "msrest>=0.6.21",
|
|
136
|
+
}
|
|
137
|
+
|
|
120
138
|
def _create_code_model(self, yaml_data: Dict[str, Any], options: Dict[str, Union[str, bool]]) -> CodeModel:
|
|
121
139
|
# Create a code model
|
|
122
140
|
|
|
@@ -161,6 +179,7 @@ class CodeGenerator(Plugin):
|
|
|
161
179
|
if options["credential"]:
|
|
162
180
|
code_model.global_parameters.add_credential_global_parameter()
|
|
163
181
|
|
|
182
|
+
code_model.package_dependency = self._build_package_dependency()
|
|
164
183
|
return code_model
|
|
165
184
|
|
|
166
185
|
def _get_credential_scopes(self, credential):
|
|
@@ -295,6 +314,9 @@ class CodeGenerator(Plugin):
|
|
|
295
314
|
"low_level_client": low_level_client,
|
|
296
315
|
"combine_operation_files": self._autorestapi.get_boolean_value("combine-operation-files", version_tolerant),
|
|
297
316
|
"python3_only": python3_only,
|
|
317
|
+
"package_mode": self._autorestapi.get_value("package-mode"),
|
|
318
|
+
"package_pprint_name": self._autorestapi.get_value("package-pprint-name"),
|
|
319
|
+
"package_configuration": self._autorestapi.get_value("package-configuration"),
|
|
298
320
|
"default_optional_constants_to_none": self._autorestapi.get_boolean_value(
|
|
299
321
|
"default-optional-constants-to-none", low_level_client or version_tolerant
|
|
300
322
|
),
|
|
@@ -51,6 +51,8 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
51
51
|
:type primitives: Dict[int, ~autorest.models.BaseSchema]
|
|
52
52
|
:param operation_groups: The operation groups we are going to serialize
|
|
53
53
|
:type operation_groups: list[~autorest.models.OperationGroup]
|
|
54
|
+
:param package_dependency: All the dependencies needed in setup.py
|
|
55
|
+
:type package_dependency: Dict[str, str]
|
|
54
56
|
"""
|
|
55
57
|
|
|
56
58
|
def __init__(
|
|
@@ -76,6 +78,7 @@ class CodeModel: # pylint: disable=too-many-instance-attributes, too-many-publi
|
|
|
76
78
|
self._rest: Optional[Rest] = None
|
|
77
79
|
self.request_builder_ids: Dict[int, RequestBuilder] = {}
|
|
78
80
|
self._credential_schema_policy: Optional[CredentialSchemaPolicy] = None
|
|
81
|
+
self.package_dependency: Dict[str, str] = {}
|
|
79
82
|
|
|
80
83
|
@property
|
|
81
84
|
def global_parameters(self) -> GlobalParameterList:
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import List, Optional
|
|
6
|
+
from typing import Dict, List, Optional, Any
|
|
7
7
|
from pathlib import Path
|
|
8
|
-
from jinja2 import PackageLoader, Environment
|
|
8
|
+
from jinja2 import PackageLoader, Environment, FileSystemLoader, StrictUndefined
|
|
9
9
|
from autorest.codegen.models.operation_group import OperationGroup
|
|
10
10
|
|
|
11
11
|
from ...jsonrpc import AutorestAPI
|
|
@@ -13,6 +13,7 @@ from ..models import (
|
|
|
13
13
|
CodeModel,
|
|
14
14
|
OperationGroup,
|
|
15
15
|
RequestBuilder,
|
|
16
|
+
TokenCredentialSchema
|
|
16
17
|
)
|
|
17
18
|
from .enum_serializer import EnumSerializer
|
|
18
19
|
from .general_serializer import GeneralSerializer
|
|
@@ -29,6 +30,20 @@ __all__ = [
|
|
|
29
30
|
"JinjaSerializer",
|
|
30
31
|
]
|
|
31
32
|
|
|
33
|
+
_PACKAGE_FILES = [
|
|
34
|
+
"CHANGELOG.md.jinja2",
|
|
35
|
+
"dev_requirements.txt.jinja2",
|
|
36
|
+
"LICENSE.jinja2",
|
|
37
|
+
"MANIFEST.in.jinja2",
|
|
38
|
+
"README.md.jinja2",
|
|
39
|
+
"setup.py.jinja2",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
_REGENERATE_FILES = {
|
|
43
|
+
"setup.py",
|
|
44
|
+
"MANIFEST.in"
|
|
45
|
+
}
|
|
46
|
+
|
|
32
47
|
class JinjaSerializer:
|
|
33
48
|
def __init__(self, autorestapi: AutorestAPI, code_model: CodeModel) -> None:
|
|
34
49
|
self._autorestapi = autorestapi
|
|
@@ -74,6 +89,60 @@ class JinjaSerializer:
|
|
|
74
89
|
if self.code_model.options["models_mode"] and (self.code_model.schemas or self.code_model.enums):
|
|
75
90
|
self._serialize_and_write_models_folder(env=env, namespace_path=namespace_path)
|
|
76
91
|
|
|
92
|
+
if self.code_model.options["package_mode"]:
|
|
93
|
+
self._serialize_and_write_package_files(out_path=namespace_path)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _serialize_and_write_package_files(self, out_path: Path) -> None:
|
|
97
|
+
def _serialize_and_write_package_files_proc(**kwargs: Any):
|
|
98
|
+
for template_name in package_files:
|
|
99
|
+
file = template_name.replace(".jinja2", "")
|
|
100
|
+
output_name = out_path / file
|
|
101
|
+
if not self._autorestapi.read_file(output_name) or file in _REGENERATE_FILES:
|
|
102
|
+
template = env.get_template(template_name)
|
|
103
|
+
render_result = template.render(**kwargs)
|
|
104
|
+
self._autorestapi.write_file(output_name, render_result)
|
|
105
|
+
|
|
106
|
+
def _prepare_params() -> Dict[Any, Any]:
|
|
107
|
+
package_parts = self.code_model.options["package_name"].split("-")[:-1]
|
|
108
|
+
try:
|
|
109
|
+
token_cred = isinstance(self.code_model.credential_schema_policy.credential, TokenCredentialSchema)
|
|
110
|
+
except ValueError:
|
|
111
|
+
token_cred = False
|
|
112
|
+
version = self.code_model.options["package_version"]
|
|
113
|
+
if any(x in version for x in ["a", "b", "rc"]) or version[0] == '0':
|
|
114
|
+
dev_status = "4 - Beta"
|
|
115
|
+
else:
|
|
116
|
+
dev_status = "5 - Production/Stable"
|
|
117
|
+
params = {
|
|
118
|
+
"token_credential": token_cred,
|
|
119
|
+
"pkgutil_names": [".".join(package_parts[: i + 1]) for i in range(len(package_parts))],
|
|
120
|
+
"init_names": ["/".join(package_parts[: i + 1]) + "/__init__.py" for i in range(len(package_parts))],
|
|
121
|
+
"dev_status": dev_status
|
|
122
|
+
}
|
|
123
|
+
params.update(self.code_model.options)
|
|
124
|
+
params.update(self.code_model.package_dependency)
|
|
125
|
+
return params
|
|
126
|
+
|
|
127
|
+
count = self.code_model.options["package_name"].count("-") + 1
|
|
128
|
+
for _ in range(count):
|
|
129
|
+
out_path = out_path / Path("..")
|
|
130
|
+
|
|
131
|
+
if self.code_model.options["package_mode"] in ("dataplane", "mgmtplane"):
|
|
132
|
+
env = Environment(
|
|
133
|
+
loader=PackageLoader("autorest.codegen", "templates"),
|
|
134
|
+
undefined=StrictUndefined)
|
|
135
|
+
package_files = _PACKAGE_FILES
|
|
136
|
+
_serialize_and_write_package_files_proc(**_prepare_params())
|
|
137
|
+
elif Path(self.code_model.options["package_mode"]).exists():
|
|
138
|
+
env = Environment(
|
|
139
|
+
loader=FileSystemLoader(str(Path(self.code_model.options["package_mode"]))),
|
|
140
|
+
keep_trailing_newline=True,
|
|
141
|
+
undefined=StrictUndefined
|
|
142
|
+
)
|
|
143
|
+
package_files = env.list_templates()
|
|
144
|
+
params = self.code_model.options["package_configuration"] or {}
|
|
145
|
+
_serialize_and_write_package_files_proc(**params)
|
|
77
146
|
|
|
78
147
|
|
|
79
148
|
def _keep_patch_file(self, path_file: Path, env: Environment):
|
|
@@ -119,4 +119,7 @@ class GeneralSerializer:
|
|
|
119
119
|
|
|
120
120
|
def serialize_setup_file(self) -> str:
|
|
121
121
|
template = self.env.get_template("setup.py.jinja2")
|
|
122
|
-
|
|
122
|
+
params = {}
|
|
123
|
+
params.update(self.code_model.options)
|
|
124
|
+
params.update(self.code_model.package_dependency)
|
|
125
|
+
return template.render(code_model=self.code_model, **params)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) Microsoft Corporation.
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -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
|
+

|
|
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 %}
|
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
{% set disable = " # pylint: disable=too-many-public-methods" if operation_group.operations | length > 20 else "" %}
|
|
2
2
|
class {{ operation_group.class_name }}{{ object_base_class }}:{{ disable }}
|
|
3
3
|
{% if not operation_group.is_empty_operation_group %}
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
instantiates it for you and attaches it as an attribute.
|
|
4
|
+
"""
|
|
5
|
+
.. warning::
|
|
6
|
+
**DO NOT** instantiate this class directly.
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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.
|
|
8
|
+
Instead, you should access the following operations through
|
|
9
|
+
:class:`{{ "~" + code_model.namespace + (".aio." if async_mode else ".") + code_model.class_name }}`'s
|
|
10
|
+
:attr:`{{ operation_group.name }}` attribute.
|
|
17
11
|
"""
|
|
18
12
|
|
|
19
13
|
{% if code_model.schemas and code_model.options["models_mode"] %}
|
|
20
14
|
models = _models
|
|
21
15
|
|
|
22
16
|
{% endif %}
|
|
23
|
-
def __init__(self,
|
|
24
|
-
|
|
25
|
-
self.
|
|
26
|
-
self.
|
|
27
|
-
self.
|
|
17
|
+
def __init__(self, *args, **kwargs){{ return_none_type_annotation }}:
|
|
18
|
+
args = list(args)
|
|
19
|
+
self._client = args.pop(0) if args else kwargs.pop("client")
|
|
20
|
+
self._config = args.pop(0) if args else kwargs.pop("config")
|
|
21
|
+
self._serialize = args.pop(0) if args else kwargs.pop("serializer")
|
|
22
|
+
self._deserialize = args.pop(0) if args else kwargs.pop("deserializer")
|
|
23
|
+
|
|
28
24
|
{% endif %}
|
|
29
25
|
{% for operation in operation_group.operations %}
|
|
30
26
|
|
|
@@ -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
|
-
{{
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
#
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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=
|
|
23
|
-
version=
|
|
24
|
-
description="{{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
)
|