Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt whole common types in TCGC #2476

Merged
merged 75 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
8e91a9e
starting moving to tcgc before vacation
iscai-msft Nov 17, 2023
4744fb0
continued work
iscai-msft Nov 27, 2023
846693c
starting on emitting basic operation
iscai-msft Nov 28, 2023
3956edc
up to responses
Dec 2, 2023
29293e1
building
Dec 4, 2023
4aaa7e7
work on getting azure core basic test to generate
Dec 4, 2023
0e7c2b0
paging failing basic test
Dec 5, 2023
ecbd57b
can generate basic
Dec 6, 2023
03e1373
can generate basic without failing
Dec 7, 2023
2de0b32
can generate, api version and accept are not generating as kwargs
Dec 7, 2023
23d90ac
Merge branch 'main' of https://github.com/Azure/autorest.python into …
Dec 8, 2023
a3f98ca
fix some generation errors of basic
Dec 8, 2023
4e6e250
Merge remote-tracking branch 'origin/main' into getAllOperations
tadelesh Dec 11, 2023
c4eebf2
migrate client hierarchy
tadelesh Dec 12, 2023
a895162
Merge branch 'getAllOperations' of https://github.com/Azure/autorest.…
Dec 12, 2023
2bcfbfd
basic generating but content type param constant
Dec 12, 2023
28ae385
can generate azure core basic
Dec 13, 2023
0fbcc1f
working on authentication api-key
Dec 13, 2023
8da16c7
generating auth api-key correctly
Dec 14, 2023
49c5a9e
generate all authentication
Dec 14, 2023
9e8f80b
change endpoint documentation to always be service host
Dec 14, 2023
34c6d12
quick fix for flattened parameter
tadelesh Dec 15, 2023
df34ca7
generating type folder
Dec 15, 2023
bad6d03
can generate special words
Dec 15, 2023
0c14211
can generate projection
Dec 15, 2023
0e3f444
fix spread
tadelesh Dec 18, 2023
4826959
fix access
tadelesh Dec 18, 2023
2890364
generate lro
Dec 18, 2023
c08e651
can generate cadl-ranch, sphere issues
Dec 19, 2023
552e292
Merge remote-tracking branch 'origin/main' into getAllOperations
tadelesh Dec 28, 2023
ee1862a
doc change
tadelesh Dec 29, 2023
dc06405
fix regen issue
tadelesh Dec 29, 2023
931947b
get tcgc change of operation parameters
Jan 9, 2024
7b956f8
Merge branch 'main' of https://github.com/Azure/autorest.python into …
Jan 9, 2024
06b9d20
temp
Jan 11, 2024
dffe761
temp
Jan 11, 2024
aec7d7e
temp
Jan 24, 2024
655f739
Merge branch 'main' of https://github.com/Azure/autorest.python into …
Mar 12, 2024
0655959
fix regen issue
tadelesh Mar 13, 2024
5dea7ff
add check for content type parameter
Mar 13, 2024
a6dba27
Merge branch 'main' of https://github.com/Azure/autorest.python into …
Mar 14, 2024
647f10b
partial regeneration
Mar 14, 2024
f58f1f6
fix arm subscription and endpoint
tadelesh Mar 15, 2024
caccdf7
Merge remote-tracking branch 'origin/main' into getAllOperations
tadelesh Mar 21, 2024
5f57572
fix and regen
tadelesh Mar 21, 2024
ee58412
fix response default content type
tadelesh Mar 21, 2024
6f8feb5
fix client parameter issue and regen
tadelesh Mar 22, 2024
9c1e343
pass all tests
tadelesh Mar 27, 2024
2c4c4b3
Merge remote-tracking branch 'origin/main' into getAllOperations
tadelesh Mar 27, 2024
f5108fd
Merge branch 'getAllOperations' of https://github.com/Azure/autorest.…
Apr 1, 2024
1f898ca
format autorest code
Apr 1, 2024
67dfc4f
lint tsp
Apr 1, 2024
820134e
Merge branch 'main' into getAllOperations
tadelesh Apr 3, 2024
60fb283
adopt latest interface
tadelesh Apr 3, 2024
ba8713a
Merge remote-tracking branch 'origin/getAllOperations' into getAllOpe…
tadelesh Apr 3, 2024
2612fda
lint and format
tadelesh Apr 3, 2024
542c923
fix
tadelesh Apr 3, 2024
8e022e0
update to patch released autorest
Apr 5, 2024
8878e32
update deps
Apr 5, 2024
00fb811
remove projection projected name test
Apr 5, 2024
fd3a3e6
set subscription id later
Apr 5, 2024
2a95bb8
format
Apr 5, 2024
ab9ca62
fix typing for lambda responses
Apr 5, 2024
b30f6d2
generate for autorest
Apr 5, 2024
7bc0c22
update changelog
Apr 5, 2024
d2fc556
pylint
Apr 5, 2024
aa0fe45
add typing for error_map
Apr 5, 2024
27d5ab7
remove useless file
tadelesh Apr 7, 2024
0e8b94d
fix pyright and regen
tadelesh Apr 7, 2024
67bf2aa
fix lint and regen
tadelesh Apr 7, 2024
350e89a
add tests
tadelesh Apr 7, 2024
3005b1d
ignore typing check for custom error handling
tadelesh Apr 7, 2024
33de2ff
fix
tadelesh Apr 7, 2024
bfe2f89
fix and regen
tadelesh Apr 7, 2024
653ee5f
fix ci
tadelesh Apr 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"cwd": "${workspaceFolder}/packages/typespec-python",
"args": [
"compile",
"${workspaceFolder}/packages/typespec-python/main.tsp",
"${workspaceFolder}/packages/typespec-python/node_modules/@azure-tools/cadl-ranch-specs/http/server/versions/not-versioned",
"--emit",
"${workspaceFolder}/packages/typespec-python/dist/src/index.js",
"--option=@azure-tools/typespec-python.debug=true"
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
},
"homepage": "https://github.com/Azure/autorest.python#readme",
"devDependencies": {
"@azure-tools/cadl-ranch": "~0.11.3",
"@typespec/prettier-plugin-typespec": "~0.51.0",
"@azure-tools/cadl-ranch": "~0.11.2",
"autorest": "3.6.3",
"eslint": "^8.44.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-unicorn": "^46.0.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-unicorn": "^46.0.1",
"prettier": "^2.8.8",
"typescript": "~5.1.3",
"syncpack": "^9.8.6"
"syncpack": "^9.8.6",
"typescript": "~5.1.6"
},
"syncpack": {
"dependencyTypes": [
Expand Down
16 changes: 16 additions & 0 deletions packages/autorest.python/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Release

## 2024-04-05 - 6.13.9

| Library | Min Version |
| ----------------------------------------------------------------------- | ----------- |
| `@autorest/core` | `3.9.2` |
| `@autorest/modelerfour` | `4.24.3` |
| `azure-core` dep of generated code | `1.30.0` |
| `isodate` dep of generated code | `0.6.1` |
| `msrest` dep of generated code (If generating legacy code) | `0.7.1` |
| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.2` |
| `typing-extensions` dep of generated code (If generating with constants)| `4.0.1` |

**Other Changes**

- Refactor code to use the type ecosystem from "@azure-tools/typespec-client-generator-core" #2476

## 2024-03-22 - 6.13.8

| Library | Min Version |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# license information.
# --------------------------------------------------------------------------
import logging
from typing import Dict, Any, Optional, TYPE_CHECKING
from typing import Dict, Any, Optional, TYPE_CHECKING, Union
from .base import BaseType
from .imports import FileImport, ImportType, TypingSection
from .primitive_types import IntegerType, BinaryType, StringType, BooleanType
Expand All @@ -31,7 +31,7 @@ def __init__(
yaml_data: Dict[str, Any],
code_model: "CodeModel",
value_type: BaseType,
value: Optional[str],
value: Optional[Union[str, int, float]],
) -> None:
super().__init__(yaml_data=yaml_data, code_model=code_model)
self.value_type = value_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ def from_yaml(
"""
from . import build_type

enum_type = cast(EnumType, code_model.lookup_type(id(yaml_data["enumType"])))
return cls(
yaml_data=yaml_data,
code_model=code_model,
enum_type=enum_type,
enum_type=cast(EnumType, build_type(yaml_data["enumType"], code_model)),
value_type=build_type(yaml_data["valueType"], code_model),
)

Expand Down
16 changes: 16 additions & 0 deletions packages/autorest.python/autorest/codegen/models/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,18 @@ def imports( # pylint: disable=too-many-branches, disable=too-many-statements
file_import.add_submodule_import(
"azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.SDKCORE
)
file_import.add_submodule_import(
"typing",
"Type",
ImportType.STDLIB,
)
file_import.add_mutable_mapping_import()
if self.non_default_error_status_codes:
file_import.add_submodule_import(
"typing",
"cast",
ImportType.STDLIB,
)

if self.has_kwargs_to_pop_with_default(
self.parameters.kwargs_to_pop, ParameterLocation.HEADER # type: ignore
Expand Down Expand Up @@ -481,6 +493,10 @@ def imports( # pylint: disable=too-many-branches, disable=too-many-statements
)
if self.overloads:
file_import.add_submodule_import("typing", "overload", ImportType.STDLIB)
if self.non_default_errors and self.code_model.options["models_mode"] == "dpg":
file_import.add_submodule_import(
f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL
)
return file_import

def get_response_from_status(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(
type: BaseType,
) -> None:
super().__init__(yaml_data, code_model)
self.wire_name: str = yaml_data["wireName"]
self.wire_name: str = yaml_data.get("wireName", "")
self.client_name: str = self.yaml_data["clientName"]
self.optional: bool = self.yaml_data["optional"]
self.location: ParameterLocation = self.yaml_data["location"]
Expand Down Expand Up @@ -373,7 +373,7 @@ def method_location( # pylint: disable=too-many-return-statements
return ParameterMethodLocation.KEYWORD_ONLY
if self.grouper:
return ParameterMethodLocation.POSITIONAL
if self.constant:
if self.constant and self.wire_name != "Content-Type":
return ParameterMethodLocation.KWARG
if self.is_content_type:
if self.in_overload:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ def serialization_type(self) -> str:
def from_yaml(
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
) -> "ResponseHeader":
from . import build_type

return cls(
yaml_data=yaml_data,
code_model=code_model,
type=code_model.lookup_type(id(yaml_data["type"])),
type=build_type(yaml_data["type"], code_model),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ def handle_response(self, builder: OperationType) -> List[str]:
return retval

def error_map(self, builder: OperationType) -> List[str]:
retval = ["error_map = {"]
retval = ["error_map: MutableMapping[int, Type[HttpResponseError]] = {"]
if builder.non_default_errors:
if not 401 in builder.non_default_error_status_codes:
retval.append(" 401: ClientAuthenticationError,")
Expand Down Expand Up @@ -1309,30 +1309,35 @@ def error_map(self, builder: OperationType) -> List[str]:
for status_code in excep.status_codes:
if status_code == 401:
retval.append(
" 401: lambda response: ClientAuthenticationError(response=response"
f"{error_model_str}{error_format_str}),"
" 401: cast(Type[HttpResponseError], "
"lambda response: ClientAuthenticationError(response=response"
f"{error_model_str}{error_format_str})),"
)
elif status_code == 404:
retval.append(
" 404: lambda response: ResourceNotFoundError(response=response"
f"{error_model_str}{error_format_str}),"
" 404: cast(Type[HttpResponseError], "
"lambda response: ResourceNotFoundError(response=response"
f"{error_model_str}{error_format_str})),"
)
elif status_code == 409:
retval.append(
" 409: lambda response: ResourceExistsError(response=response"
f"{error_model_str}{error_format_str}),"
" 409: cast(Type[HttpResponseError], "
"lambda response: ResourceExistsError(response=response"
f"{error_model_str}{error_format_str})),"
)
elif status_code == 304:
retval.append(
" 304: lambda response: ResourceNotModifiedError(response=response"
f"{error_model_str}{error_format_str}),"
" 304: cast(Type[HttpResponseError], "
"lambda response: ResourceNotModifiedError(response=response"
f"{error_model_str}{error_format_str})),"
)
elif not error_model_str and not error_format_str:
retval.append(f" {status_code}: HttpResponseError,")
else:
retval.append(
f" {status_code}: lambda response: HttpResponseError(response=response"
f"{error_model_str}{error_format_str}),"
f" {status_code}: cast(Type[HttpResponseError], "
"lambda response: HttpResponseError(response=response"
f"{error_model_str}{error_format_str})),"
)
else:
retval.append(
Expand Down
26 changes: 17 additions & 9 deletions packages/autorest.python/autorest/preprocess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ def update_overload_section(
yaml_data: Dict[str, Any],
section: str,
):
for overload_s, original_s in zip(overload[section], yaml_data[section]):
if overload_s.get("type"):
overload_s["type"] = original_s["type"]
if overload_s.get("headers"):
for overload_h, original_h in zip(
overload_s["headers"], original_s["headers"]
):
if overload_h.get("type"):
overload_h["type"] = original_h["type"]
try:
for overload_s, original_s in zip(overload[section], yaml_data[section]):
if overload_s.get("type"):
overload_s["type"] = original_s["type"]
if overload_s.get("headers"):
for overload_h, original_h in zip(
overload_s["headers"], original_s["headers"]
):
if overload_h.get("type"):
overload_h["type"] = original_h["type"]
except KeyError as exc:
raise ValueError(overload["name"]) from exc


def add_overload(
Expand Down Expand Up @@ -390,6 +393,11 @@ def update_parameter(self, yaml_data: Dict[str, Any]) -> None:
and wire_name_lower in HEADERS_CONVERT_IN_METHOD
):
headers_convert(yaml_data, HEADERS_CONVERT_IN_METHOD[wire_name_lower])
if (
wire_name_lower in ["$host", "content-type", "accept"]
and yaml_data["type"]["type"] == "constant"
):
yaml_data["clientDefaultValue"] = yaml_data["type"]["value"]

def update_operation(
self,
Expand Down
2 changes: 1 addition & 1 deletion packages/autorest.python/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autorest/python",
"version": "6.13.8",
"version": "6.13.9",
"description": "The Python extension for generators in AutoRest.",
"scripts": {
"prepare": "node run-python3.js prepare.py",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from typing import Any, Callable, Dict, Optional, TypeVar
import sys
from typing import Any, Callable, Dict, Optional, Type, TypeVar

from azure.core.exceptions import (
ClientAuthenticationError,
Expand All @@ -26,6 +27,10 @@
build_http_success_head404_request,
)

if sys.version_info >= (3, 9):
from collections.abc import MutableMapping
else:
from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports
T = TypeVar("T")
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]

Expand Down Expand Up @@ -55,7 +60,7 @@ async def head200(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map = {
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down Expand Up @@ -98,7 +103,7 @@ async def head204(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map = {
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down Expand Up @@ -141,7 +146,7 @@ async def head404(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map = {
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from typing import Any, Callable, Dict, Optional, TypeVar
import sys
from typing import Any, Callable, Dict, Optional, Type, TypeVar

from azure.core.exceptions import (
ClientAuthenticationError,
Expand All @@ -22,6 +23,10 @@

from .._serialization import Serializer

if sys.version_info >= (3, 9):
from collections.abc import MutableMapping
else:
from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports
T = TypeVar("T")
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]

Expand Down Expand Up @@ -75,7 +80,7 @@ def head200(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-return
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map = {
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down Expand Up @@ -118,7 +123,7 @@ def head204(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-return
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map = {
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down Expand Up @@ -161,7 +166,7 @@ def head404(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-return
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map = {
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from typing import Any, Callable, Dict, Optional, TypeVar
import sys
from typing import Any, Callable, Dict, Optional, Type, TypeVar

from azure.core.exceptions import (
ClientAuthenticationError,
Expand All @@ -26,6 +27,10 @@
build_http_success_head404_request,
)

if sys.version_info >= (3, 9):
from collections.abc import MutableMapping
else:
from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports
T = TypeVar("T")
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]

Expand Down Expand Up @@ -55,7 +60,7 @@ async def head200(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map = {
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down Expand Up @@ -98,7 +103,7 @@ async def head204(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map = {
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down Expand Up @@ -141,7 +146,7 @@ async def head404(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map = {
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
Expand Down
Loading
Loading