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

Bump cadl ranch 0.37.1 #2815

Merged
merged 10 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .chronus/changes/bump-cadl-ranch-2024-2024-8-5-17-18-29.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/typespec-python"
---

Add support for `HttpPart<{@body body: XXX}>` of multipart
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"homepage": "https://github.com/Azure/autorest.python#readme",
"devDependencies": {
"@actions/github": "6.0.0",
"@azure-tools/cadl-ranch": "~0.14.2",
"@azure-tools/cadl-ranch": "~0.14.5",
"@chronus/chronus": "^0.10.2",
"@chronus/github": "^0.3.2",
"@typespec/prettier-plugin-typespec": "~0.58.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ def entries(self) -> List["BodyParameter"]:
def is_form_data(self) -> bool:
# hacky, but rn in legacy, there is no formdata model type, it's just a dict
# with all of the entries splatted out
return self.type.is_form_data or bool(self.entries)
return (
self.type.is_form_data
or bool(self.entries)
or ("multipart/form-data" in self.content_types and self.code_model.options["from_typespec"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to check if it's "from_typespec". We should also remove this option and deal with the differences earlier on in the pipeline

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without from_typespec, there will be diff for legacy code under autorest.python folder. Since multipart is mainly for typespec design, I think we had better keep legacy same as before.

)

@property
def is_partial_body(self) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def __init__(
self.operation = operation
self.is_async = is_async

@property
def name(self) -> str:
if self.operation_groups[-1].is_mixin:
return self.operation.name
return "_".join([og.property_name for og in self.operation_groups] + [self.operation.name])

@property
def operation_group_prefix(self) -> str:
if self.operation_groups[-1].is_mixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class {{ test.test_class_name }}({{ test.base_test_class_name }}):
{% endif %}
@recorded_by_proxy{{ async_suffix }}
{% if code_model.options["azure_arm"] %}
{{ async }}def test_{{ testcase.operation.name }}(self, resource_group):
{{ async }}def test_{{ testcase.name }}(self, resource_group):
{% else %}
{{ async }}def test_{{ testcase.operation.name }}(self, {{ prefix_lower }}_endpoint):
{{ async }}def test_{{ testcase.name }}(self, {{ prefix_lower }}_endpoint):
{{ client_var }} = self.{{ test.create_client_name }}(endpoint={{ prefix_lower }}_endpoint)
{% endif %}
{{testcase.response }}{{ client_var }}{{ testcase.operation_group_prefix }}.{{ testcase.operation.name }}(
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
"devDependencies": {
"@azure-tools/typespec-azure-resource-manager": "~0.45.0",
"@azure-tools/typespec-autorest": "~0.45.0",
"@azure-tools/cadl-ranch-expect": "~0.15.1",
"@azure-tools/cadl-ranch-specs": "~0.36.1",
"@azure-tools/cadl-ranch-expect": "~0.15.3",
"@azure-tools/cadl-ranch-specs": "~0.37.1",
"@types/js-yaml": "~4.0.5",
"@types/node": "^18.16.3",
"@types/yargs": "17.0.32",
Expand Down
3 changes: 0 additions & 3 deletions packages/typespec-python/scripts/eng/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ const EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, st
"type/model/empty": {
"package-name": "typetest-model-empty",
},
"type/model/flatten": {
"package-name": "typetest-model-flatten",
},
"type/model/inheritance/enum-discriminator": {
"package-name": "typetest-model-enumdiscriminator",
},
Expand Down
11 changes: 10 additions & 1 deletion packages/typespec-python/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,16 @@ function emitProperty<TServiceOperation extends SdkServiceOperation>(
property: SdkBodyModelPropertyType,
): Record<string, any> {
const isMultipartFileInput = property.multipartOptions?.isFilePart;
const sourceType = isMultipartFileInput ? createMultiPartFileType(property.type) : property.type;
let sourceType: SdkType | MultiPartFileType = property.type;
if (isMultipartFileInput) {
sourceType = createMultiPartFileType(property.type);
} else if (property.type.kind === "model") {
const body = property.type.properties.find((x) => x.kind === "body");
if (body) {
// for `temperature: HttpPart<{@body body: float64, @header contentType: "text/plain"}>`, the real type is float64
sourceType = body.type;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For temperature: HttpPart<{@body body: float64, @header contentType: "text/plain"}>, TCGC provide model of {@body body: float64, @header contentType: "text/plain"} while python emitter actually only need float64 so we need to parse it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it bad that we have contentType? I'm thinking we still just pass it through. But I'm good either way

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpPart permit us to define more specific info for this part. In this case @header contentType: "text/plain" means SDK shall serialize the float64 as plain string instead of json string. Although both actually send same content, JS owner thought we shall add the specific info in the cadl-ranch case then I just added it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I raise an issue Azure/typespec-azure#1488. If all languages agree Azure/typespec-azure#1488 (comment), TCGC could do the parse logic so that emitters don't need the duplicated work any more.

if (isMultipartFileInput) {
// Python convert all the type of file part to FileType so clear these models' usage so that they won't be generated
addDisableGenerationMap(property.type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class TestAccessPublicOperationOperations(AccessClientTestBase):
@AccessPreparer()
@recorded_by_proxy
def test_no_decorator_in_public(self, access_endpoint):
def test_public_operation_no_decorator_in_public(self, access_endpoint):
client = self.create_client(endpoint=access_endpoint)
response = client.public_operation.no_decorator_in_public(
name="str",
Expand All @@ -25,7 +25,7 @@ def test_no_decorator_in_public(self, access_endpoint):

@AccessPreparer()
@recorded_by_proxy
def test_public_decorator_in_public(self, access_endpoint):
def test_public_operation_public_decorator_in_public(self, access_endpoint):
client = self.create_client(endpoint=access_endpoint)
response = client.public_operation.public_decorator_in_public(
name="str",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TestAccessPublicOperationOperationsAsync(AccessClientTestBaseAsync):
@AccessPreparer()
@recorded_by_proxy_async
async def test_no_decorator_in_public(self, access_endpoint):
async def test_public_operation_no_decorator_in_public(self, access_endpoint):
client = self.create_async_client(endpoint=access_endpoint)
response = await client.public_operation.no_decorator_in_public(
name="str",
Expand All @@ -26,7 +26,7 @@ async def test_no_decorator_in_public(self, access_endpoint):

@AccessPreparer()
@recorded_by_proxy_async
async def test_public_decorator_in_public(self, access_endpoint):
async def test_public_operation_public_decorator_in_public(self, access_endpoint):
client = self.create_async_client(endpoint=access_endpoint)
response = await client.public_operation.public_decorator_in_public(
name="str",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class TestAccessSharedModelInOperationOperations(AccessClientTestBase):
@AccessPreparer()
@recorded_by_proxy
def test_public(self, access_endpoint):
def test_shared_model_in_operation_public(self, access_endpoint):
client = self.create_client(endpoint=access_endpoint)
response = client.shared_model_in_operation.public(
name="str",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TestAccessSharedModelInOperationOperationsAsync(AccessClientTestBaseAsync):
@AccessPreparer()
@recorded_by_proxy_async
async def test_public(self, access_endpoint):
async def test_shared_model_in_operation_public(self, access_endpoint):
client = self.create_async_client(endpoint=access_endpoint)
response = await client.shared_model_in_operation.public(
name="str",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
include *.md
include LICENSE
include azure/clientgenerator/core/flattenproperty/py.typed
include specs/azure/clientgenerator/core/flattenproperty/py.typed
recursive-include tests *.py
recursive-include samples *.py *.md
include azure/__init__.py
include azure/clientgenerator/__init__.py
include azure/clientgenerator/core/__init__.py
include specs/__init__.py
include specs/azure/__init__.py
include specs/azure/clientgenerator/__init__.py
include specs/azure/clientgenerator/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@


# Azure Clientgenerator Core Flattenproperty client library for Python
# Specs Azure Clientgenerator Core Flattenproperty client library for Python
<!-- write necessary description of service -->

## Getting started

### Install the package

```bash
python -m pip install azure-clientgenerator-core-flattenproperty
python -m pip install specs-azure-clientgenerator-core-flattenproperty
```

#### Prequisites

- Python 3.8 or later is required to use this package.
- You need an [Azure subscription][azure_sub] to use this package.
- An existing Azure Clientgenerator Core Flattenproperty instance.
- An existing Specs Azure Clientgenerator Core Flattenproperty instance.

## Contributing

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"CrossLanguagePackageId": "Azure.ClientGenerator.Core.FlattenProperty",
"CrossLanguagePackageId": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty",
"CrossLanguageDefinitionId": {
"azure.clientgenerator.core.flattenproperty.models.ChildFlattenModel": "Azure.ClientGenerator.Core.FlattenProperty.ChildFlattenModel",
"azure.clientgenerator.core.flattenproperty.models.ChildModel": "Azure.ClientGenerator.Core.FlattenProperty.ChildModel",
"azure.clientgenerator.core.flattenproperty.models.FlattenModel": "Azure.ClientGenerator.Core.FlattenProperty.FlattenModel",
"azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel": "Azure.ClientGenerator.Core.FlattenProperty.NestedFlattenModel",
"azure.clientgenerator.core.flattenproperty.FlattenPropertyClient.put_flatten_model": "Azure.ClientGenerator.Core.FlattenProperty.putFlattenModel",
"azure.clientgenerator.core.flattenproperty.FlattenPropertyClient.put_nested_flatten_model": "Azure.ClientGenerator.Core.FlattenProperty.putNestedFlattenModel"
"specs.azure.clientgenerator.core.flattenproperty.models.ChildFlattenModel": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.ChildFlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.models.ChildModel": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.ChildModel",
"specs.azure.clientgenerator.core.flattenproperty.models.FlattenModel": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.FlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.NestedFlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.FlattenPropertyClient.put_flatten_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putFlattenModel",
"specs.azure.clientgenerator.core.flattenproperty.FlattenPropertyClient.put_nested_flatten_model": "_Specs_.Azure.ClientGenerator.Core.FlattenProperty.putNestedFlattenModel"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from azure.clientgenerator.core.flattenproperty import FlattenPropertyClient
from devtools_testutils import AzureRecordedTestCase, PowerShellPreparer
import functools
from specs.azure.clientgenerator.core.flattenproperty import FlattenPropertyClient


class FlattenPropertyClientTestBase(AzureRecordedTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from azure.clientgenerator.core.flattenproperty.aio import FlattenPropertyClient
from devtools_testutils import AzureRecordedTestCase
from specs.azure.clientgenerator.core.flattenproperty.aio import FlattenPropertyClient


class FlattenPropertyClientTestBaseAsync(AzureRecordedTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from setuptools import setup, find_packages


PACKAGE_NAME = "azure-clientgenerator-core-flattenproperty"
PACKAGE_PPRINT_NAME = "Azure Clientgenerator Core Flattenproperty"
PACKAGE_NAME = "specs-azure-clientgenerator-core-flattenproperty"
PACKAGE_PPRINT_NAME = "Specs Azure Clientgenerator Core Flattenproperty"

# a-b-c => a/b/c
package_folder_path = PACKAGE_NAME.replace("-", "/")
Expand Down Expand Up @@ -54,14 +54,15 @@
exclude=[
"tests",
# Exclude packages that will be covered by PEP420 or nspkg
"azure",
"azure.clientgenerator",
"azure.clientgenerator.core",
"specs",
"specs.azure",
"specs.azure.clientgenerator",
"specs.azure.clientgenerator.core",
]
),
include_package_data=True,
package_data={
"azure.clientgenerator.core.flattenproperty": ["py.typed"],
"specs.azure.clientgenerator.core.flattenproperty": ["py.typed"],
},
install_requires=[
"isodate>=0.6.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FlattenPropertyClientConfiguration: # pylint: disable=too-many-instance-a
def __init__(self, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None:

self.endpoint = endpoint
kwargs.setdefault("sdk_moniker", "clientgenerator-core-flattenproperty/{}".format(VERSION))
kwargs.setdefault("sdk_moniker", "specs-azure-clientgenerator-core-flattenproperty/{}".format(VERSION))
self.polling_interval = kwargs.get("polling_interval", 30)
self._configure(**kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ def put_flatten_model(
"""put_flatten_model.

:param input: Required.
:type input: ~azure.clientgenerator.core.flattenproperty.models.FlattenModel
:type input: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenModel
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/json".
:paramtype content_type: str
:return: FlattenModel. The FlattenModel is compatible with MutableMapping
:rtype: ~azure.clientgenerator.core.flattenproperty.models.FlattenModel
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenModel
:raises ~azure.core.exceptions.HttpResponseError:
"""

Expand All @@ -109,7 +109,7 @@ def put_flatten_model(
Default value is "application/json".
:paramtype content_type: str
:return: FlattenModel. The FlattenModel is compatible with MutableMapping
:rtype: ~azure.clientgenerator.core.flattenproperty.models.FlattenModel
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenModel
:raises ~azure.core.exceptions.HttpResponseError:
"""

Expand All @@ -125,7 +125,7 @@ def put_flatten_model(
Default value is "application/json".
:paramtype content_type: str
:return: FlattenModel. The FlattenModel is compatible with MutableMapping
:rtype: ~azure.clientgenerator.core.flattenproperty.models.FlattenModel
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenModel
:raises ~azure.core.exceptions.HttpResponseError:
"""

Expand All @@ -136,10 +136,10 @@ def put_flatten_model(
"""put_flatten_model.

:param input: Is one of the following types: FlattenModel, JSON, IO[bytes] Required.
:type input: ~azure.clientgenerator.core.flattenproperty.models.FlattenModel or JSON or
:type input: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenModel or JSON or
IO[bytes]
:return: FlattenModel. The FlattenModel is compatible with MutableMapping
:rtype: ~azure.clientgenerator.core.flattenproperty.models.FlattenModel
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.FlattenModel
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = {
Expand Down Expand Up @@ -207,12 +207,12 @@ def put_nested_flatten_model(
"""put_nested_flatten_model.

:param input: Required.
:type input: ~azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel
:type input: ~specs.azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/json".
:paramtype content_type: str
:return: NestedFlattenModel. The NestedFlattenModel is compatible with MutableMapping
:rtype: ~azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel
:raises ~azure.core.exceptions.HttpResponseError:
"""

Expand All @@ -228,7 +228,7 @@ def put_nested_flatten_model(
Default value is "application/json".
:paramtype content_type: str
:return: NestedFlattenModel. The NestedFlattenModel is compatible with MutableMapping
:rtype: ~azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel
:raises ~azure.core.exceptions.HttpResponseError:
"""

Expand All @@ -244,7 +244,7 @@ def put_nested_flatten_model(
Default value is "application/json".
:paramtype content_type: str
:return: NestedFlattenModel. The NestedFlattenModel is compatible with MutableMapping
:rtype: ~azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel
:raises ~azure.core.exceptions.HttpResponseError:
"""

Expand All @@ -255,10 +255,10 @@ def put_nested_flatten_model(
"""put_nested_flatten_model.

:param input: Is one of the following types: NestedFlattenModel, JSON, IO[bytes] Required.
:type input: ~azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel or JSON or
IO[bytes]
:type input: ~specs.azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel or
JSON or IO[bytes]
:return: NestedFlattenModel. The NestedFlattenModel is compatible with MutableMapping
:rtype: ~azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel
:rtype: ~specs.azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FlattenPropertyClientConfiguration: # pylint: disable=too-many-instance-a
def __init__(self, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None:

self.endpoint = endpoint
kwargs.setdefault("sdk_moniker", "clientgenerator-core-flattenproperty/{}".format(VERSION))
kwargs.setdefault("sdk_moniker", "specs-azure-clientgenerator-core-flattenproperty/{}".format(VERSION))
self.polling_interval = kwargs.get("polling_interval", 30)
self._configure(**kwargs)

Expand Down
Loading
Loading