@typespec/http-client-python 0.4.4 → 0.5.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/dist/emitter/emitter.d.ts.map +1 -1
- package/dist/emitter/emitter.js +110 -24
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/http.js +1 -1
- package/dist/emitter/http.js.map +1 -1
- package/dist/emitter/lib.d.ts +1 -0
- package/dist/emitter/lib.d.ts.map +1 -1
- package/dist/emitter/lib.js +1 -0
- package/dist/emitter/lib.js.map +1 -1
- package/dist/emitter/run-python3.d.ts +2 -0
- package/dist/emitter/run-python3.d.ts.map +1 -0
- package/dist/emitter/run-python3.js +19 -0
- package/dist/emitter/run-python3.js.map +1 -0
- package/dist/emitter/system-requirements.d.ts +17 -0
- package/dist/emitter/system-requirements.d.ts.map +1 -0
- package/dist/emitter/system-requirements.js +167 -0
- package/dist/emitter/system-requirements.js.map +1 -0
- package/emitter/src/emitter.ts +111 -23
- package/emitter/src/http.ts +1 -1
- package/emitter/src/lib.ts +2 -0
- package/emitter/src/run-python3.ts +20 -0
- package/emitter/src/system-requirements.ts +261 -0
- package/emitter/temp/tsconfig.tsbuildinfo +1 -1
- package/eng/scripts/Test-Packages.ps1 +1 -1
- package/eng/scripts/ci/regenerate.ts +20 -8
- package/eng/scripts/setup/__pycache__/venvtools.cpython-38.pyc +0 -0
- package/eng/scripts/setup/build.ts +16 -0
- package/eng/scripts/setup/build_pygen_wheel.py +40 -0
- package/eng/scripts/setup/install.py +9 -8
- package/eng/scripts/setup/install.ts +12 -0
- package/eng/scripts/setup/prepare.py +3 -1
- package/eng/scripts/setup/prepare.ts +11 -0
- package/eng/scripts/setup/run-python3.ts +1 -6
- package/generator/build/lib/pygen/__init__.py +107 -0
- package/generator/build/lib/pygen/_version.py +7 -0
- package/generator/build/lib/pygen/black.py +71 -0
- package/generator/build/lib/pygen/codegen/__init__.py +357 -0
- package/generator/build/lib/pygen/codegen/_utils.py +17 -0
- package/generator/build/lib/pygen/codegen/models/__init__.py +204 -0
- package/generator/build/lib/pygen/codegen/models/base.py +186 -0
- package/generator/build/lib/pygen/codegen/models/base_builder.py +118 -0
- package/generator/build/lib/pygen/codegen/models/client.py +435 -0
- package/generator/build/lib/pygen/codegen/models/code_model.py +237 -0
- package/generator/build/lib/pygen/codegen/models/combined_type.py +149 -0
- package/generator/build/lib/pygen/codegen/models/constant_type.py +129 -0
- package/generator/build/lib/pygen/codegen/models/credential_types.py +214 -0
- package/generator/build/lib/pygen/codegen/models/dictionary_type.py +127 -0
- package/generator/build/lib/pygen/codegen/models/enum_type.py +238 -0
- package/generator/build/lib/pygen/codegen/models/imports.py +291 -0
- package/generator/build/lib/pygen/codegen/models/list_type.py +143 -0
- package/generator/build/lib/pygen/codegen/models/lro_operation.py +142 -0
- package/generator/build/lib/pygen/codegen/models/lro_paging_operation.py +32 -0
- package/generator/build/lib/pygen/codegen/models/model_type.py +357 -0
- package/generator/build/lib/pygen/codegen/models/operation.py +509 -0
- package/generator/build/lib/pygen/codegen/models/operation_group.py +184 -0
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +155 -0
- package/generator/build/lib/pygen/codegen/models/parameter.py +412 -0
- package/generator/build/lib/pygen/codegen/models/parameter_list.py +387 -0
- package/generator/build/lib/pygen/codegen/models/primitive_types.py +659 -0
- package/generator/build/lib/pygen/codegen/models/property.py +170 -0
- package/generator/build/lib/pygen/codegen/models/request_builder.py +189 -0
- package/generator/build/lib/pygen/codegen/models/request_builder_parameter.py +115 -0
- package/generator/build/lib/pygen/codegen/models/response.py +348 -0
- package/generator/build/lib/pygen/codegen/models/utils.py +21 -0
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +574 -0
- package/generator/build/lib/pygen/codegen/serializers/base_serializer.py +21 -0
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +1533 -0
- package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +294 -0
- package/generator/build/lib/pygen/codegen/serializers/enum_serializer.py +15 -0
- package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +213 -0
- package/generator/build/lib/pygen/codegen/serializers/import_serializer.py +126 -0
- package/generator/build/lib/pygen/codegen/serializers/metadata_serializer.py +198 -0
- package/generator/build/lib/pygen/codegen/serializers/model_init_serializer.py +33 -0
- package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +335 -0
- package/generator/build/lib/pygen/codegen/serializers/operation_groups_serializer.py +89 -0
- package/generator/build/lib/pygen/codegen/serializers/operations_init_serializer.py +44 -0
- package/generator/build/lib/pygen/codegen/serializers/parameter_serializer.py +221 -0
- package/generator/build/lib/pygen/codegen/serializers/patch_serializer.py +19 -0
- package/generator/build/lib/pygen/codegen/serializers/request_builders_serializer.py +52 -0
- package/generator/build/lib/pygen/codegen/serializers/sample_serializer.py +168 -0
- package/generator/build/lib/pygen/codegen/serializers/test_serializer.py +292 -0
- package/generator/build/lib/pygen/codegen/serializers/types_serializer.py +31 -0
- package/generator/build/lib/pygen/codegen/serializers/utils.py +68 -0
- package/generator/build/lib/pygen/codegen/templates/client.py.jinja2 +37 -0
- package/generator/build/lib/pygen/codegen/templates/client_container.py.jinja2 +12 -0
- package/generator/build/lib/pygen/codegen/templates/config.py.jinja2 +73 -0
- package/generator/build/lib/pygen/codegen/templates/config_container.py.jinja2 +16 -0
- package/generator/build/lib/pygen/codegen/templates/conftest.py.jinja2 +28 -0
- package/generator/build/lib/pygen/codegen/templates/enum.py.jinja2 +13 -0
- package/generator/build/lib/pygen/codegen/templates/enum_container.py.jinja2 +10 -0
- package/generator/build/lib/pygen/codegen/templates/init.py.jinja2 +24 -0
- package/generator/build/lib/pygen/codegen/templates/keywords.jinja2 +27 -0
- package/generator/build/lib/pygen/codegen/templates/lro_operation.py.jinja2 +16 -0
- package/generator/build/lib/pygen/codegen/templates/lro_paging_operation.py.jinja2 +18 -0
- package/generator/build/lib/pygen/codegen/templates/macros.jinja2 +12 -0
- package/generator/build/lib/pygen/codegen/templates/metadata.json.jinja2 +167 -0
- package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +1174 -0
- package/generator/build/lib/pygen/codegen/templates/model_container.py.jinja2 +15 -0
- package/generator/build/lib/pygen/codegen/templates/model_dpg.py.jinja2 +97 -0
- package/generator/build/lib/pygen/codegen/templates/model_init.py.jinja2 +33 -0
- package/generator/build/lib/pygen/codegen/templates/model_msrest.py.jinja2 +92 -0
- package/generator/build/lib/pygen/codegen/templates/operation.py.jinja2 +21 -0
- package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +75 -0
- package/generator/build/lib/pygen/codegen/templates/operation_groups_container.py.jinja2 +19 -0
- package/generator/build/lib/pygen/codegen/templates/operation_tools.jinja2 +81 -0
- package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +17 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/CHANGELOG.md.jinja2 +6 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/LICENSE.jinja2 +21 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +8 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/README.md.jinja2 +107 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +9 -0
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +108 -0
- package/generator/build/lib/pygen/codegen/templates/paging_operation.py.jinja2 +21 -0
- package/generator/build/lib/pygen/codegen/templates/patch.py.jinja2 +19 -0
- package/generator/build/lib/pygen/codegen/templates/pkgutil_init.py.jinja2 +1 -0
- package/generator/build/lib/pygen/codegen/templates/request_builder.py.jinja2 +28 -0
- package/generator/build/lib/pygen/codegen/templates/request_builders.py.jinja2 +10 -0
- package/generator/build/lib/pygen/codegen/templates/rest_init.py.jinja2 +12 -0
- package/generator/build/lib/pygen/codegen/templates/sample.py.jinja2 +44 -0
- package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +2117 -0
- package/generator/build/lib/pygen/codegen/templates/test.py.jinja2 +50 -0
- package/generator/build/lib/pygen/codegen/templates/testpreparer.py.jinja2 +26 -0
- package/generator/build/lib/pygen/codegen/templates/types.py.jinja2 +7 -0
- package/generator/build/lib/pygen/codegen/templates/validation.py.jinja2 +38 -0
- package/generator/build/lib/pygen/codegen/templates/vendor.py.jinja2 +96 -0
- package/generator/build/lib/pygen/codegen/templates/version.py.jinja2 +4 -0
- package/generator/build/lib/pygen/m2r.py +65 -0
- package/generator/build/lib/pygen/preprocess/__init__.py +515 -0
- package/generator/build/lib/pygen/preprocess/helpers.py +27 -0
- package/generator/build/lib/pygen/preprocess/python_mappings.py +226 -0
- package/generator/build/lib/pygen/utils.py +163 -0
- package/generator/component-detection-pip-report.json +134 -0
- package/generator/dev_requirements.txt +0 -1
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/__init__.py +4 -4
- package/generator/pygen.egg-info/PKG-INFO +7 -4
- package/generator/pygen.egg-info/requires.txt +7 -4
- package/generator/setup.py +7 -4
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_flatten_async.py +1 -1
- package/generator/test/{generic_mock_api_tests/asynctests/test_payload_pageable_async.py → azure/mock_api_tests/asynctests/test_azure_payload_pageable_async.py} +1 -1
- package/generator/test/azure/mock_api_tests/conftest.py +5 -4
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_flatten.py +1 -1
- package/generator/test/{generic_mock_api_tests/test_payload_pageable.py → azure/mock_api_tests/test_azure_payload_pageable.py} +1 -1
- package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_resiliency_srv_driven.py +4 -2
- package/generator/test/{generic_mock_api_tests/asynctests → azure/mock_api_tests}/test_resiliency_srv_driven_async.py +3 -2
- package/generator/test/azure/requirements.txt +9 -8
- package/generator/test/generic_mock_api_tests/conftest.py +9 -4
- package/generator/test/unbranded/mock_api_tests/conftest.py +4 -4
- package/generator/test/unbranded/mock_api_tests/test_unbranded.py +1 -1
- package/generator/test/unbranded/requirements.txt +1 -8
- package/package.json +10 -10
- package/generator/requirements.txt +0 -12
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_client_naming_async.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/asynctests/test_client_structure_async.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_client_naming.py +0 -0
- /package/generator/test/{generic_mock_api_tests → azure/mock_api_tests}/test_client_structure.py +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{% import 'operation_tools.jinja2' as op_tools %}
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
{{ code_model.options['license_header'] }}
|
|
4
|
+
{% if serializer.global_pylint_disables() %}
|
|
5
|
+
{{ serializer.global_pylint_disables() }}
|
|
6
|
+
{% endif %}
|
|
7
|
+
|
|
8
|
+
{{ imports }}
|
|
9
|
+
{% for model in code_model.model_types %}
|
|
10
|
+
{% if model.base == "dpg" %}
|
|
11
|
+
{% include "model_dpg.py.jinja2" %}
|
|
12
|
+
{% elif model.base == "msrest" %}
|
|
13
|
+
{% include "model_msrest.py.jinja2" %}
|
|
14
|
+
{% endif %}
|
|
15
|
+
{% endfor %}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{# actual template starts here #}
|
|
2
|
+
{% import "macros.jinja2" as macros %}
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
{{ serializer.declare_model(model) }}
|
|
6
|
+
"""{{ op_tools.wrap_string(model.description(is_operation_file=False), "\n ") }}
|
|
7
|
+
{% if model.discriminated_subtypes %}
|
|
8
|
+
|
|
9
|
+
{{ serializer.discriminator_docstring(model) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
|
|
10
|
+
{% endif %}
|
|
11
|
+
{% if model.has_readonly_or_constant_property %}
|
|
12
|
+
|
|
13
|
+
Readonly variables are only populated by the server, and will be ignored when sending a request.
|
|
14
|
+
{% endif %}
|
|
15
|
+
{% if (model.properties | selectattr('optional', "equalto", false) | first) is defined %}
|
|
16
|
+
|
|
17
|
+
{% if not model.is_usage_output %}
|
|
18
|
+
All required parameters must be populated in order to send to server.
|
|
19
|
+
{% endif %}
|
|
20
|
+
{% endif %}
|
|
21
|
+
|
|
22
|
+
{% if model.properties != None %}
|
|
23
|
+
{% for p in model.properties %}
|
|
24
|
+
{% for line in serializer.variable_documentation_string(p) %}
|
|
25
|
+
{% for doc_string in line.replace('\n', '\n ').split('\n') %}
|
|
26
|
+
{{ macros.wrap_model_string(doc_string, '\n ') -}}
|
|
27
|
+
{% endfor %}
|
|
28
|
+
{% endfor %}
|
|
29
|
+
{% endfor %}
|
|
30
|
+
{% endif %}
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
{% if model.is_polymorphic %}
|
|
34
|
+
__mapping__: Dict[str, _model_base.Model] = {}
|
|
35
|
+
{% endif %}
|
|
36
|
+
{% for p in serializer.get_properties_to_declare(model)%}
|
|
37
|
+
{{ serializer.declare_property(p) }}
|
|
38
|
+
{% set prop_description = p.description(is_operation_file=False).replace('"', '\\"') %}
|
|
39
|
+
{% if prop_description %}
|
|
40
|
+
"""{{ macros.wrap_model_string(prop_description, '\n ', '\"\"\"') -}}
|
|
41
|
+
{% endif %}
|
|
42
|
+
{% endfor %}
|
|
43
|
+
|
|
44
|
+
{% if code_model.options["models_mode"] == "dpg" and model.flattened_property %}
|
|
45
|
+
__flattened_items = ["{{ model.flattened_items|join('\", \"') }}"]
|
|
46
|
+
{% endif %}
|
|
47
|
+
|
|
48
|
+
{% if model.xml_metadata %}
|
|
49
|
+
_xml = {{model.xml_metadata}}
|
|
50
|
+
{% endif %}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
{% if serializer.need_init(model) %}
|
|
54
|
+
@overload
|
|
55
|
+
def __init__({{ model.init_pylint_disable }}
|
|
56
|
+
self,
|
|
57
|
+
{% for param_signature in serializer.init_line(model) %}
|
|
58
|
+
{{ param_signature }}
|
|
59
|
+
{% endfor %}
|
|
60
|
+
) -> None:
|
|
61
|
+
...
|
|
62
|
+
|
|
63
|
+
@overload
|
|
64
|
+
def __init__(self, mapping: Mapping[str, Any]) -> None:
|
|
65
|
+
"""
|
|
66
|
+
:param mapping: raw JSON to initialize the model.
|
|
67
|
+
:type mapping: Mapping[str, Any]
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
{% endif %}
|
|
71
|
+
{% set initialize_properties = serializer.initialize_properties(model) %}
|
|
72
|
+
{% if serializer.need_init(model) or initialize_properties %}
|
|
73
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
74
|
+
{% for line in serializer.super_call(model) %}
|
|
75
|
+
{{ line }}
|
|
76
|
+
{% endfor %}
|
|
77
|
+
{% for initialize_property in initialize_properties %}
|
|
78
|
+
{{ initialize_property }}
|
|
79
|
+
{% endfor %}
|
|
80
|
+
{% if code_model.options["models_mode"] == "dpg" and model.flattened_property %}
|
|
81
|
+
{% set flattened_property_attr = model.flattened_property.client_name %}
|
|
82
|
+
|
|
83
|
+
def __getattr__(self, name: str) -> Any:
|
|
84
|
+
if name in self.__flattened_items:
|
|
85
|
+
if self.{{ flattened_property_attr }} is None: return None
|
|
86
|
+
return getattr(self.{{ flattened_property_attr }}, name)
|
|
87
|
+
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
|
|
88
|
+
|
|
89
|
+
def __setattr__(self, key: str, value: Any) -> None:
|
|
90
|
+
if key in self.__flattened_items:
|
|
91
|
+
if self.{{ flattened_property_attr }} is None:
|
|
92
|
+
self.{{ flattened_property_attr }} = self._attr_to_rest_field["{{ flattened_property_attr }}"]._class_type()
|
|
93
|
+
setattr(self.properties, key, value)
|
|
94
|
+
else:
|
|
95
|
+
super().__setattr__(key, value)
|
|
96
|
+
{% endif %}
|
|
97
|
+
{% endif %}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{% import 'keywords.jinja2' as keywords %}
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
{{ code_model.options['license_header'] }}
|
|
4
|
+
{{ keywords.path_type_checking_imports() }}
|
|
5
|
+
{% if schemas %}
|
|
6
|
+
|
|
7
|
+
from .{{ code_model.models_filename }} import ( # type: ignore
|
|
8
|
+
{% for schema in schemas %}
|
|
9
|
+
{{ schema }},
|
|
10
|
+
{% endfor %}
|
|
11
|
+
)
|
|
12
|
+
{% endif %}
|
|
13
|
+
{% if enums %}
|
|
14
|
+
|
|
15
|
+
from .{{ code_model.enums_filename }} import ( # type: ignore
|
|
16
|
+
{% for enum in enums %}
|
|
17
|
+
{{ enum }},
|
|
18
|
+
{% endfor %}
|
|
19
|
+
)
|
|
20
|
+
{% endif %}
|
|
21
|
+
{{ keywords.patch_imports() }}
|
|
22
|
+
__all__ = [
|
|
23
|
+
{% for schema in schemas %}
|
|
24
|
+
'{{ schema }}',
|
|
25
|
+
{% endfor %}
|
|
26
|
+
{% if enums %}
|
|
27
|
+
{% for enum in enums %}
|
|
28
|
+
'{{ enum }}',
|
|
29
|
+
{% endfor %}
|
|
30
|
+
{% endif %}
|
|
31
|
+
]
|
|
32
|
+
{{ keywords.extend_all }}
|
|
33
|
+
_patch_sdk()
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{# actual template starts here #}
|
|
2
|
+
{% import "macros.jinja2" as macros %}
|
|
3
|
+
{% set initialize_properties = serializer.initialize_properties(model) %}
|
|
4
|
+
{% set exist_constant = (model.properties | selectattr('constant') | first) is defined %}
|
|
5
|
+
|
|
6
|
+
{{ serializer.declare_model(model) }}
|
|
7
|
+
"""{{ op_tools.wrap_string(model.description(is_operation_file=False), "\n ") }}
|
|
8
|
+
{% if model.discriminated_subtypes %}
|
|
9
|
+
|
|
10
|
+
{{ serializer.discriminator_docstring(model) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
|
|
11
|
+
{% endif %}
|
|
12
|
+
{% if model.has_readonly_or_constant_property %}
|
|
13
|
+
|
|
14
|
+
Variables are only populated by the server, and will be ignored when sending a request.
|
|
15
|
+
{% endif %}
|
|
16
|
+
{% if (model.properties | selectattr('optional', "equalto", false) | first) is defined %}
|
|
17
|
+
|
|
18
|
+
All required parameters must be populated in order to send to server.
|
|
19
|
+
{% endif %}
|
|
20
|
+
|
|
21
|
+
{% if model.properties != None %}
|
|
22
|
+
{% for p in model.properties %}
|
|
23
|
+
{% for line in serializer.variable_documentation_string(p) %}
|
|
24
|
+
{% for doc_string in line.replace('\n', '\n ').split('\n') %}
|
|
25
|
+
{{ macros.wrap_model_string(doc_string, '\n ') -}}
|
|
26
|
+
{% endfor %}
|
|
27
|
+
{% endfor %}
|
|
28
|
+
{% endfor %}
|
|
29
|
+
{% endif %}
|
|
30
|
+
"""
|
|
31
|
+
{% if initialize_properties or exist_constant %}
|
|
32
|
+
{% if (model.properties | selectattr('validation') ) | first %}
|
|
33
|
+
|
|
34
|
+
_validation = {
|
|
35
|
+
{% for p in model.properties | selectattr('validation')%}
|
|
36
|
+
'{{ p.client_name }}': {{ str(p.validation) }},
|
|
37
|
+
{% endfor %}
|
|
38
|
+
}
|
|
39
|
+
{% endif %}
|
|
40
|
+
|
|
41
|
+
_attribute_map = {
|
|
42
|
+
{% if model.properties %}
|
|
43
|
+
{% for p in model.properties %}
|
|
44
|
+
{{ serializer.declare_property(p) }}
|
|
45
|
+
{% endfor %}
|
|
46
|
+
{% endif %}
|
|
47
|
+
}
|
|
48
|
+
{% if model.discriminated_subtypes %}
|
|
49
|
+
|
|
50
|
+
_subtype_map = {
|
|
51
|
+
'{{ model.discriminator.client_name }}': {{ str(model.discriminated_subtypes_name_mapping) }}
|
|
52
|
+
}
|
|
53
|
+
{% endif %}
|
|
54
|
+
{% if model.xml_map_content %}
|
|
55
|
+
_xml_map = {
|
|
56
|
+
{{ model.xml_map_content }}
|
|
57
|
+
}
|
|
58
|
+
{% endif %}
|
|
59
|
+
{% if exist_constant %}
|
|
60
|
+
|
|
61
|
+
{% for p in model.properties | selectattr('constant')%}
|
|
62
|
+
{{ p.client_name }} = {{ p.type.get_declaration() }}
|
|
63
|
+
{% endfor %}
|
|
64
|
+
{% endif %}
|
|
65
|
+
|
|
66
|
+
def __init__({{ model.init_pylint_disable }}
|
|
67
|
+
self,
|
|
68
|
+
{% for param_signature in serializer.init_line(model) %}
|
|
69
|
+
{{ param_signature }}
|
|
70
|
+
{% endfor %}
|
|
71
|
+
**kwargs: Any
|
|
72
|
+
) -> None:
|
|
73
|
+
"""
|
|
74
|
+
{% if model.properties %}
|
|
75
|
+
{% for p in model.properties %}
|
|
76
|
+
{% if p.is_input %}
|
|
77
|
+
{% for line in serializer.input_documentation_string(p) %}
|
|
78
|
+
{% for doc_string in line.replace('\n', '\n ').split('\n') %}
|
|
79
|
+
{{ macros.wrap_model_string(doc_string, '\n ') -}}
|
|
80
|
+
{% endfor %}
|
|
81
|
+
{% endfor %}
|
|
82
|
+
{% endif %}
|
|
83
|
+
{% endfor %}
|
|
84
|
+
{% endif %}
|
|
85
|
+
"""
|
|
86
|
+
{% for line in serializer.super_call(model) %}
|
|
87
|
+
{{ line }}
|
|
88
|
+
{% endfor %}
|
|
89
|
+
{% for initialize_property in initialize_properties %}
|
|
90
|
+
{{ initialize_property }}
|
|
91
|
+
{% endfor %}
|
|
92
|
+
{% endif %}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{% import 'keywords.jinja2' as keywords with context %}
|
|
2
|
+
{% import 'operation_tools.jinja2' as op_tools %}
|
|
3
|
+
{# actual template starts here #}
|
|
4
|
+
{% if operation.overloads and operation.include_documentation %}
|
|
5
|
+
{{ op_tools.generate_overloads(operation_serializer, operation) }}
|
|
6
|
+
{% endif %}
|
|
7
|
+
{{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
|
|
8
|
+
{% if operation.include_documentation %}
|
|
9
|
+
{{ op_tools.description(operation, operation_serializer) | indent }}{% endif %}
|
|
10
|
+
{% if not operation.abstract %}
|
|
11
|
+
{% if operation.deprecated %}
|
|
12
|
+
warnings.warn('Method {{operation.name}} is deprecated', DeprecationWarning)
|
|
13
|
+
{% endif %}
|
|
14
|
+
{{ op_tools.serialize(operation_serializer.error_map(operation)) | indent }}
|
|
15
|
+
{% if operation_serializer.pop_kwargs_from_signature(operation) %}
|
|
16
|
+
{{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
|
|
17
|
+
{% endif %}
|
|
18
|
+
{{ op_tools.serialize(operation_serializer.call_request_builder(operation)) | indent }}
|
|
19
|
+
{{ op_tools.serialize(operation_serializer.make_pipeline_call(operation)) | indent }}
|
|
20
|
+
{{ op_tools.serialize(operation_serializer.handle_response(operation)) | indent }}
|
|
21
|
+
{% endif %}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{% set base_class = ("(" + operation_group.base_class + ")") if operation_group.base_class else "" %}
|
|
2
|
+
{% macro check_abstract_methods() %}
|
|
3
|
+
{% if operation_group.has_abstract_operations %}
|
|
4
|
+
raise_if_not_implemented(self.__class__, [
|
|
5
|
+
{% for operation in operation_group.operations if operation.abstract %}
|
|
6
|
+
'{{operation.name}}',
|
|
7
|
+
{% endfor %}
|
|
8
|
+
])
|
|
9
|
+
{% endif %}
|
|
10
|
+
{% endmacro %}
|
|
11
|
+
{% if operation_group.base_class %}
|
|
12
|
+
class {{ operation_group.class_name }}( {{ operation_group.pylint_disable() }}
|
|
13
|
+
{{ operation_group.base_class }}
|
|
14
|
+
):
|
|
15
|
+
{% else %}
|
|
16
|
+
class {{ operation_group.class_name }}: {{ operation_group.pylint_disable() }}
|
|
17
|
+
{% endif %}
|
|
18
|
+
{% if not operation_group.is_mixin %}
|
|
19
|
+
"""
|
|
20
|
+
.. warning::
|
|
21
|
+
**DO NOT** instantiate this class directly.
|
|
22
|
+
|
|
23
|
+
Instead, you should access the following operations through
|
|
24
|
+
:class:`{{ "~" + code_model.namespace + (".aio." if async_mode else ".") + operation_group.client.name }}`'s
|
|
25
|
+
:attr:`{{ operation_group.property_name }}` attribute.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
{% if code_model.public_model_types and code_model.options["models_mode"] == "msrest" %}
|
|
29
|
+
models = _models
|
|
30
|
+
|
|
31
|
+
{% endif %}
|
|
32
|
+
def __init__(self, *args, **kwargs){{ return_none_type_annotation }}:
|
|
33
|
+
input_args = list(args)
|
|
34
|
+
self._client = input_args.pop(0) if input_args else kwargs.pop("client")
|
|
35
|
+
self._config = input_args.pop(0) if input_args else kwargs.pop("config")
|
|
36
|
+
self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer")
|
|
37
|
+
self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer")
|
|
38
|
+
{% if code_model.options["multiapi"] %}
|
|
39
|
+
self._api_version = input_args.pop(0) if input_args else kwargs.pop("api_version")
|
|
40
|
+
{% endif %}
|
|
41
|
+
|
|
42
|
+
{% for og in operation_group.operation_groups %}
|
|
43
|
+
self.{{ og.property_name }} = {{ og.class_name }}(
|
|
44
|
+
self._client, self._config, self._serialize, self._deserialize{{ ", self._api_version" if code_model.options["multiapi"] else "" }}
|
|
45
|
+
)
|
|
46
|
+
{% endfor %}
|
|
47
|
+
|
|
48
|
+
{{ check_abstract_methods() }}
|
|
49
|
+
{% elif operation_group.has_abstract_operations %}
|
|
50
|
+
|
|
51
|
+
def __init__(self){{ return_none_type_annotation }}:
|
|
52
|
+
{{ check_abstract_methods() }}
|
|
53
|
+
{% endif %}
|
|
54
|
+
{% if operation_group.is_mixin and code_model.options["multiapi"] %}
|
|
55
|
+
def _api_version(self, op_name: str) -> str: # pylint: disable=unused-argument
|
|
56
|
+
try:
|
|
57
|
+
return self._config.api_version
|
|
58
|
+
except: # pylint: disable=bare-except
|
|
59
|
+
return ""
|
|
60
|
+
{% endif %}
|
|
61
|
+
{% for operation in operation_group.operations if not operation.abstract %}
|
|
62
|
+
|
|
63
|
+
{% set request_builder = operation.request_builder %}
|
|
64
|
+
{% set operation_serializer = get_operation_serializer(operation) %}
|
|
65
|
+
{% if operation.operation_type == "lropaging" %}
|
|
66
|
+
{%- macro some_op() %}{% include "lro_paging_operation.py.jinja2" %}{% endmacro %}
|
|
67
|
+
{% elif operation.operation_type == "lro" %}
|
|
68
|
+
{%- macro some_op() %}{% include "lro_operation.py.jinja2" %}{% endmacro %}
|
|
69
|
+
{% elif operation.operation_type == "paging" %}
|
|
70
|
+
{% macro some_op() %}{% include "paging_operation.py.jinja2" %}{% endmacro %}
|
|
71
|
+
{% else %}
|
|
72
|
+
{% macro some_op() %}{% include "operation.py.jinja2" %}{% endmacro %}
|
|
73
|
+
{% endif %}
|
|
74
|
+
{{ some_op()|indent }}
|
|
75
|
+
{% endfor %}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{% import 'operation_tools.jinja2' as op_tools %}
|
|
2
|
+
{% set operations_description = "async operations" if async_mode else "operations" %}
|
|
3
|
+
{% set return_none_type_annotation = " -> None" if async_mode else "" %}
|
|
4
|
+
# coding=utf-8
|
|
5
|
+
{{ code_model.options['license_header'] }}
|
|
6
|
+
{{ imports }}
|
|
7
|
+
{{ unset }}
|
|
8
|
+
{% if code_model.options["builders_visibility"] == "embedded" and not async_mode %}
|
|
9
|
+
{{ op_tools.declare_serializer(code_model) }}
|
|
10
|
+
{% for operation_group in operation_groups %}
|
|
11
|
+
{% for request_builder in get_request_builders(operation_group) %}
|
|
12
|
+
|
|
13
|
+
{% include "request_builder.py.jinja2" %}
|
|
14
|
+
{% endfor %}
|
|
15
|
+
{% endfor %}
|
|
16
|
+
{% endif %}
|
|
17
|
+
{% for operation_group in operation_groups %}
|
|
18
|
+
{% include "operation_group.py.jinja2" %}
|
|
19
|
+
{% endfor %}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{% macro wrap_string(string, wrapstring, width=95) %}{{ string | replace("\\", "\\\\") | wordwrap(width=width, break_long_words=False, break_on_hyphens=False, wrapstring=wrapstring)}}{% endmacro %}
|
|
2
|
+
|
|
3
|
+
{% macro description(builder, serializer) %}
|
|
4
|
+
{% set example_template = serializer.example_template(builder) %}
|
|
5
|
+
{% set param_description_and_response_docstring = serializer.param_description_and_response_docstring(builder) %}
|
|
6
|
+
{% set ns = namespace(line_too_long=false) %}
|
|
7
|
+
{% for item in param_description_and_response_docstring %}
|
|
8
|
+
{% if item and serializer.line_too_long(wrap_string(item, wrapstring='\n ').split('\n'), 8) %}
|
|
9
|
+
{% set ns.line_too_long = true %}
|
|
10
|
+
{% endif %}
|
|
11
|
+
{% endfor %}
|
|
12
|
+
{% for description in serializer.description_and_summary(builder) %}
|
|
13
|
+
{% if description %}
|
|
14
|
+
{% set description = wrap_string(description, wrapstring='\n') %}
|
|
15
|
+
{% if (serializer.line_too_long(example_template) or ns.line_too_long) and loop.first %}
|
|
16
|
+
# pylint: disable=line-too-long
|
|
17
|
+
{% endif %}
|
|
18
|
+
{{ '"""' + description if loop.first else description }}
|
|
19
|
+
{% else %}
|
|
20
|
+
|
|
21
|
+
{% endif %}
|
|
22
|
+
{% endfor %}
|
|
23
|
+
{% for description in param_description_and_response_docstring %}
|
|
24
|
+
{% if description %}
|
|
25
|
+
{{ wrap_string(description, wrapstring='\n ') }}
|
|
26
|
+
{% else %}
|
|
27
|
+
|
|
28
|
+
{% endif %}
|
|
29
|
+
{% endfor %}
|
|
30
|
+
{% if example_template %}
|
|
31
|
+
|
|
32
|
+
Example:
|
|
33
|
+
.. code-block:: python
|
|
34
|
+
{% for template_line in example_template %}
|
|
35
|
+
{% if template_line %}
|
|
36
|
+
{% set wrap_amount = (template_line | length) - (template_line.lstrip() | length) + 10 %}
|
|
37
|
+
{{ wrap_string(template_line, wrapstring='\n' + " " * wrap_amount, width=(95 - wrap_amount)) }}
|
|
38
|
+
{% else %}
|
|
39
|
+
|
|
40
|
+
{% endif %}
|
|
41
|
+
{% endfor %}
|
|
42
|
+
{% endif %}
|
|
43
|
+
"""
|
|
44
|
+
{% endmacro %}
|
|
45
|
+
|
|
46
|
+
{% macro serialize(lines) %}
|
|
47
|
+
{% for line in lines %}
|
|
48
|
+
{% if line %}
|
|
49
|
+
{{ line }}
|
|
50
|
+
{% else %}
|
|
51
|
+
|
|
52
|
+
{% endif %}
|
|
53
|
+
{% endfor %}{% endmacro %}
|
|
54
|
+
|
|
55
|
+
{% macro serialize_with_wrap(lines, wrapstring) %}
|
|
56
|
+
{% for line in lines %}
|
|
57
|
+
{% if line %}
|
|
58
|
+
{{ wrap_string(line, wrapstring=wrapstring) }}
|
|
59
|
+
{% else %}
|
|
60
|
+
|
|
61
|
+
{% endif %}
|
|
62
|
+
{% endfor %}{% endmacro %}
|
|
63
|
+
|
|
64
|
+
{% macro declare_serializer(code_model) %}
|
|
65
|
+
{% if code_model.has_non_abstract_operations %}
|
|
66
|
+
_SERIALIZER = Serializer()
|
|
67
|
+
{% if not code_model.options["client_side_validation"] %}
|
|
68
|
+
_SERIALIZER.client_side_validation = False
|
|
69
|
+
{% endif %}
|
|
70
|
+
{% endif %}
|
|
71
|
+
{% endmacro %}
|
|
72
|
+
|
|
73
|
+
{% macro generate_overloads(operation_serializer, operation) %}
|
|
74
|
+
{% for overload in operation.overloads %}
|
|
75
|
+
{{ operation_serializer.method_signature_and_response_type_annotation(overload) }}
|
|
76
|
+
{% if not operation.internal %}
|
|
77
|
+
{{ description(overload, operation_serializer) | indent }}
|
|
78
|
+
{% else %}
|
|
79
|
+
...
|
|
80
|
+
{% endif %}
|
|
81
|
+
{% endfor %}{% endmacro %}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{% import 'operation_tools.jinja2' as op_tools %}
|
|
2
|
+
{% import 'keywords.jinja2' as keywords %}
|
|
3
|
+
{# actual template starts here #}
|
|
4
|
+
# coding=utf-8
|
|
5
|
+
{{ code_model.options['license_header'] }}
|
|
6
|
+
{{ keywords.path_type_checking_imports() }}
|
|
7
|
+
{{ op_tools.serialize(operation_group_imports()) }}
|
|
8
|
+
{{ keywords.patch_imports() }}
|
|
9
|
+
__all__ = [
|
|
10
|
+
{% for client in clients %}
|
|
11
|
+
{% for operation_group in client.operation_groups %}
|
|
12
|
+
'{{ operation_group.class_name }}',
|
|
13
|
+
{% endfor %}
|
|
14
|
+
{% endfor %}
|
|
15
|
+
]
|
|
16
|
+
{{ keywords.extend_all }}
|
|
17
|
+
_patch_sdk()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) {{ code_model.options["company_name"] }} 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,107 @@
|
|
|
1
|
+
{% if code_model.is_azure_flavor %}
|
|
2
|
+
{% if package_mode == "mgmtplane" -%}
|
|
3
|
+
# Microsoft Azure SDK for Python
|
|
4
|
+
|
|
5
|
+
This is the Microsoft {{package_pprint_name}} Client Library.
|
|
6
|
+
This package has been tested with Python 3.8+.
|
|
7
|
+
For a more complete view of Azure libraries, see the [azure sdk python release](https://aka.ms/azsdk/python/all).
|
|
8
|
+
|
|
9
|
+
# Usage
|
|
10
|
+
|
|
11
|
+
To learn how to use this package, see the [quickstart guide](https://aka.ms/azsdk/python/mgmt)
|
|
12
|
+
|
|
13
|
+
For docs and references, see [Python SDK References](https://docs.microsoft.com/python/api/overview/azure)
|
|
14
|
+
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.
|
|
15
|
+
Additional code samples for different Azure services are available at [Samples Repo](https://aka.ms/azsdk/python/mgmt/samples)
|
|
16
|
+
|
|
17
|
+
# Provide Feedback
|
|
18
|
+
|
|
19
|
+
If you encounter any bugs or have suggestions, please file an issue in the
|
|
20
|
+
[Issues](https://github.com/Azure/azure-sdk-for-python/issues)
|
|
21
|
+
section of the project.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+

|
|
25
|
+
{% else %}
|
|
26
|
+
# {{ package_pprint_name }} client library for Python
|
|
27
|
+
<!-- write necessary description of service -->
|
|
28
|
+
|
|
29
|
+
## Getting started
|
|
30
|
+
|
|
31
|
+
### Install the package
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python -m pip install {{ package_name }}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
#### Prequisites
|
|
38
|
+
|
|
39
|
+
- Python 3.8 or later is required to use this package.
|
|
40
|
+
- You need an [Azure subscription][azure_sub] to use this package.
|
|
41
|
+
- An existing {{ package_pprint_name }} instance.
|
|
42
|
+
|
|
43
|
+
{%- if token_credential %}
|
|
44
|
+
#### Create with an Azure Active Directory Credential
|
|
45
|
+
To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
|
|
46
|
+
provide an instance of the desired credential type obtained from the
|
|
47
|
+
[azure-identity][azure_identity_credentials] library.
|
|
48
|
+
|
|
49
|
+
To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip]
|
|
50
|
+
|
|
51
|
+
After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
|
|
52
|
+
As an example, [DefaultAzureCredential][default_azure_credential] can be used to authenticate the client:
|
|
53
|
+
|
|
54
|
+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
|
|
55
|
+
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`
|
|
56
|
+
|
|
57
|
+
Use the returned token credential to authenticate the client:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
>>> from {{ namespace }} import {{ client_name }}
|
|
61
|
+
>>> from azure.identity import DefaultAzureCredential
|
|
62
|
+
>>> client = {{ client_name }}(endpoint='<endpoint>', credential=DefaultAzureCredential())
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Examples
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
>>> from {{ namespace }} import {{ client_name }}
|
|
69
|
+
>>> from azure.identity import DefaultAzureCredential
|
|
70
|
+
>>> from {{ code_model.core_library }}.exceptions import HttpResponseError
|
|
71
|
+
|
|
72
|
+
>>> client = {{ client_name }}(endpoint='<endpoint>', credential=DefaultAzureCredential())
|
|
73
|
+
>>> try:
|
|
74
|
+
<!-- write test code here -->
|
|
75
|
+
except HttpResponseError as e:
|
|
76
|
+
print('service responds error: {}'.format(e.response.json()))
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
{%- endif %}
|
|
80
|
+
|
|
81
|
+
## Contributing
|
|
82
|
+
|
|
83
|
+
This project welcomes contributions and suggestions. Most contributions require
|
|
84
|
+
you to agree to a Contributor License Agreement (CLA) declaring that you have
|
|
85
|
+
the right to, and actually do, grant us the rights to use your contribution.
|
|
86
|
+
For details, visit https://cla.microsoft.com.
|
|
87
|
+
|
|
88
|
+
When you submit a pull request, a CLA-bot will automatically determine whether
|
|
89
|
+
you need to provide a CLA and decorate the PR appropriately (e.g., label,
|
|
90
|
+
comment). Simply follow the instructions provided by the bot. You will only
|
|
91
|
+
need to do this once across all repos using our CLA.
|
|
92
|
+
|
|
93
|
+
This project has adopted the
|
|
94
|
+
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
|
|
95
|
+
see the Code of Conduct FAQ or contact opencode@microsoft.com with any
|
|
96
|
+
additional questions or comments.
|
|
97
|
+
|
|
98
|
+
<!-- LINKS -->
|
|
99
|
+
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
|
|
100
|
+
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
|
|
101
|
+
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
|
|
102
|
+
[azure_identity_pip]: https://pypi.org/project/azure-identity/
|
|
103
|
+
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
|
|
104
|
+
[pip]: https://pypi.org/project/pip/
|
|
105
|
+
[azure_sub]: https://azure.microsoft.com/free/
|
|
106
|
+
{% endif %}
|
|
107
|
+
{% endif %}
|