@typespec/http-client-python 0.8.2 → 0.8.3-dev.1
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/README.md +0 -6
- package/dist/emitter/code-model.d.ts.map +1 -1
- package/dist/emitter/code-model.js +3 -0
- package/dist/emitter/code-model.js.map +1 -1
- package/dist/emitter/lib.d.ts +0 -1
- package/dist/emitter/lib.d.ts.map +1 -1
- package/dist/emitter/lib.js +0 -5
- package/dist/emitter/lib.js.map +1 -1
- package/emitter/src/code-model.ts +3 -0
- package/emitter/src/lib.ts +0 -7
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/ci/pylintrc +1 -1
- package/eng/scripts/ci/regenerate.ts +0 -3
- package/eng/scripts/setup/__pycache__/venvtools.cpython-38.pyc +0 -0
- package/generator/build/lib/pygen/codegen/__init__.py +7 -21
- package/generator/build/lib/pygen/codegen/_utils.py +26 -2
- package/generator/build/lib/pygen/codegen/models/code_model.py +33 -0
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +3 -1
- package/generator/build/lib/pygen/codegen/templates/client_container.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/config_container.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/conftest.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/enum_container.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/init.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +3 -5
- package/generator/build/lib/pygen/codegen/templates/model_container.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/model_init.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/operation_groups_container.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/LICENSE.jinja2 +1 -21
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +6 -4
- package/generator/build/lib/pygen/codegen/templates/patch.py.jinja2 +9 -4
- package/generator/build/lib/pygen/codegen/templates/request_builders.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/rest_init.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/sample.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +4 -25
- package/generator/build/lib/pygen/codegen/templates/test.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/testpreparer.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/types.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/validation.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/vendor.py.jinja2 +3 -1
- package/generator/build/lib/pygen/codegen/templates/version.py.jinja2 +3 -1
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/__init__.py +7 -21
- package/generator/pygen/codegen/_utils.py +26 -2
- package/generator/pygen/codegen/models/code_model.py +33 -0
- package/generator/pygen/codegen/serializers/__init__.py +3 -1
- package/generator/pygen/codegen/templates/client_container.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/config_container.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/conftest.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/enum_container.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/init.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +3 -5
- package/generator/pygen/codegen/templates/model_container.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/model_init.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/operation_groups_container.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/operations_folder_init.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/packaging_templates/LICENSE.jinja2 +1 -21
- package/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +6 -4
- package/generator/pygen/codegen/templates/patch.py.jinja2 +9 -4
- package/generator/pygen/codegen/templates/request_builders.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/rest_init.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/sample.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/serialization.py.jinja2 +4 -25
- package/generator/pygen/codegen/templates/test.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/testpreparer.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/types.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/validation.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/vendor.py.jinja2 +3 -1
- package/generator/pygen/codegen/templates/version.py.jinja2 +3 -1
- package/generator/test/azure/requirements.txt +1 -0
- package/generator/test/generic_mock_api_tests/asynctests/test_streaming_jsonl_async.py +27 -0
- package/generator/test/generic_mock_api_tests/test_streaming_jsonl.py +25 -0
- package/generator/test/unbranded/requirements.txt +1 -0
- package/package.json +8 -2
|
@@ -13,7 +13,7 @@ from .. import Plugin
|
|
|
13
13
|
from ..utils import parse_args
|
|
14
14
|
from .models.code_model import CodeModel
|
|
15
15
|
from .serializers import JinjaSerializer
|
|
16
|
-
from ._utils import
|
|
16
|
+
from ._utils import VALID_PACKAGE_MODE, TYPESPEC_PACKAGE_MODE
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def _default_pprint(package_name: str) -> str:
|
|
@@ -53,24 +53,6 @@ class OptionsRetriever:
|
|
|
53
53
|
key = prop.replace("_", "-")
|
|
54
54
|
return self.options.get(key, self.OPTIONS_TO_DEFAULT.get(key))
|
|
55
55
|
|
|
56
|
-
@property
|
|
57
|
-
def company_name(self) -> str:
|
|
58
|
-
return self.options.get("company-name", "Microsoft" if self.is_azure_flavor else "")
|
|
59
|
-
|
|
60
|
-
@property
|
|
61
|
-
def license_header(self) -> str:
|
|
62
|
-
license_header = self.options.get(
|
|
63
|
-
"header-text",
|
|
64
|
-
(DEFAULT_HEADER_TEXT.format(company_name=self.company_name) if self.company_name else ""),
|
|
65
|
-
)
|
|
66
|
-
if license_header:
|
|
67
|
-
license_header = license_header.replace("\n", "\n# ")
|
|
68
|
-
license_header = (
|
|
69
|
-
"# --------------------------------------------------------------------------\n# " + license_header
|
|
70
|
-
)
|
|
71
|
-
license_header += "\n# --------------------------------------------------------------------------"
|
|
72
|
-
return license_header
|
|
73
|
-
|
|
74
56
|
@property
|
|
75
57
|
def show_operations(self) -> bool:
|
|
76
58
|
return self.options.get("show-operations", not self.low_level_client)
|
|
@@ -168,6 +150,11 @@ class OptionsRetriever:
|
|
|
168
150
|
def package_version(self) -> Optional[str]:
|
|
169
151
|
return str(self.options.get("package-version", ""))
|
|
170
152
|
|
|
153
|
+
|
|
154
|
+
@property
|
|
155
|
+
def header_text(self) -> Optional[str]:
|
|
156
|
+
return self.options.get("header-text")
|
|
157
|
+
|
|
171
158
|
|
|
172
159
|
class CodeGenerator(Plugin):
|
|
173
160
|
def __init__(self, *args, **kwargs: Any) -> None:
|
|
@@ -286,7 +273,7 @@ class CodeGenerator(Plugin):
|
|
|
286
273
|
flags = [
|
|
287
274
|
"azure_arm",
|
|
288
275
|
"head_as_boolean",
|
|
289
|
-
"
|
|
276
|
+
"header_text",
|
|
290
277
|
"keep_version_file",
|
|
291
278
|
"no_async",
|
|
292
279
|
"no_namespace_folders",
|
|
@@ -314,7 +301,6 @@ class CodeGenerator(Plugin):
|
|
|
314
301
|
"default_api_version",
|
|
315
302
|
"from_typespec",
|
|
316
303
|
"flavor",
|
|
317
|
-
"company_name",
|
|
318
304
|
"emit_cross_language_definition_file",
|
|
319
305
|
]
|
|
320
306
|
return {f: getattr(self.options_retriever, f) for f in flags}
|
|
@@ -5,12 +5,36 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
|
|
7
7
|
DEFAULT_HEADER_TEXT = (
|
|
8
|
-
"Copyright (c)
|
|
8
|
+
"Copyright (c) Microsoft Corporation. All rights reserved.\n"
|
|
9
9
|
"Licensed under the MIT License. See License.txt in the project root for license information.\n"
|
|
10
|
-
"Code generated by
|
|
10
|
+
"Code generated by Microsoft (R) Python Code Generator.\n"
|
|
11
11
|
"Changes may cause incorrect behavior and will be lost if the code is regenerated."
|
|
12
12
|
)
|
|
13
13
|
|
|
14
|
+
DEFAULT_LICENSE_DESCRIPTION = (
|
|
15
|
+
"Copyright (c) Microsoft Corporation.\n"
|
|
16
|
+
"\n"
|
|
17
|
+
"MIT License\n"
|
|
18
|
+
"\n"
|
|
19
|
+
"Permission is hereby granted, free of charge, to any person obtaining a copy\n"
|
|
20
|
+
"of this software and associated documentation files (the \"Software\"), to deal\n"
|
|
21
|
+
"in the Software without restriction, including without limitation the rights\n"
|
|
22
|
+
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"
|
|
23
|
+
"copies of the Software, and to permit persons to whom the Software is\n"
|
|
24
|
+
"furnished to do so, subject to the following conditions:\n"
|
|
25
|
+
"\n"
|
|
26
|
+
"The above copyright notice and this permission notice shall be included in all\n"
|
|
27
|
+
"copies or substantial portions of the Software.\n"
|
|
28
|
+
"\n"
|
|
29
|
+
"THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
|
|
30
|
+
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
|
|
31
|
+
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"
|
|
32
|
+
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"
|
|
33
|
+
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"
|
|
34
|
+
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n"
|
|
35
|
+
"SOFTWARE."
|
|
36
|
+
)
|
|
37
|
+
|
|
14
38
|
SWAGGER_PACKAGE_MODE = ["mgmtplane", "dataplane"] # for backward compatibility
|
|
15
39
|
TYPESPEC_PACKAGE_MODE = ["azure-mgmt", "azure-dataplane", "generic"]
|
|
16
40
|
VALID_PACKAGE_MODE = SWAGGER_PACKAGE_MODE + TYPESPEC_PACKAGE_MODE
|
|
@@ -13,6 +13,7 @@ from .client import Client
|
|
|
13
13
|
from .request_builder import RequestBuilder, OverloadedRequestBuilder
|
|
14
14
|
from .operation_group import OperationGroup
|
|
15
15
|
from .utils import NamespaceType
|
|
16
|
+
from .._utils import DEFAULT_HEADER_TEXT, DEFAULT_LICENSE_DESCRIPTION
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
def _is_legacy(options) -> bool:
|
|
@@ -406,3 +407,35 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
406
407
|
@property
|
|
407
408
|
def is_tsp(self) -> bool:
|
|
408
409
|
return self.options.get("tsp_file") is not None
|
|
410
|
+
|
|
411
|
+
@property
|
|
412
|
+
def license_header(self) -> str:
|
|
413
|
+
if self.yaml_data.get("licenseInfo") or not self.is_azure_flavor:
|
|
414
|
+
# typespec unbranded case and azure case with custom license
|
|
415
|
+
license_header = self.yaml_data.get("licenseInfo", {}).get("header", "")
|
|
416
|
+
else:
|
|
417
|
+
# typespec azure case without custom license and swagger case
|
|
418
|
+
license_header = self.options.get("header_text", DEFAULT_HEADER_TEXT)
|
|
419
|
+
if license_header:
|
|
420
|
+
license_header = license_header.replace("\n", "\n# ")
|
|
421
|
+
license_header = (
|
|
422
|
+
"# --------------------------------------------------------------------------\n# " + license_header
|
|
423
|
+
)
|
|
424
|
+
license_header += "\n# --------------------------------------------------------------------------"
|
|
425
|
+
return license_header
|
|
426
|
+
|
|
427
|
+
@property
|
|
428
|
+
def license_description(self) -> str:
|
|
429
|
+
if self.yaml_data.get("licenseInfo") or not self.is_azure_flavor:
|
|
430
|
+
# typespec unbranded case and azure case with custom license
|
|
431
|
+
return self.yaml_data.get("licenseInfo", {}).get("description", "")
|
|
432
|
+
# typespec azure case without custom license and swagger case
|
|
433
|
+
return DEFAULT_LICENSE_DESCRIPTION
|
|
434
|
+
|
|
435
|
+
@property
|
|
436
|
+
def company_name(self) -> str:
|
|
437
|
+
if self.yaml_data.get("licenseInfo") or not self.is_azure_flavor:
|
|
438
|
+
# typespec unbranded case and azure case with custom license
|
|
439
|
+
return self.yaml_data.get("licenseInfo", {}).get("company", "")
|
|
440
|
+
# typespec azure case without custom license and swagger case
|
|
441
|
+
return "Microsoft Corporation"
|
|
@@ -202,6 +202,8 @@ class JinjaSerializer(ReaderAndWriter):
|
|
|
202
202
|
)
|
|
203
203
|
|
|
204
204
|
package_files = _PACKAGE_FILES
|
|
205
|
+
if not self.code_model.license_description:
|
|
206
|
+
package_files.remove("LICENSE.jinja2")
|
|
205
207
|
elif Path(self.code_model.options["package_mode"]).exists():
|
|
206
208
|
env = Environment(
|
|
207
209
|
loader=FileSystemLoader(str(Path(self.code_model.options["package_mode"]))),
|
|
@@ -273,7 +275,7 @@ class JinjaSerializer(ReaderAndWriter):
|
|
|
273
275
|
if not "" in group_names:
|
|
274
276
|
self.write_file(
|
|
275
277
|
rest_path / Path("__init__.py"),
|
|
276
|
-
self.code_model.
|
|
278
|
+
self.code_model.license_header,
|
|
277
279
|
)
|
|
278
280
|
|
|
279
281
|
def _serialize_and_write_single_rest_layer(
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{% import 'operation_tools.jinja2' as op_tools %}
|
|
2
2
|
# coding=utf-8
|
|
3
|
-
{
|
|
3
|
+
{% if code_model.license_header %}
|
|
4
|
+
{{ code_model.license_header }}
|
|
5
|
+
{% endif %}
|
|
4
6
|
|
|
5
7
|
from enum import Enum
|
|
6
8
|
from {{ code_model.core_library }}{{ "" if code_model.is_azure_flavor else ".utils" }} import CaseInsensitiveEnumMeta
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{% import 'keywords.jinja2' as keywords %}
|
|
2
2
|
# coding=utf-8
|
|
3
|
-
{
|
|
3
|
+
{% if code_model.license_header %}
|
|
4
|
+
{{ code_model.license_header }}
|
|
5
|
+
{% endif %}
|
|
4
6
|
{{ keywords.path_type_checking_imports() }}
|
|
5
7
|
{% if clients %}
|
|
6
8
|
{% for client in clients %}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# license information.
|
|
6
|
-
# --------------------------------------------------------------------------
|
|
2
|
+
{% if code_model.license_header %}
|
|
3
|
+
{{ code_model.license_header }}
|
|
4
|
+
{% endif %}
|
|
7
5
|
# pylint: disable=protected-access, broad-except
|
|
8
6
|
|
|
9
7
|
import copy
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{% import 'operation_tools.jinja2' as op_tools %}
|
|
2
2
|
# coding=utf-8
|
|
3
|
-
{
|
|
3
|
+
{% if code_model.license_header %}
|
|
4
|
+
{{ code_model.license_header }}
|
|
5
|
+
{% endif %}
|
|
4
6
|
{% if serializer.global_pylint_disables() %}
|
|
5
7
|
{{ serializer.global_pylint_disables() }}
|
|
6
8
|
{% endif %}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
{% set operations_description = "async operations" if async_mode else "operations" %}
|
|
3
3
|
{% set return_none_type_annotation = " -> None" if async_mode else "" %}
|
|
4
4
|
# coding=utf-8
|
|
5
|
-
{
|
|
5
|
+
{% if code_model.license_header %}
|
|
6
|
+
{{ code_model.license_header }}
|
|
7
|
+
{% endif %}
|
|
6
8
|
{{ imports }}
|
|
7
9
|
{{ unset }}
|
|
8
10
|
{% if code_model.options["builders_visibility"] == "embedded" and not async_mode %}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
{% import 'keywords.jinja2' as keywords %}
|
|
3
3
|
{# actual template starts here #}
|
|
4
4
|
# coding=utf-8
|
|
5
|
-
{
|
|
5
|
+
{% if code_model.license_header %}
|
|
6
|
+
{{ code_model.license_header }}
|
|
7
|
+
{% endif %}
|
|
6
8
|
{{ keywords.path_type_checking_imports() }}
|
|
7
9
|
{{ op_tools.serialize(operation_group_imports()) }}
|
|
8
10
|
{{ keywords.patch_imports() }}
|
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
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.
|
|
1
|
+
{{ code_model.license_description }}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
|
-
{
|
|
3
|
-
|
|
2
|
+
{% if code_model.license_header %}
|
|
3
|
+
{{ code_model.license_header }}
|
|
4
|
+
{% endif %}
|
|
5
|
+
|
|
4
6
|
{% if package_mode %}
|
|
5
7
|
|
|
6
8
|
import os
|
|
@@ -32,7 +34,7 @@ with open(os.path.join(package_folder_path, "_version.py"), "r") as fd:
|
|
|
32
34
|
|
|
33
35
|
if not version:
|
|
34
36
|
raise RuntimeError("Cannot find version information")
|
|
35
|
-
{% set description = "\"" + code_model.
|
|
37
|
+
{% set description = "\"" + code_model.company_name + " {} Client Library for Python\".format(PACKAGE_PPRINT_NAME)" %}
|
|
36
38
|
{% set author_email = "azpysdkhelp@microsoft.com" %}
|
|
37
39
|
{% set url = "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk" %}
|
|
38
40
|
{% else %}
|
|
@@ -52,7 +54,7 @@ setup(
|
|
|
52
54
|
long_description=open("README.md", "r").read(),
|
|
53
55
|
long_description_content_type="text/markdown",
|
|
54
56
|
license="MIT License",
|
|
55
|
-
author="{{ code_model.
|
|
57
|
+
author="{{ code_model.company_name }}",
|
|
56
58
|
{% endif %}
|
|
57
59
|
{% if code_model.is_azure_flavor %}
|
|
58
60
|
author_email="{{ author_email }}",
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
{% if not code_model.is_azure_flavor %}
|
|
3
|
+
{{ code_model.license_header }}
|
|
4
|
+
{% else %}
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
8
|
+
# --------------------------------------------------------------------------
|
|
9
|
+
{% endif %}
|
|
5
10
|
"""Customize generated code here.
|
|
6
11
|
|
|
7
12
|
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
2
|
{% set aad_token = "DefaultAzureCredential" %}
|
|
3
3
|
{% set azure_key = "AzureKeyCredential" %}
|
|
4
|
-
{
|
|
4
|
+
{% if code_model.license_header %}
|
|
5
|
+
{{ code_model.license_header }}
|
|
6
|
+
{% endif %}
|
|
5
7
|
|
|
6
8
|
{{ imports }}
|
|
7
9
|
"""
|
|
@@ -1,28 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# The MIT License (MIT)
|
|
6
|
-
#
|
|
7
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
# of this software and associated documentation files (the ""Software""), to
|
|
9
|
-
# deal in the Software without restriction, including without limitation the
|
|
10
|
-
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
11
|
-
# sell copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
# furnished to do so, subject to the following conditions:
|
|
13
|
-
#
|
|
14
|
-
# The above copyright notice and this permission notice shall be included in
|
|
15
|
-
# all copies or substantial portions of the Software.
|
|
16
|
-
#
|
|
17
|
-
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
22
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
23
|
-
# IN THE SOFTWARE.
|
|
24
|
-
#
|
|
25
|
-
# --------------------------------------------------------------------------
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
{% if code_model.license_header %}
|
|
3
|
+
{{ code_model.license_header }}
|
|
4
|
+
{% endif %}
|
|
26
5
|
|
|
27
6
|
# pyright: reportUnnecessaryTypeIgnoreComment=false
|
|
28
7
|
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
{% set async = "async " if test.async_mode else "" %}
|
|
4
4
|
{% set async_suffix = "_async" if test.async_mode else "" %}
|
|
5
5
|
# coding=utf-8
|
|
6
|
-
{
|
|
6
|
+
{% if code_model.license_header %}
|
|
7
|
+
{{ code_model.license_header }}
|
|
8
|
+
{% endif %}
|
|
7
9
|
import pytest
|
|
8
10
|
{{ imports }}
|
|
9
11
|
|
|
Binary file
|
|
@@ -13,7 +13,7 @@ from .. import Plugin
|
|
|
13
13
|
from ..utils import parse_args
|
|
14
14
|
from .models.code_model import CodeModel
|
|
15
15
|
from .serializers import JinjaSerializer
|
|
16
|
-
from ._utils import
|
|
16
|
+
from ._utils import VALID_PACKAGE_MODE, TYPESPEC_PACKAGE_MODE
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def _default_pprint(package_name: str) -> str:
|
|
@@ -53,24 +53,6 @@ class OptionsRetriever:
|
|
|
53
53
|
key = prop.replace("_", "-")
|
|
54
54
|
return self.options.get(key, self.OPTIONS_TO_DEFAULT.get(key))
|
|
55
55
|
|
|
56
|
-
@property
|
|
57
|
-
def company_name(self) -> str:
|
|
58
|
-
return self.options.get("company-name", "Microsoft" if self.is_azure_flavor else "")
|
|
59
|
-
|
|
60
|
-
@property
|
|
61
|
-
def license_header(self) -> str:
|
|
62
|
-
license_header = self.options.get(
|
|
63
|
-
"header-text",
|
|
64
|
-
(DEFAULT_HEADER_TEXT.format(company_name=self.company_name) if self.company_name else ""),
|
|
65
|
-
)
|
|
66
|
-
if license_header:
|
|
67
|
-
license_header = license_header.replace("\n", "\n# ")
|
|
68
|
-
license_header = (
|
|
69
|
-
"# --------------------------------------------------------------------------\n# " + license_header
|
|
70
|
-
)
|
|
71
|
-
license_header += "\n# --------------------------------------------------------------------------"
|
|
72
|
-
return license_header
|
|
73
|
-
|
|
74
56
|
@property
|
|
75
57
|
def show_operations(self) -> bool:
|
|
76
58
|
return self.options.get("show-operations", not self.low_level_client)
|
|
@@ -168,6 +150,11 @@ class OptionsRetriever:
|
|
|
168
150
|
def package_version(self) -> Optional[str]:
|
|
169
151
|
return str(self.options.get("package-version", ""))
|
|
170
152
|
|
|
153
|
+
|
|
154
|
+
@property
|
|
155
|
+
def header_text(self) -> Optional[str]:
|
|
156
|
+
return self.options.get("header-text")
|
|
157
|
+
|
|
171
158
|
|
|
172
159
|
class CodeGenerator(Plugin):
|
|
173
160
|
def __init__(self, *args, **kwargs: Any) -> None:
|
|
@@ -286,7 +273,7 @@ class CodeGenerator(Plugin):
|
|
|
286
273
|
flags = [
|
|
287
274
|
"azure_arm",
|
|
288
275
|
"head_as_boolean",
|
|
289
|
-
"
|
|
276
|
+
"header_text",
|
|
290
277
|
"keep_version_file",
|
|
291
278
|
"no_async",
|
|
292
279
|
"no_namespace_folders",
|
|
@@ -314,7 +301,6 @@ class CodeGenerator(Plugin):
|
|
|
314
301
|
"default_api_version",
|
|
315
302
|
"from_typespec",
|
|
316
303
|
"flavor",
|
|
317
|
-
"company_name",
|
|
318
304
|
"emit_cross_language_definition_file",
|
|
319
305
|
]
|
|
320
306
|
return {f: getattr(self.options_retriever, f) for f in flags}
|
|
@@ -5,12 +5,36 @@
|
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
|
|
7
7
|
DEFAULT_HEADER_TEXT = (
|
|
8
|
-
"Copyright (c)
|
|
8
|
+
"Copyright (c) Microsoft Corporation. All rights reserved.\n"
|
|
9
9
|
"Licensed under the MIT License. See License.txt in the project root for license information.\n"
|
|
10
|
-
"Code generated by
|
|
10
|
+
"Code generated by Microsoft (R) Python Code Generator.\n"
|
|
11
11
|
"Changes may cause incorrect behavior and will be lost if the code is regenerated."
|
|
12
12
|
)
|
|
13
13
|
|
|
14
|
+
DEFAULT_LICENSE_DESCRIPTION = (
|
|
15
|
+
"Copyright (c) Microsoft Corporation.\n"
|
|
16
|
+
"\n"
|
|
17
|
+
"MIT License\n"
|
|
18
|
+
"\n"
|
|
19
|
+
"Permission is hereby granted, free of charge, to any person obtaining a copy\n"
|
|
20
|
+
"of this software and associated documentation files (the \"Software\"), to deal\n"
|
|
21
|
+
"in the Software without restriction, including without limitation the rights\n"
|
|
22
|
+
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"
|
|
23
|
+
"copies of the Software, and to permit persons to whom the Software is\n"
|
|
24
|
+
"furnished to do so, subject to the following conditions:\n"
|
|
25
|
+
"\n"
|
|
26
|
+
"The above copyright notice and this permission notice shall be included in all\n"
|
|
27
|
+
"copies or substantial portions of the Software.\n"
|
|
28
|
+
"\n"
|
|
29
|
+
"THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
|
|
30
|
+
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
|
|
31
|
+
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"
|
|
32
|
+
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"
|
|
33
|
+
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"
|
|
34
|
+
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n"
|
|
35
|
+
"SOFTWARE."
|
|
36
|
+
)
|
|
37
|
+
|
|
14
38
|
SWAGGER_PACKAGE_MODE = ["mgmtplane", "dataplane"] # for backward compatibility
|
|
15
39
|
TYPESPEC_PACKAGE_MODE = ["azure-mgmt", "azure-dataplane", "generic"]
|
|
16
40
|
VALID_PACKAGE_MODE = SWAGGER_PACKAGE_MODE + TYPESPEC_PACKAGE_MODE
|
|
@@ -13,6 +13,7 @@ from .client import Client
|
|
|
13
13
|
from .request_builder import RequestBuilder, OverloadedRequestBuilder
|
|
14
14
|
from .operation_group import OperationGroup
|
|
15
15
|
from .utils import NamespaceType
|
|
16
|
+
from .._utils import DEFAULT_HEADER_TEXT, DEFAULT_LICENSE_DESCRIPTION
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
def _is_legacy(options) -> bool:
|
|
@@ -406,3 +407,35 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
406
407
|
@property
|
|
407
408
|
def is_tsp(self) -> bool:
|
|
408
409
|
return self.options.get("tsp_file") is not None
|
|
410
|
+
|
|
411
|
+
@property
|
|
412
|
+
def license_header(self) -> str:
|
|
413
|
+
if self.yaml_data.get("licenseInfo") or not self.is_azure_flavor:
|
|
414
|
+
# typespec unbranded case and azure case with custom license
|
|
415
|
+
license_header = self.yaml_data.get("licenseInfo", {}).get("header", "")
|
|
416
|
+
else:
|
|
417
|
+
# typespec azure case without custom license and swagger case
|
|
418
|
+
license_header = self.options.get("header_text", DEFAULT_HEADER_TEXT)
|
|
419
|
+
if license_header:
|
|
420
|
+
license_header = license_header.replace("\n", "\n# ")
|
|
421
|
+
license_header = (
|
|
422
|
+
"# --------------------------------------------------------------------------\n# " + license_header
|
|
423
|
+
)
|
|
424
|
+
license_header += "\n# --------------------------------------------------------------------------"
|
|
425
|
+
return license_header
|
|
426
|
+
|
|
427
|
+
@property
|
|
428
|
+
def license_description(self) -> str:
|
|
429
|
+
if self.yaml_data.get("licenseInfo") or not self.is_azure_flavor:
|
|
430
|
+
# typespec unbranded case and azure case with custom license
|
|
431
|
+
return self.yaml_data.get("licenseInfo", {}).get("description", "")
|
|
432
|
+
# typespec azure case without custom license and swagger case
|
|
433
|
+
return DEFAULT_LICENSE_DESCRIPTION
|
|
434
|
+
|
|
435
|
+
@property
|
|
436
|
+
def company_name(self) -> str:
|
|
437
|
+
if self.yaml_data.get("licenseInfo") or not self.is_azure_flavor:
|
|
438
|
+
# typespec unbranded case and azure case with custom license
|
|
439
|
+
return self.yaml_data.get("licenseInfo", {}).get("company", "")
|
|
440
|
+
# typespec azure case without custom license and swagger case
|
|
441
|
+
return "Microsoft Corporation"
|
|
@@ -202,6 +202,8 @@ class JinjaSerializer(ReaderAndWriter):
|
|
|
202
202
|
)
|
|
203
203
|
|
|
204
204
|
package_files = _PACKAGE_FILES
|
|
205
|
+
if not self.code_model.license_description:
|
|
206
|
+
package_files.remove("LICENSE.jinja2")
|
|
205
207
|
elif Path(self.code_model.options["package_mode"]).exists():
|
|
206
208
|
env = Environment(
|
|
207
209
|
loader=FileSystemLoader(str(Path(self.code_model.options["package_mode"]))),
|
|
@@ -273,7 +275,7 @@ class JinjaSerializer(ReaderAndWriter):
|
|
|
273
275
|
if not "" in group_names:
|
|
274
276
|
self.write_file(
|
|
275
277
|
rest_path / Path("__init__.py"),
|
|
276
|
-
self.code_model.
|
|
278
|
+
self.code_model.license_header,
|
|
277
279
|
)
|
|
278
280
|
|
|
279
281
|
def _serialize_and_write_single_rest_layer(
|