From f2f67a49a4571db85d8baa86aa3126707af98fc9 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 15 Feb 2022 18:34:53 -0500 Subject: [PATCH 1/2] add code model as an attr on JinjaSerializer --- autorest/codegen/__init__.py | 4 +- autorest/codegen/serializers/__init__.py | 140 +++++++++--------- .../_llc_client.py | 76 ---------- .../aio/_llc_client.py | 72 --------- .../_llc_client.py | 76 ---------- .../aio/_llc_client.py | 72 --------- 6 files changed, 71 insertions(+), 369 deletions(-) delete mode 100644 test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenInitialLowLevel/dpgservicedriveninitiallowlevel/_llc_client.py delete mode 100644 test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenInitialLowLevel/dpgservicedriveninitiallowlevel/aio/_llc_client.py delete mode 100644 test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneLowLevel/dpgservicedrivenupdateonelowlevel/_llc_client.py delete mode 100644 test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneLowLevel/dpgservicedrivenupdateonelowlevel/aio/_llc_client.py diff --git a/autorest/codegen/__init__.py b/autorest/codegen/__init__.py index 26ddbd6fd72..7625faa5a12 100644 --- a/autorest/codegen/__init__.py +++ b/autorest/codegen/__init__.py @@ -327,8 +327,8 @@ def process(self) -> bool: code_model = self._create_code_model(yaml_data=yaml_data, options=options) - serializer = JinjaSerializer(self._autorestapi) - serializer.serialize(code_model) + serializer = JinjaSerializer(self._autorestapi, code_model) + serializer.serialize() return True diff --git a/autorest/codegen/serializers/__init__.py b/autorest/codegen/serializers/__init__.py index eda1ea1f881..05d001c8238 100644 --- a/autorest/codegen/serializers/__init__.py +++ b/autorest/codegen/serializers/__init__.py @@ -30,10 +30,11 @@ ] class JinjaSerializer: - def __init__(self, autorestapi: AutorestAPI) -> None: + def __init__(self, autorestapi: AutorestAPI, code_model: CodeModel) -> None: self._autorestapi = autorestapi + self.code_model = code_model - def serialize(self, code_model: CodeModel) -> None: + def serialize(self) -> None: env = Environment( loader=PackageLoader("autorest.codegen", "templates"), keep_trailing_newline=True, @@ -44,32 +45,32 @@ def serialize(self, code_model: CodeModel) -> None: ) namespace_path = ( - Path(".") if code_model.options["no_namespace_folders"] else Path(*(code_model.namespace.split("."))) + Path(".") if self.code_model.options["no_namespace_folders"] else Path(*(self.code_model.namespace.split("."))) ) # if there was a patch file before, we keep it self._keep_patch_file(namespace_path / Path("_patch.py"), env) self._keep_patch_file(namespace_path / Path("aio") / Path("_patch.py"), env) - self._serialize_and_write_top_level_folder(code_model=code_model, env=env, namespace_path=namespace_path) + self._serialize_and_write_top_level_folder(env=env, namespace_path=namespace_path) - if code_model.rest.request_builders: - if code_model.options["builders_visibility"] != "embedded": - self._serialize_and_write_rest_layer(code_model=code_model, env=env, namespace_path=namespace_path) - if not code_model.options["no_async"]: + if self.code_model.rest.request_builders: + if self.code_model.options["builders_visibility"] != "embedded": + self._serialize_and_write_rest_layer(env=env, namespace_path=namespace_path) + if not self.code_model.options["no_async"]: self._serialize_and_write_aio_top_level_folder( - code_model=code_model, env=env, namespace_path=namespace_path, + env=env, namespace_path=namespace_path, ) - if code_model.options["show_operations"] and code_model.operation_groups: - self._serialize_and_write_operations_folder(code_model=code_model, env=env, namespace_path=namespace_path) - if code_model.options["multiapi"]: + if self.code_model.options["show_operations"] and self.code_model.operation_groups: + self._serialize_and_write_operations_folder(env=env, namespace_path=namespace_path) + if self.code_model.options["multiapi"]: self._serialize_and_write_metadata( - code_model, env=env, namespace_path=namespace_path + env=env, namespace_path=namespace_path ) - if code_model.options["models_mode"] and (code_model.schemas or code_model.enums): - self._serialize_and_write_models_folder(code_model=code_model, env=env, namespace_path=namespace_path) + if self.code_model.options["models_mode"] and (self.code_model.schemas or self.code_model.enums): + self._serialize_and_write_models_folder(env=env, namespace_path=namespace_path) @@ -80,49 +81,49 @@ def _keep_patch_file(self, path_file: Path, env: Environment): self._autorestapi.write_file(path_file, PatchSerializer(env=env).serialize()) - def _serialize_and_write_models_folder(self, code_model: CodeModel, env: Environment, namespace_path: Path) -> None: + def _serialize_and_write_models_folder(self, env: Environment, namespace_path: Path) -> None: # Write the models folder models_path = namespace_path / Path("models") - if code_model.schemas: - if not code_model.options['python3_only']: + if self.code_model.schemas: + if not self.code_model.options['python3_only']: self._autorestapi.write_file( - models_path / Path("_models.py"), ModelGenericSerializer(code_model=code_model, env=env).serialize() + models_path / Path("_models.py"), ModelGenericSerializer(code_model=self.code_model, env=env).serialize() ) self._autorestapi.write_file( - models_path / Path("_models_py3.py"), ModelPython3Serializer(code_model=code_model, env=env).serialize() + models_path / Path("_models_py3.py"), ModelPython3Serializer(code_model=self.code_model, env=env).serialize() ) - if code_model.enums: + if self.code_model.enums: self._autorestapi.write_file( - models_path / Path(f"_{code_model.module_name}_enums.py"), - EnumSerializer(code_model=code_model, env=env).serialize(), + models_path / Path(f"_{self.code_model.module_name}_enums.py"), + EnumSerializer(code_model=self.code_model, env=env).serialize(), ) self._autorestapi.write_file( - models_path / Path("__init__.py"), ModelInitSerializer(code_model=code_model, env=env).serialize() + models_path / Path("__init__.py"), ModelInitSerializer(code_model=self.code_model, env=env).serialize() ) def _serialize_and_write_rest_layer( - self, code_model: CodeModel, env: Environment, namespace_path: Path + self, env: Environment, namespace_path: Path ) -> None: - rest_path = namespace_path / Path(code_model.rest_layer_name) + rest_path = namespace_path / Path(self.code_model.rest_layer_name) operation_group_names = { - rb.operation_group_name for rb in code_model.rest.request_builders + rb.operation_group_name for rb in self.code_model.rest.request_builders } for operation_group_name in operation_group_names: request_builders = [ - r for r in code_model.rest.request_builders if r.operation_group_name == operation_group_name + r for r in self.code_model.rest.request_builders if r.operation_group_name == operation_group_name ] self._serialize_and_write_single_rest_layer( - code_model, env, rest_path, request_builders + env, rest_path, request_builders ) if not "" in operation_group_names: self._autorestapi.write_file( - rest_path / Path("__init__.py"), code_model.options['license_header'] + rest_path / Path("__init__.py"), self.code_model.options['license_header'] ) def _serialize_and_write_single_rest_layer( - self, code_model: CodeModel, env: Environment, rest_path: Path, request_builders: List[RequestBuilder] + self, env: Environment, rest_path: Path, request_builders: List[RequestBuilder] ) -> None: builder_group_name = request_builders[0].builder_group_name output_path = rest_path / Path(builder_group_name) if builder_group_name else rest_path @@ -130,7 +131,7 @@ def _serialize_and_write_single_rest_layer( self._autorestapi.write_file( output_path / Path("_request_builders.py"), RestGenericSerializer( - code_model=code_model, env=env, request_builders=request_builders + code_model=self.code_model, env=env, request_builders=request_builders ).serialize_request_builders() ) @@ -138,20 +139,19 @@ def _serialize_and_write_single_rest_layer( self._autorestapi.write_file( output_path / Path("_request_builders_py3.py"), RestPython3Serializer( - code_model=code_model, env=env, request_builders=request_builders + code_model=self.code_model, env=env, request_builders=request_builders ).serialize_request_builders() ) # write rest init file self._autorestapi.write_file( output_path / Path("__init__.py"), RestSerializer( - code_model=code_model, env=env, request_builders=request_builders + code_model=self.code_model, env=env, request_builders=request_builders ).serialize_init() ) def _serialize_and_write_operations_file( self, - code_model: CodeModel, env: Environment, namespace_path: Path, operation_group: Optional[OperationGroup] = None @@ -159,35 +159,35 @@ def _serialize_and_write_operations_file( filename = operation_group.filename if operation_group else "_operations" # write first sync file operation_group_serializer = OperationGroupsSerializer( - code_model=code_model, + code_model=self.code_model, env=env, async_mode=False, - is_python3_file=code_model.options['python3_only'], + is_python3_file=self.code_model.options['python3_only'], operation_group=operation_group ) self._autorestapi.write_file( - namespace_path / Path(code_model.operations_folder_name) / Path(f"{filename}.py"), + namespace_path / Path(self.code_model.operations_folder_name) / Path(f"{filename}.py"), operation_group_serializer.serialize(), ) - if not code_model.options['python3_only'] and code_model.options["add_python3_operation_files"]: + if not self.code_model.options['python3_only'] and self.code_model.options["add_python3_operation_files"]: # write typed second file if not python 3 only operation_group_serializer = OperationGroupsSerializer( - code_model=code_model, + code_model=self.code_model, env=env, async_mode=False, is_python3_file=True, ) self._autorestapi.write_file( - namespace_path / Path(code_model.operations_folder_name) / Path(f"{filename}_py3.py"), + namespace_path / Path(self.code_model.operations_folder_name) / Path(f"{filename}_py3.py"), operation_group_serializer.serialize(), ) - if not code_model.options["no_async"]: + if not self.code_model.options["no_async"]: # write async operation group and operation files operation_group_async_serializer = OperationGroupsSerializer( - code_model=code_model, + code_model=self.code_model, env=env, async_mode=True, is_python3_file=True, @@ -197,47 +197,45 @@ def _serialize_and_write_operations_file( ( namespace_path / Path("aio") - / Path(code_model.operations_folder_name) + / Path(self.code_model.operations_folder_name) / Path(f"{filename}.py") ), operation_group_async_serializer.serialize(), ) def _serialize_and_write_operations_folder( - self, code_model: CodeModel, env: Environment, namespace_path: Path + self, env: Environment, namespace_path: Path ) -> None: # write sync operations init file - operations_init_serializer = OperationsInitSerializer(code_model=code_model, env=env, async_mode=False) + operations_init_serializer = OperationsInitSerializer(code_model=self.code_model, env=env, async_mode=False) self._autorestapi.write_file( - namespace_path / Path(code_model.operations_folder_name) / Path("__init__.py"), + namespace_path / Path(self.code_model.operations_folder_name) / Path("__init__.py"), operations_init_serializer.serialize(), ) # write async operations init file - if not code_model.options["no_async"]: - operations_async_init_serializer = OperationsInitSerializer(code_model=code_model, env=env, async_mode=True) + if not self.code_model.options["no_async"]: + operations_async_init_serializer = OperationsInitSerializer(code_model=self.code_model, env=env, async_mode=True) self._autorestapi.write_file( - namespace_path / Path("aio") / Path(code_model.operations_folder_name) / Path("__init__.py"), + namespace_path / Path("aio") / Path(self.code_model.operations_folder_name) / Path("__init__.py"), operations_async_init_serializer.serialize(), ) - if code_model.options["combine_operation_files"]: + if self.code_model.options["combine_operation_files"]: self._serialize_and_write_operations_file( - code_model=code_model, env=env, namespace_path=namespace_path, ) else: - for operation_group in code_model.operation_groups: + for operation_group in self.code_model.operation_groups: self._serialize_and_write_operations_file( - code_model=code_model, env=env, namespace_path=namespace_path, operation_group=operation_group, ) def _serialize_and_write_version_file( - self, code_model: CodeModel, namespace_path: Path, general_serializer: GeneralSerializer + self, namespace_path: Path, general_serializer: GeneralSerializer ): def _read_version_file(original_version_file_name: str) -> str: return self._autorestapi.read_file(namespace_path / original_version_file_name) @@ -247,23 +245,23 @@ def _write_version_file(original_version_file_name: str) -> None: namespace_path / Path("_version.py"), _read_version_file(original_version_file_name) ) - keep_version_file = code_model.options['keep_version_file'] + keep_version_file = self.code_model.options['keep_version_file'] if keep_version_file and _read_version_file("_version.py"): _write_version_file(original_version_file_name="_version.py") elif keep_version_file and _read_version_file("version.py"): _write_version_file(original_version_file_name="version.py") - elif code_model.options['package_version']: + elif self.code_model.options['package_version']: self._autorestapi.write_file( namespace_path / Path("_version.py"), general_serializer.serialize_version_file() ) def _serialize_and_write_top_level_folder( - self, code_model: CodeModel, env: Environment, namespace_path: Path + self, env: Environment, namespace_path: Path ) -> None: - general_serializer = GeneralSerializer(code_model=code_model, env=env, async_mode=False) + general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=False) - if code_model.rest.request_builders: + if self.code_model.rest.request_builders: self._autorestapi.write_file( namespace_path / Path("__init__.py"), general_serializer.serialize_init_file() ) @@ -280,37 +278,37 @@ def _serialize_and_write_top_level_folder( p = p.parent # Write the service client - if code_model.rest.request_builders: + if self.code_model.rest.request_builders: self._autorestapi.write_file( - namespace_path / Path(f"_{code_model.module_name}.py"), + namespace_path / Path(f"_{self.code_model.module_name}.py"), general_serializer.serialize_service_client_file() ) - if code_model.need_vendored_code: + if self.code_model.need_vendored_code: self._autorestapi.write_file( namespace_path / Path("_vendor.py"), general_serializer.serialize_vendor_file() ) - self._serialize_and_write_version_file(code_model, namespace_path, general_serializer) + self._serialize_and_write_version_file(namespace_path, general_serializer) # write the empty py.typed file self._autorestapi.write_file(namespace_path / Path("py.typed"), "# Marker file for PEP 561.") # Write the config file - if code_model.rest.request_builders: + if self.code_model.rest.request_builders: self._autorestapi.write_file( namespace_path / Path("_configuration.py"), general_serializer.serialize_config_file() ) # Write the setup file - if code_model.options["basic_setup_py"]: + if self.code_model.options["basic_setup_py"]: self._autorestapi.write_file(Path("setup.py"), general_serializer.serialize_setup_file()) def _serialize_and_write_aio_top_level_folder( - self, code_model: CodeModel, env: Environment, namespace_path: Path + self, env: Environment, namespace_path: Path ) -> None: - aio_general_serializer = GeneralSerializer(code_model=code_model, env=env, async_mode=True) + aio_general_serializer = GeneralSerializer(code_model=self.code_model, env=env, async_mode=True) aio_path = namespace_path / Path("aio") @@ -319,7 +317,7 @@ def _serialize_and_write_aio_top_level_folder( # Write the service client self._autorestapi.write_file( - aio_path / Path(f"_{code_model.module_name}.py"), + aio_path / Path(f"_{self.code_model.module_name}.py"), aio_general_serializer.serialize_service_client_file(), ) @@ -329,6 +327,6 @@ def _serialize_and_write_aio_top_level_folder( ) - def _serialize_and_write_metadata(self, code_model: CodeModel, env: Environment, namespace_path: Path) -> None: - metadata_serializer = MetadataSerializer(code_model, env) + def _serialize_and_write_metadata(self, env: Environment, namespace_path: Path) -> None: + metadata_serializer = MetadataSerializer(self.code_model, env) self._autorestapi.write_file(namespace_path / Path("_metadata.json"), metadata_serializer.serialize()) diff --git a/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenInitialLowLevel/dpgservicedriveninitiallowlevel/_llc_client.py b/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenInitialLowLevel/dpgservicedriveninitiallowlevel/_llc_client.py deleted file mode 100644 index a1cfcf0a98b..00000000000 --- a/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenInitialLowLevel/dpgservicedriveninitiallowlevel/_llc_client.py +++ /dev/null @@ -1,76 +0,0 @@ -# coding=utf-8 -# -------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# Code generated by Microsoft (R) AutoRest Code Generator. -# Changes may cause incorrect behavior and will be lost if the code is regenerated. -# -------------------------------------------------------------------------- - -from copy import deepcopy -from typing import Any, TYPE_CHECKING - -from msrest import Deserializer, Serializer - -from azure.core import PipelineClient -from azure.core.rest import HttpRequest, HttpResponse - -from ._configuration import LLCClientConfiguration - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from typing import Dict - - -class LLCClient: - """LLC Swagger, this is the initial swagger a service could do. - - :keyword endpoint: Service URL. Default value is 'http://localhost:3000'. - :paramtype endpoint: str - """ - - def __init__(self, *, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None: - - self._config = LLCClientConfiguration(**kwargs) - self._client = PipelineClient(base_url=endpoint, config=self._config, **kwargs) - - self._serialize = Serializer() - self._deserialize = Deserializer() - self._serialize.client_side_validation = False - - def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: - """Runs the network request through the client's chained policies. - - We have helper methods to create requests specific to this service in `dpgservicedriveninitiallowlevel.rest`. - Use these helper methods to create the request you pass to this method. - - >>> from dpgservicedriveninitiallowlevel.rest import params - >>> request = params.build_head_no_params_request(**kwargs) - - >>> response = client.send_request(request) - - - For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart - - :param request: The network request you want to make. Required. - :type request: ~azure.core.rest.HttpRequest - :keyword bool stream: Whether the response payload will be streamed. Defaults to False. - :return: The response of your network call. Does not do error handling on your response. - :rtype: ~azure.core.rest.HttpResponse - """ - - request_copy = deepcopy(request) - request_copy.url = self._client.format_url(request_copy.url) - return self._client.send_request(request_copy, **kwargs) - - def close(self): - # type: () -> None - self._client.close() - - def __enter__(self): - # type: () -> LLCClient - self._client.__enter__() - return self - - def __exit__(self, *exc_details): - # type: (Any) -> None - self._client.__exit__(*exc_details) diff --git a/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenInitialLowLevel/dpgservicedriveninitiallowlevel/aio/_llc_client.py b/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenInitialLowLevel/dpgservicedriveninitiallowlevel/aio/_llc_client.py deleted file mode 100644 index 076747af4c5..00000000000 --- a/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenInitialLowLevel/dpgservicedriveninitiallowlevel/aio/_llc_client.py +++ /dev/null @@ -1,72 +0,0 @@ -# coding=utf-8 -# -------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# Code generated by Microsoft (R) AutoRest Code Generator. -# Changes may cause incorrect behavior and will be lost if the code is regenerated. -# -------------------------------------------------------------------------- - -from copy import deepcopy -from typing import Any, Awaitable, TYPE_CHECKING - -from msrest import Deserializer, Serializer - -from azure.core import AsyncPipelineClient -from azure.core.rest import AsyncHttpResponse, HttpRequest - -from ._configuration import LLCClientConfiguration - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from typing import Dict - - -class LLCClient: - """LLC Swagger, this is the initial swagger a service could do. - - :keyword endpoint: Service URL. Default value is 'http://localhost:3000'. - :paramtype endpoint: str - """ - - def __init__(self, *, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None: - self._config = LLCClientConfiguration(**kwargs) - self._client = AsyncPipelineClient(base_url=endpoint, config=self._config, **kwargs) - - self._serialize = Serializer() - self._deserialize = Deserializer() - self._serialize.client_side_validation = False - - def send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: - """Runs the network request through the client's chained policies. - - We have helper methods to create requests specific to this service in `dpgservicedriveninitiallowlevel.rest`. - Use these helper methods to create the request you pass to this method. - - >>> from dpgservicedriveninitiallowlevel.rest import params - >>> request = params.build_head_no_params_request(**kwargs) - - >>> response = await client.send_request(request) - - - For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart - - :param request: The network request you want to make. Required. - :type request: ~azure.core.rest.HttpRequest - :keyword bool stream: Whether the response payload will be streamed. Defaults to False. - :return: The response of your network call. Does not do error handling on your response. - :rtype: ~azure.core.rest.AsyncHttpResponse - """ - - request_copy = deepcopy(request) - request_copy.url = self._client.format_url(request_copy.url) - return self._client.send_request(request_copy, **kwargs) - - async def close(self) -> None: - await self._client.close() - - async def __aenter__(self) -> "LLCClient": - await self._client.__aenter__() - return self - - async def __aexit__(self, *exc_details) -> None: - await self._client.__aexit__(*exc_details) diff --git a/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneLowLevel/dpgservicedrivenupdateonelowlevel/_llc_client.py b/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneLowLevel/dpgservicedrivenupdateonelowlevel/_llc_client.py deleted file mode 100644 index 20bcf314a8a..00000000000 --- a/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneLowLevel/dpgservicedrivenupdateonelowlevel/_llc_client.py +++ /dev/null @@ -1,76 +0,0 @@ -# coding=utf-8 -# -------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# Code generated by Microsoft (R) AutoRest Code Generator. -# Changes may cause incorrect behavior and will be lost if the code is regenerated. -# -------------------------------------------------------------------------- - -from copy import deepcopy -from typing import Any, TYPE_CHECKING - -from msrest import Deserializer, Serializer - -from azure.core import PipelineClient -from azure.core.rest import HttpRequest, HttpResponse - -from ._configuration import LLCClientConfiguration - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from typing import Dict - - -class LLCClient: - """LLC Swagger, this is the initial swagger a service could do. - - :keyword endpoint: Service URL. Default value is 'http://localhost:3000'. - :paramtype endpoint: str - """ - - def __init__(self, *, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None: - - self._config = LLCClientConfiguration(**kwargs) - self._client = PipelineClient(base_url=endpoint, config=self._config, **kwargs) - - self._serialize = Serializer() - self._deserialize = Deserializer() - self._serialize.client_side_validation = False - - def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: - """Runs the network request through the client's chained policies. - - We have helper methods to create requests specific to this service in `dpgservicedrivenupdateonelowlevel.rest`. - Use these helper methods to create the request you pass to this method. - - >>> from dpgservicedrivenupdateonelowlevel.rest import params - >>> request = params.build_head_no_params_request(new_parameter=new_parameter, **kwargs) - - >>> response = client.send_request(request) - - - For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart - - :param request: The network request you want to make. Required. - :type request: ~azure.core.rest.HttpRequest - :keyword bool stream: Whether the response payload will be streamed. Defaults to False. - :return: The response of your network call. Does not do error handling on your response. - :rtype: ~azure.core.rest.HttpResponse - """ - - request_copy = deepcopy(request) - request_copy.url = self._client.format_url(request_copy.url) - return self._client.send_request(request_copy, **kwargs) - - def close(self): - # type: () -> None - self._client.close() - - def __enter__(self): - # type: () -> LLCClient - self._client.__enter__() - return self - - def __exit__(self, *exc_details): - # type: (Any) -> None - self._client.__exit__(*exc_details) diff --git a/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneLowLevel/dpgservicedrivenupdateonelowlevel/aio/_llc_client.py b/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneLowLevel/dpgservicedrivenupdateonelowlevel/aio/_llc_client.py deleted file mode 100644 index eee2b2ca4a1..00000000000 --- a/test/dpg/low-level/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneLowLevel/dpgservicedrivenupdateonelowlevel/aio/_llc_client.py +++ /dev/null @@ -1,72 +0,0 @@ -# coding=utf-8 -# -------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# Code generated by Microsoft (R) AutoRest Code Generator. -# Changes may cause incorrect behavior and will be lost if the code is regenerated. -# -------------------------------------------------------------------------- - -from copy import deepcopy -from typing import Any, Awaitable, TYPE_CHECKING - -from msrest import Deserializer, Serializer - -from azure.core import AsyncPipelineClient -from azure.core.rest import AsyncHttpResponse, HttpRequest - -from ._configuration import LLCClientConfiguration - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from typing import Dict - - -class LLCClient: - """LLC Swagger, this is the initial swagger a service could do. - - :keyword endpoint: Service URL. Default value is 'http://localhost:3000'. - :paramtype endpoint: str - """ - - def __init__(self, *, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None: - self._config = LLCClientConfiguration(**kwargs) - self._client = AsyncPipelineClient(base_url=endpoint, config=self._config, **kwargs) - - self._serialize = Serializer() - self._deserialize = Deserializer() - self._serialize.client_side_validation = False - - def send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: - """Runs the network request through the client's chained policies. - - We have helper methods to create requests specific to this service in `dpgservicedrivenupdateonelowlevel.rest`. - Use these helper methods to create the request you pass to this method. - - >>> from dpgservicedrivenupdateonelowlevel.rest import params - >>> request = params.build_head_no_params_request(new_parameter=new_parameter, **kwargs) - - >>> response = await client.send_request(request) - - - For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart - - :param request: The network request you want to make. Required. - :type request: ~azure.core.rest.HttpRequest - :keyword bool stream: Whether the response payload will be streamed. Defaults to False. - :return: The response of your network call. Does not do error handling on your response. - :rtype: ~azure.core.rest.AsyncHttpResponse - """ - - request_copy = deepcopy(request) - request_copy.url = self._client.format_url(request_copy.url) - return self._client.send_request(request_copy, **kwargs) - - async def close(self) -> None: - await self._client.close() - - async def __aenter__(self) -> "LLCClient": - await self._client.__aenter__() - return self - - async def __aexit__(self, *exc_details) -> None: - await self._client.__aexit__(*exc_details) From 67f014be528e65e4766e4b78e41606ac103c7fff Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 15 Feb 2022 18:59:22 -0500 Subject: [PATCH 2/2] pylint --- autorest/codegen/serializers/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/autorest/codegen/serializers/__init__.py b/autorest/codegen/serializers/__init__.py index 05d001c8238..25cd4dd9ec6 100644 --- a/autorest/codegen/serializers/__init__.py +++ b/autorest/codegen/serializers/__init__.py @@ -45,7 +45,9 @@ def serialize(self) -> None: ) namespace_path = ( - Path(".") if self.code_model.options["no_namespace_folders"] else Path(*(self.code_model.namespace.split("."))) + Path(".") + if self.code_model.options["no_namespace_folders"] + else Path(*(self.code_model.namespace.split("."))) ) # if there was a patch file before, we keep it @@ -87,10 +89,12 @@ def _serialize_and_write_models_folder(self, env: Environment, namespace_path: P if self.code_model.schemas: if not self.code_model.options['python3_only']: self._autorestapi.write_file( - models_path / Path("_models.py"), ModelGenericSerializer(code_model=self.code_model, env=env).serialize() + models_path / Path("_models.py"), + ModelGenericSerializer(code_model=self.code_model, env=env).serialize() ) self._autorestapi.write_file( - models_path / Path("_models_py3.py"), ModelPython3Serializer(code_model=self.code_model, env=env).serialize() + models_path / Path("_models_py3.py"), + ModelPython3Serializer(code_model=self.code_model, env=env).serialize() ) if self.code_model.enums: self._autorestapi.write_file( @@ -215,7 +219,9 @@ def _serialize_and_write_operations_folder( # write async operations init file if not self.code_model.options["no_async"]: - operations_async_init_serializer = OperationsInitSerializer(code_model=self.code_model, env=env, async_mode=True) + operations_async_init_serializer = OperationsInitSerializer( + code_model=self.code_model, env=env, async_mode=True + ) self._autorestapi.write_file( namespace_path / Path("aio") / Path(self.code_model.operations_folder_name) / Path("__init__.py"), operations_async_init_serializer.serialize(),