@autorest/python 5.14.0 → 5.17.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 +91 -2
- package/README.md +30 -4
- package/autorest/__init__.py +2 -3
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +130 -179
- package/autorest/codegen/models/__init__.py +122 -78
- package/autorest/codegen/models/base_builder.py +70 -72
- package/autorest/codegen/models/base_model.py +7 -5
- package/autorest/codegen/models/{base_schema.py → base_type.py} +62 -49
- package/autorest/codegen/models/client.py +195 -36
- package/autorest/codegen/models/code_model.py +165 -299
- package/autorest/codegen/models/combined_type.py +107 -0
- package/autorest/codegen/models/constant_type.py +122 -0
- package/autorest/codegen/models/credential_types.py +224 -0
- package/autorest/codegen/models/dictionary_type.py +116 -0
- package/autorest/codegen/models/enum_type.py +195 -0
- package/autorest/codegen/models/imports.py +95 -41
- package/autorest/codegen/models/list_type.py +134 -0
- package/autorest/codegen/models/lro_operation.py +90 -133
- package/autorest/codegen/models/lro_paging_operation.py +28 -12
- package/autorest/codegen/models/model_type.py +239 -0
- package/autorest/codegen/models/operation.py +415 -241
- package/autorest/codegen/models/operation_group.py +82 -88
- package/autorest/codegen/models/paging_operation.py +101 -117
- package/autorest/codegen/models/parameter.py +307 -322
- package/autorest/codegen/models/parameter_list.py +366 -357
- package/autorest/codegen/models/primitive_types.py +544 -0
- package/autorest/codegen/models/property.py +122 -134
- package/autorest/codegen/models/request_builder.py +138 -86
- package/autorest/codegen/models/request_builder_parameter.py +122 -79
- package/autorest/codegen/models/response.py +325 -0
- package/autorest/codegen/models/utils.py +17 -1
- package/autorest/codegen/serializers/__init__.py +242 -118
- package/autorest/codegen/serializers/builder_serializer.py +863 -1027
- package/autorest/codegen/serializers/client_serializer.py +148 -82
- package/autorest/codegen/serializers/general_serializer.py +44 -47
- package/autorest/codegen/serializers/import_serializer.py +96 -31
- package/autorest/codegen/serializers/metadata_serializer.py +39 -79
- package/autorest/codegen/serializers/model_base_serializer.py +65 -29
- package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
- package/autorest/codegen/serializers/model_init_serializer.py +4 -2
- package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
- package/autorest/codegen/serializers/operation_groups_serializer.py +21 -18
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/parameter_serializer.py +174 -0
- package/autorest/codegen/serializers/patch_serializer.py +14 -2
- package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
- package/autorest/codegen/serializers/utils.py +0 -103
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
- package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
- package/autorest/codegen/templates/config.py.jinja2 +13 -13
- package/autorest/codegen/templates/enum.py.jinja2 +4 -4
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -2
- package/autorest/codegen/templates/init.py.jinja2 +9 -6
- package/autorest/codegen/templates/keywords.jinja2 +14 -1
- package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
- package/autorest/codegen/templates/model.py.jinja2 +23 -29
- package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
- package/autorest/codegen/templates/model_init.py.jinja2 +9 -8
- package/autorest/codegen/templates/operation.py.jinja2 +10 -15
- package/autorest/codegen/templates/operation_group.py.jinja2 +14 -13
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
- package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
- package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/patch.py.jinja2 +18 -29
- package/autorest/codegen/templates/request_builder.py.jinja2 +20 -13
- package/autorest/codegen/templates/setup.py.jinja2 +9 -3
- package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +28 -9
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- package/autorest/m4reformatter/__init__.py +1108 -0
- package/autorest/multiapi/__init__.py +24 -14
- package/autorest/multiapi/models/client.py +21 -11
- package/autorest/multiapi/models/code_model.py +23 -10
- package/autorest/multiapi/models/config.py +4 -1
- package/autorest/multiapi/models/constant_global_parameter.py +1 -0
- package/autorest/multiapi/models/global_parameter.py +2 -1
- package/autorest/multiapi/models/global_parameters.py +14 -8
- package/autorest/multiapi/models/imports.py +35 -18
- package/autorest/multiapi/models/mixin_operation.py +5 -5
- package/autorest/multiapi/models/operation_group.py +2 -1
- package/autorest/multiapi/models/operation_mixin_group.py +21 -10
- package/autorest/multiapi/serializers/__init__.py +20 -25
- package/autorest/multiapi/serializers/import_serializer.py +47 -15
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/postprocess/__init__.py +202 -0
- package/autorest/postprocess/get_all.py +19 -0
- package/autorest/postprocess/venvtools.py +73 -0
- package/autorest/preprocess/__init__.py +209 -0
- package/autorest/preprocess/helpers.py +54 -0
- package/autorest/{namer → preprocess}/python_mappings.py +25 -32
- package/package.json +3 -3
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/constant_schema.py +0 -97
- package/autorest/codegen/models/credential_schema.py +0 -90
- package/autorest/codegen/models/credential_schema_policy.py +0 -77
- package/autorest/codegen/models/dictionary_schema.py +0 -103
- package/autorest/codegen/models/enum_schema.py +0 -246
- package/autorest/codegen/models/list_schema.py +0 -113
- package/autorest/codegen/models/object_schema.py +0 -249
- package/autorest/codegen/models/primitive_schemas.py +0 -476
- package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
- package/autorest/codegen/models/rest.py +0 -42
- package/autorest/codegen/models/schema_request.py +0 -45
- package/autorest/codegen/models/schema_response.py +0 -123
- package/autorest/codegen/serializers/rest_serializer.py +0 -57
- package/autorest/namer/__init__.py +0 -25
- package/autorest/namer/name_converter.py +0 -412
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
{% endif %}
|
|
18
18
|
{% endfor %}
|
|
19
|
-
{% if serializer.
|
|
19
|
+
{% if serializer.example_template(builder) %}
|
|
20
20
|
|
|
21
21
|
Example:
|
|
22
22
|
.. code-block:: python
|
|
23
|
-
{% for template_line in serializer.
|
|
23
|
+
{% for template_line in serializer.example_template(builder) %}
|
|
24
24
|
{% if template_line %}
|
|
25
25
|
{% set wrap_amount = (template_line | length) - (template_line.lstrip() | length) + 10 %}
|
|
26
26
|
{{ wrap_string(template_line, wrapstring='\n' + " " * wrap_amount, width=(95 - wrap_amount)) }}
|
|
@@ -56,3 +56,9 @@ _SERIALIZER = Serializer()
|
|
|
56
56
|
_SERIALIZER.client_side_validation = False
|
|
57
57
|
{% endif %}
|
|
58
58
|
{% endmacro %}
|
|
59
|
+
|
|
60
|
+
{% macro generate_overloads(operation_serializer, operation) %}
|
|
61
|
+
{% for overload in operation.overloads %}
|
|
62
|
+
{{ operation_serializer.method_signature_and_response_type_annotation(overload) }}
|
|
63
|
+
{{ description(overload, operation_serializer) | indent }}
|
|
64
|
+
{% endfor %}{% endmacro %}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{% import 'operation_tools.jinja2' as op_tools %}
|
|
2
|
+
{% import 'keywords.jinja2' as keywords %}
|
|
2
3
|
{# actual template starts here #}
|
|
3
4
|
# coding=utf-8
|
|
4
5
|
{{ code_model.options['license_header'] }}
|
|
5
6
|
|
|
6
7
|
{{ op_tools.serialize(operation_group_imports()) }}
|
|
8
|
+
{{ keywords.patch_imports() }}
|
|
7
9
|
{% if operation_groups %}
|
|
8
10
|
__all__ = [
|
|
9
11
|
{% for operation_group in operation_groups %}
|
|
@@ -11,3 +13,5 @@ __all__ = [
|
|
|
11
13
|
{% endfor %}
|
|
12
14
|
]
|
|
13
15
|
{% endif %}
|
|
16
|
+
{{ keywords.extend_all }}
|
|
17
|
+
_patch_sdk()
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
{% import 'operation_tools.jinja2' as op_tools with context %}
|
|
2
2
|
{# actual template starts here #}
|
|
3
|
-
{% if code_model.options['tracing'] and operation.want_tracing %}
|
|
4
|
-
@distributed_trace
|
|
5
|
-
{% endif %}
|
|
6
3
|
{{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
|
|
7
|
-
{% if operation.
|
|
4
|
+
{% if operation.public %}
|
|
8
5
|
{{ op_tools.description(operation, operation_serializer) | indent }}{% endif %}
|
|
9
|
-
{% if operation.
|
|
6
|
+
{% if not operation.abstract %}
|
|
7
|
+
{% if operation.deprecated %}
|
|
10
8
|
warnings.warn('Method {{operation.name}} is deprecated', DeprecationWarning)
|
|
11
|
-
{% endif %}
|
|
12
|
-
|
|
9
|
+
{% endif %}
|
|
10
|
+
{% if operation_serializer.pop_kwargs_from_signature(operation) %}
|
|
13
11
|
{{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
|
|
14
|
-
|
|
12
|
+
{% endif %}
|
|
15
13
|
{{ op_tools.serialize(operation_serializer.set_up_params_for_pager(operation)) | indent }}
|
|
16
14
|
|
|
17
15
|
return {{ operation.get_pager(async_mode) }}(
|
|
18
16
|
get_next, extract_data
|
|
19
17
|
)
|
|
18
|
+
{% endif %}
|
|
20
19
|
{% if not code_model.options["version_tolerant"] %}
|
|
21
20
|
{{ operation_serializer.get_metadata_url(operation) -}}
|
|
22
21
|
{% endif %}
|
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
# furnished to do so, subject to the following conditions:
|
|
14
|
-
#
|
|
15
|
-
# The above copyright notice and this permission notice shall be included in
|
|
16
|
-
# all copies or substantial portions of the Software.
|
|
17
|
-
#
|
|
18
|
-
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
24
|
-
# IN THE SOFTWARE.
|
|
25
|
-
#
|
|
26
|
-
# --------------------------------------------------------------------------
|
|
1
|
+
# ------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation.
|
|
3
|
+
# Licensed under the MIT License.
|
|
4
|
+
# ------------------------------------
|
|
5
|
+
"""Customize generated code here.
|
|
6
|
+
|
|
7
|
+
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
|
|
8
|
+
"""
|
|
9
|
+
{{ imports }}
|
|
10
|
+
|
|
11
|
+
{% set type_annotation = ": List[str]" %}
|
|
12
|
+
__all__{{ type_annotation if is_python3_file else "" }} = []{{ "" if is_python3_file else (" # type" + type_annotation) }} # Add all objects you want publicly available to users at this package level
|
|
27
13
|
|
|
28
|
-
# This file is used for handwritten extensions to the generated code. Example:
|
|
29
|
-
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
|
|
30
14
|
def patch_sdk():
|
|
31
|
-
|
|
15
|
+
"""Do not remove from this file.
|
|
16
|
+
|
|
17
|
+
`patch_sdk` is a last resort escape hatch that allows you to do customizations
|
|
18
|
+
you can't accomplish using the techniques described in
|
|
19
|
+
https://aka.ms/azsdk/python/dpcodegen/python/customize
|
|
20
|
+
"""
|
|
@@ -4,25 +4,32 @@
|
|
|
4
4
|
{% if code_model.options["builders_visibility"] == "public" %}
|
|
5
5
|
{{ op_tools.description(request_builder, request_builder_serializer) | indent }}
|
|
6
6
|
{% endif %}
|
|
7
|
-
{% if request_builder.
|
|
7
|
+
{% if not request_builder.is_overload %}
|
|
8
|
+
{% if request_builder.abstract %}
|
|
9
|
+
raise NotImplementedError(
|
|
10
|
+
"You need to write a custom operation for '{{ request_builder.name }}'. "
|
|
11
|
+
"Please refer to https://aka.ms/azsdk/python/dpcodegen/python/customize to learn how to customize."
|
|
12
|
+
)
|
|
13
|
+
{% else %}
|
|
14
|
+
{% if request_builder_serializer.pop_kwargs_from_signature(request_builder) %}
|
|
8
15
|
{{ op_tools.serialize(request_builder_serializer.pop_kwargs_from_signature(request_builder)) | indent }}
|
|
9
|
-
{
|
|
10
|
-
{% if
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
{% endfor %}
|
|
14
|
-
{% endif %}
|
|
16
|
+
{%- endif -%}
|
|
17
|
+
{% if request_builder_serializer.declare_non_inputtable_constants(request_builder) %}
|
|
18
|
+
{{ op_tools.serialize(request_builder_serializer.declare_non_inputtable_constants(request_builder)) | indent }}
|
|
19
|
+
{% endif %}
|
|
15
20
|
# Construct URL
|
|
16
21
|
{{ request_builder_serializer.construct_url(request_builder) }}
|
|
17
|
-
{% if request_builder.parameters.path %}
|
|
22
|
+
{% if request_builder.parameters.path %}
|
|
18
23
|
{{ op_tools.serialize(request_builder_serializer.serialize_path(request_builder)) | indent }}
|
|
19
24
|
_url = _format_url_section(_url, **path_format_arguments)
|
|
20
|
-
{% endif %}
|
|
25
|
+
{% endif %}
|
|
21
26
|
|
|
22
|
-
{% if request_builder.parameters.query %}
|
|
27
|
+
{% if request_builder.parameters.query %}
|
|
23
28
|
{{ op_tools.serialize(request_builder_serializer.serialize_query(request_builder)) | indent }}
|
|
24
|
-
{% endif %}
|
|
25
|
-
{% if request_builder.parameters.headers %}
|
|
29
|
+
{% endif %}
|
|
30
|
+
{% if request_builder.parameters.headers %}
|
|
26
31
|
{{ op_tools.serialize(request_builder_serializer.serialize_headers(request_builder)) | indent }}
|
|
27
|
-
{% endif %}
|
|
32
|
+
{% endif %}
|
|
28
33
|
{{ op_tools.serialize(request_builder_serializer.create_http_request(request_builder)) | indent }}
|
|
34
|
+
{% endif %}
|
|
35
|
+
{% endif %}
|
|
@@ -7,7 +7,7 @@ import re
|
|
|
7
7
|
{% endif -%}
|
|
8
8
|
from setuptools import setup, find_packages
|
|
9
9
|
|
|
10
|
-
{% set package_name_render = package_name or code_model.
|
|
10
|
+
{% set package_name_render = package_name or code_model.client.name %}
|
|
11
11
|
|
|
12
12
|
PACKAGE_NAME = "{{ package_name_render|lower }}"
|
|
13
13
|
{% if package_mode -%}
|
|
@@ -30,7 +30,7 @@ if not version:
|
|
|
30
30
|
{% else %}
|
|
31
31
|
version = "{{ code_model.options['package_version'] }}"
|
|
32
32
|
{% set description = "%s"|format(package_name_render) %}
|
|
33
|
-
{% set long_description = code_model.description %}
|
|
33
|
+
{% set long_description = code_model.client.description %}
|
|
34
34
|
{% set author_email = "" %}
|
|
35
35
|
{% set url = "" %}
|
|
36
36
|
{% endif -%}
|
|
@@ -65,12 +65,18 @@ setup(
|
|
|
65
65
|
packages=find_packages(
|
|
66
66
|
exclude=[
|
|
67
67
|
"tests",
|
|
68
|
+
{% if pkgutil_names %}
|
|
68
69
|
# Exclude packages that will be covered by PEP420 or nspkg
|
|
70
|
+
{% endif %}
|
|
69
71
|
{%- for pkgutil_name in pkgutil_names %}
|
|
70
72
|
"{{ pkgutil_name }}",
|
|
71
73
|
{%- endfor %}
|
|
72
74
|
]
|
|
73
75
|
),
|
|
76
|
+
include_package_data=True,
|
|
77
|
+
package_data={
|
|
78
|
+
'pytyped': ['py.typed'],
|
|
79
|
+
},
|
|
74
80
|
{% else %}
|
|
75
81
|
packages=find_packages(),
|
|
76
82
|
include_package_data=True,
|
|
@@ -87,7 +93,7 @@ setup(
|
|
|
87
93
|
python_requires=">=3.6",
|
|
88
94
|
{% else %}
|
|
89
95
|
long_description="""\
|
|
90
|
-
{{ code_model.description }}
|
|
96
|
+
{{ code_model.client.description }}
|
|
91
97
|
"""
|
|
92
98
|
{% endif %}
|
|
93
99
|
)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
{% import 'keywords.jinja2' as keywords with context %}
|
|
1
2
|
{{ code_model.options['license_header'] }}
|
|
2
3
|
|
|
3
4
|
{{ imports }}
|
|
4
5
|
|
|
5
|
-
{% if code_model.need_request_converter %}
|
|
6
|
+
{% if code_model.need_request_converter and not async_mode %}
|
|
6
7
|
def _convert_request(request, files=None):
|
|
7
8
|
data = request.content if not files else None
|
|
8
9
|
request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data)
|
|
@@ -10,7 +11,7 @@ def _convert_request(request, files=None):
|
|
|
10
11
|
request.set_formdata_body(files)
|
|
11
12
|
return request
|
|
12
13
|
{% endif %}
|
|
13
|
-
{% if code_model.need_format_url %}
|
|
14
|
+
{% if code_model.need_format_url and not async_mode %}
|
|
14
15
|
|
|
15
16
|
def _format_url_section(template, **kwargs):
|
|
16
17
|
components = template.split("/")
|
|
@@ -24,3 +25,12 @@ def _format_url_section(template, **kwargs):
|
|
|
24
25
|
]
|
|
25
26
|
template = "/".join(components)
|
|
26
27
|
{% endif %}
|
|
28
|
+
{% if code_model.need_mixin_abc %}
|
|
29
|
+
|
|
30
|
+
class MixinABC(ABC):
|
|
31
|
+
"""DO NOT use this class. It is for internal typing use only."""
|
|
32
|
+
_client: "{{ keywords.async_class }}PipelineClient"
|
|
33
|
+
_config: {{ code_model.client.name }}Configuration
|
|
34
|
+
_serialize: "Serializer"
|
|
35
|
+
_deserialize: "Deserializer"
|
|
36
|
+
{% endif %}
|
|
@@ -7,7 +7,7 @@ from abc import ABC, abstractmethod
|
|
|
7
7
|
from enum import Enum
|
|
8
8
|
from typing import Any, List, Optional, Union
|
|
9
9
|
import logging
|
|
10
|
-
import logging.config
|
|
10
|
+
import logging.config # need to include this extra import so mypy doesn't throw logging module has no config
|
|
11
11
|
from pathlib import Path
|
|
12
12
|
|
|
13
13
|
|
|
@@ -45,13 +45,12 @@ class AutorestHandler(logging.Handler):
|
|
|
45
45
|
# Initialize this handler with the max loglevel, since
|
|
46
46
|
# autorest is deciding what to show, not us
|
|
47
47
|
# so we want to log everything and let autorest filters.
|
|
48
|
-
super(
|
|
48
|
+
super().__init__(logging.DEBUG)
|
|
49
49
|
self._autorest_api = autorest_api
|
|
50
50
|
|
|
51
51
|
@staticmethod
|
|
52
52
|
def _get_log_level(level: int) -> Channel:
|
|
53
|
-
"""Convert Python log levels to Autorest Channel.
|
|
54
|
-
"""
|
|
53
|
+
"""Convert Python log levels to Autorest Channel."""
|
|
55
54
|
return _LEVEL_MAPPING.get(level, Channel.Warning)
|
|
56
55
|
|
|
57
56
|
def emit(self, record: logging.LogRecord) -> None:
|
|
@@ -65,8 +64,7 @@ class AutorestHandler(logging.Handler):
|
|
|
65
64
|
|
|
66
65
|
|
|
67
66
|
class AutorestAPI(ABC):
|
|
68
|
-
"""Defines the base interface of communication to Autorest from the plugin.
|
|
69
|
-
"""
|
|
67
|
+
"""Defines the base interface of communication to Autorest from the plugin."""
|
|
70
68
|
|
|
71
69
|
def __init__(self) -> None:
|
|
72
70
|
if Path("logging.conf").exists():
|
|
@@ -106,18 +104,15 @@ class AutorestAPI(ABC):
|
|
|
106
104
|
|
|
107
105
|
@abstractmethod
|
|
108
106
|
def list_inputs(self) -> List[str]:
|
|
109
|
-
"""List possible inputs for this plugin.
|
|
110
|
-
"""
|
|
107
|
+
"""List possible inputs for this plugin."""
|
|
111
108
|
|
|
112
109
|
@abstractmethod
|
|
113
110
|
def get_value(self, key: str) -> Any:
|
|
114
|
-
"""Get a value from configuration.
|
|
115
|
-
"""
|
|
111
|
+
"""Get a value from configuration."""
|
|
116
112
|
|
|
117
113
|
@abstractmethod
|
|
118
114
|
def message(self, channel: Channel, text: str) -> None:
|
|
119
|
-
"""Send a log message to autorest.
|
|
120
|
-
"""
|
|
115
|
+
"""Send a log message to autorest."""
|
|
121
116
|
|
|
122
117
|
def get_boolean_value(self, key: str, default: bool = None) -> Optional[bool]:
|
|
123
118
|
"""Check if value is present on the line, and interpret it as bool if it was.
|
|
@@ -14,10 +14,11 @@ _LOGGER = logging.getLogger(__name__)
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class LocalAutorestAPI(AutorestAPI):
|
|
17
|
-
"""A local API that will write on local disk.
|
|
18
|
-
"""
|
|
17
|
+
"""A local API that will write on local disk."""
|
|
19
18
|
|
|
20
|
-
def __init__(
|
|
19
|
+
def __init__(
|
|
20
|
+
self, reachable_files: List[str] = None, output_folder: str = "generated"
|
|
21
|
+
) -> None:
|
|
21
22
|
super().__init__()
|
|
22
23
|
if reachable_files is None:
|
|
23
24
|
reachable_files = []
|
|
@@ -18,27 +18,42 @@ _LOGGER = logging.getLogger(__name__)
|
|
|
18
18
|
|
|
19
19
|
@dispatcher.add_method
|
|
20
20
|
def GetPluginNames():
|
|
21
|
-
return [
|
|
21
|
+
return [
|
|
22
|
+
"codegen",
|
|
23
|
+
"m2r",
|
|
24
|
+
"preprocess",
|
|
25
|
+
"m4reformatter",
|
|
26
|
+
"black",
|
|
27
|
+
"multiapiscript",
|
|
28
|
+
"postprocess",
|
|
29
|
+
]
|
|
22
30
|
|
|
23
31
|
|
|
24
32
|
@dispatcher.add_method
|
|
25
33
|
def Process(plugin_name: str, session_id: str) -> bool:
|
|
26
34
|
# pylint: disable=import-outside-toplevel
|
|
27
|
-
"""JSON-RPC process call.
|
|
28
|
-
"""
|
|
35
|
+
"""JSON-RPC process call."""
|
|
29
36
|
from .stdstream import StdStreamAutorestAPI
|
|
30
37
|
|
|
31
38
|
with contextlib.closing(StdStreamAutorestAPI(session_id)) as stdstream_connection:
|
|
32
39
|
|
|
33
|
-
_LOGGER.debug(
|
|
40
|
+
_LOGGER.debug(
|
|
41
|
+
"Autorest called process with plugin_name '%s' and session_id: '%s'",
|
|
42
|
+
plugin_name,
|
|
43
|
+
session_id,
|
|
44
|
+
)
|
|
34
45
|
if plugin_name == "m2r":
|
|
35
46
|
from ..m2r import M2R as PluginToLoad
|
|
36
|
-
elif plugin_name == "
|
|
37
|
-
from ..
|
|
47
|
+
elif plugin_name == "preprocess":
|
|
48
|
+
from ..preprocess import PreProcessPlugin as PluginToLoad # type: ignore
|
|
49
|
+
elif plugin_name == "m4reformatter":
|
|
50
|
+
from ..m4reformatter import M4Reformatter as PluginToLoad # type: ignore
|
|
38
51
|
elif plugin_name == "codegen":
|
|
39
52
|
from ..codegen import CodeGenerator as PluginToLoad # type: ignore
|
|
53
|
+
elif plugin_name == "postprocess":
|
|
54
|
+
from ..postprocess import PostProcessPlugin as PluginToLoad # type: ignore
|
|
40
55
|
elif plugin_name == "black":
|
|
41
|
-
from ..black import BlackScriptPlugin
|
|
56
|
+
from ..black import BlackScriptPlugin as PluginToLoad # type: ignore
|
|
42
57
|
elif plugin_name == "multiapiscript":
|
|
43
58
|
from ..multiapi import MultiApiScriptPlugin as PluginToLoad # type: ignore
|
|
44
59
|
else:
|
|
@@ -58,11 +73,15 @@ def Process(plugin_name: str, session_id: str) -> bool:
|
|
|
58
73
|
def main() -> None:
|
|
59
74
|
# If --python.debugger is specified on the command line, we call the server.py file internally
|
|
60
75
|
# with flag --debug.
|
|
61
|
-
if
|
|
76
|
+
if "--debug" in sys.argv or os.environ.get(
|
|
77
|
+
"AUTOREST_PYTHON_ATTACH_VSCODE_DEBUG", False
|
|
78
|
+
):
|
|
62
79
|
try:
|
|
63
80
|
import ptvsd # pylint: disable=import-outside-toplevel
|
|
64
81
|
except ImportError:
|
|
65
|
-
raise SystemExit(
|
|
82
|
+
raise SystemExit(
|
|
83
|
+
"Please pip install ptvsd in order to use VSCode debugging"
|
|
84
|
+
)
|
|
66
85
|
|
|
67
86
|
# 5678 is the default attach port in the VS Code debug configurations
|
|
68
87
|
ptvsd.enable_attach(address=("localhost", 5678), redirect_output=True)
|
|
@@ -53,8 +53,7 @@ def write_message(message: str, stream: BinaryIO = sys.stdout.buffer) -> None:
|
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
class StdStreamAutorestAPI(AutorestAPI):
|
|
56
|
-
"""The stream API with Autorest
|
|
57
|
-
"""
|
|
56
|
+
"""The stream API with Autorest"""
|
|
58
57
|
|
|
59
58
|
def __init__(self, session_id: str) -> None:
|
|
60
59
|
super().__init__()
|
|
@@ -73,19 +72,25 @@ class StdStreamAutorestAPI(AutorestAPI):
|
|
|
73
72
|
def read_file(self, filename: Union[str, Path]) -> str:
|
|
74
73
|
_LOGGER.debug("Asking content for file %s", filename)
|
|
75
74
|
filename = os.fspath(filename)
|
|
76
|
-
request = JSONRPC20Request(
|
|
75
|
+
request = JSONRPC20Request(
|
|
76
|
+
method="ReadFile", params=[self.session_id, filename], _id=42
|
|
77
|
+
)
|
|
77
78
|
write_message(request.json)
|
|
78
79
|
return json.loads(read_message())["result"]
|
|
79
80
|
|
|
80
81
|
def list_inputs(self) -> List[str]:
|
|
81
82
|
_LOGGER.debug("Calling list inputs to Autorest")
|
|
82
|
-
request = JSONRPC20Request(
|
|
83
|
+
request = JSONRPC20Request(
|
|
84
|
+
method="ListInputs", params=[self.session_id, None], _id=42
|
|
85
|
+
)
|
|
83
86
|
write_message(request.json)
|
|
84
87
|
return json.loads(read_message())["result"]
|
|
85
88
|
|
|
86
89
|
def get_value(self, key: str) -> Any:
|
|
87
90
|
_LOGGER.debug("Calling get value to Autorest: %s", key)
|
|
88
|
-
request = JSONRPC20Request(
|
|
91
|
+
request = JSONRPC20Request(
|
|
92
|
+
method="GetValue", params=[self.session_id, key], _id=42
|
|
93
|
+
)
|
|
89
94
|
write_message(request.json)
|
|
90
95
|
return json.loads(read_message())["result"]
|
|
91
96
|
|
|
@@ -96,5 +101,7 @@ class StdStreamAutorestAPI(AutorestAPI):
|
|
|
96
101
|
"Channel": channel.value,
|
|
97
102
|
"Text": text,
|
|
98
103
|
}
|
|
99
|
-
request = JSONRPC20Request(
|
|
104
|
+
request = JSONRPC20Request(
|
|
105
|
+
method="Message", params=[self.session_id, message], is_notification=True
|
|
106
|
+
)
|
|
100
107
|
write_message(request.json)
|
package/autorest/m2r/__init__.py
CHANGED
|
@@ -27,18 +27,16 @@ class AutorestRender(m2r.RestRenderer):
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
class M2R(YamlUpdatePlugin):
|
|
30
|
-
"""A plugin to convert any description and summary from MD to RST.
|
|
31
|
-
|
|
30
|
+
"""A plugin to convert any description and summary from MD to RST."""
|
|
31
|
+
|
|
32
32
|
def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
|
|
33
|
-
"""Convert in place the YAML str.
|
|
34
|
-
"""
|
|
33
|
+
"""Convert in place the YAML str."""
|
|
35
34
|
self._convert_docstring_no_cycles(yaml_data, set())
|
|
36
35
|
|
|
37
36
|
def _convert_docstring_no_cycles(
|
|
38
37
|
self, yaml_data: Dict[str, Any], node_list: Set[int]
|
|
39
38
|
) -> None:
|
|
40
|
-
"""Walk the YAML tree to convert MD to RST.
|
|
41
|
-
"""
|
|
39
|
+
"""Walk the YAML tree to convert MD to RST."""
|
|
42
40
|
if id(yaml_data) in node_list:
|
|
43
41
|
return
|
|
44
42
|
node_list.add(id(yaml_data))
|
|
@@ -55,8 +53,7 @@ class M2R(YamlUpdatePlugin):
|
|
|
55
53
|
|
|
56
54
|
@staticmethod
|
|
57
55
|
def convert_to_rst(string_to_convert: str) -> str:
|
|
58
|
-
"""Convert that string from MD to RST.
|
|
59
|
-
"""
|
|
56
|
+
"""Convert that string from MD to RST."""
|
|
60
57
|
try:
|
|
61
58
|
return m2r.convert(string_to_convert, renderer=AutorestRender()).strip()
|
|
62
59
|
except Exception: # pylint: disable=broad-except
|