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

[python] Add test for typespec namespace #5574

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

msyyc
Copy link
Contributor

@msyyc msyyc commented Jan 13, 2025

Fix Azure/autorest.python#2998

  • Open feature of typespec namespace for some packages when flavor=unbranded
  • Update test case to adopt the change after enabling typespec namespace for unbranded test
  • Fix some import issues found when adding test

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Jan 13, 2025
@azure-sdk
Copy link
Collaborator

No changes needing a change description found.

@azure-sdk
Copy link
Collaborator

azure-sdk commented Jan 13, 2025

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs 🛝 VSCode Extension

@@ -159,7 +159,9 @@ def serialize(self) -> None:
self._serialize_and_write_top_level_folder(env=env, namespace=client_namespace)

# add models folder if there are models in this namespace
if (client_namespace_type.models or client_namespace_type.enums) and self.code_model.options["models_mode"]:
if (
self.code_model.has_non_json_models(client_namespace_type.models) or client_namespace_type.enums
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When there are only json models which will not be serialized, we shall skip the serialization for models.

Copy link
Member

Choose a reason for hiding this comment

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

can you explain this logic more clearly? I'm having a hard time following this and also only writing the models file below if there are non-json models

@@ -6,7 +6,9 @@
{{ imports }}
{{ unset }}
{% if code_model.options["builders_visibility"] == "embedded" and not async_mode %}
{% if need_declare_serializer %}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix unused declaration for __SERIALIZER = Serializer()

@msyyc msyyc changed the title [python] Add test for typespec namespace (not ready to review) [python] Add test for typespec namespace Jan 14, 2025
@@ -452,7 +456,7 @@ def imports( # pylint: disable=too-many-branches, disable=too-many-statements
file_import.add_import("json", ImportType.STDLIB)
if any(xml_serializable(str(r.default_content_type)) for r in self.responses):
file_import.add_submodule_import(relative_path, "_deserialize_xml", ImportType.LOCAL)
elif any(r.type for r in self.responses):
elif self.need_deserialize:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix unused import _deserialize.

@@ -159,7 +159,9 @@ def serialize(self) -> None:
self._serialize_and_write_top_level_folder(env=env, namespace=client_namespace)

# add models folder if there are models in this namespace
if (client_namespace_type.models or client_namespace_type.enums) and self.code_model.options["models_mode"]:
if (
self.code_model.has_non_json_models(client_namespace_type.models) or client_namespace_type.enums
Copy link
Member

Choose a reason for hiding this comment

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

can you explain this logic more clearly? I'm having a hard time following this and also only writing the models file below if there are non-json models

Copy link
Member

Choose a reason for hiding this comment

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

why did all of these files move from generic -> azure? does it have to do with azure-http-specs? I wasn't here for the change, so am a little lost here

result = client.property.float_seconds(FloatSecondsDurationProperty(value=35.625))
assert abs(result.value - 35.625) < 0.0001
result = client.property.float64_seconds(FloatSecondsDurationProperty(value=35.625))
assert abs(result.value - 35.625) < 0.0001
Copy link
Member

Choose a reason for hiding this comment

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

why are we splitting the existing generic tests into azure and unbranded?

}

// when package name is different with typespec namespace, disable typespec namespace
if (flavor !== "azure") {
Copy link
Member

Choose a reason for hiding this comment

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

i'm lost why we have this default flag setting in regenerate.ts. Why are we not relying on the default behavior in our emitter, and where needed, change enable-typespec-namespace to be the value we want to be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emitter:client:python Issue for the Python client emitter: @typespec/http-client-python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more test for feature that supports typespec namespace
3 participants