Skip to content

[cadl-python] fix import and _vendor.py for subclient #1649

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

Merged
merged 5 commits into from
Jan 5, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def need_validation(self) -> bool:
def imports(self, async_mode: bool) -> FileImport:
file_import = FileImport()

relative_path = "..." if async_mode else ".."
relative_path = ("..." if async_mode else "..") + (
"." if self.client.is_subclient else ""
)
for operation in self.operations:
file_import.merge(
operation.imports(async_mode, relative_path=relative_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def _serialize_and_write_top_level_folder(
if self.code_model.need_vendored_code(async_mode=False):
self.write_file(
namespace_path / Path("_vendor.py"),
general_serializer.serialize_vendor_file(),
general_serializer.serialize_vendor_file(clients),
)

self._serialize_and_write_version_file(namespace_path, general_serializer)
Expand Down Expand Up @@ -521,7 +521,7 @@ def _serialize_and_write_aio_top_level_folder(
if self.code_model.need_vendored_code(async_mode=True):
self.write_file(
aio_path / Path("_vendor.py"),
aio_general_serializer.serialize_vendor_file(),
aio_general_serializer.serialize_vendor_file(clients),
)

def _serialize_and_write_metadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def serialize_service_client_file(self, clients: List[Client]) -> str:
imports=FileImportSerializer(imports),
)

def serialize_vendor_file(self) -> str:
def serialize_vendor_file(self, clients: List[Client]) -> str:
template = self.env.get_template("vendor.py.jinja2")

# configure imports
Expand Down Expand Up @@ -128,7 +128,7 @@ def serialize_vendor_file(self) -> str:
MsrestImportType.SerializerDeserializer,
TypingSection.TYPING,
)
for client in self.code_model.clients:
for client in clients:
file_import.add_submodule_import(
"._configuration",
f"{client.name}Configuration",
Expand All @@ -141,6 +141,7 @@ def serialize_vendor_file(self) -> str:
file_import,
),
async_mode=self.async_mode,
clients=clients,
)

def serialize_config_file(self, clients: List[Client]) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _format_url_section(template, **kwargs):
template = "/".join(components)
{% endif %}
{% if code_model.need_mixin_abc %}
{% for client in code_model.clients | selectattr("has_mixin") %}
{% for client in clients | selectattr("has_mixin") %}

class {{ client.name }}MixinABC(ABC):
"""DO NOT use this class. It is for internal typing use only."""
Expand Down
9 changes: 7 additions & 2 deletions packages/cadl-python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Release History

## 2022-12-16 - 0.4.15
## 2023-01-XX - 0.4.15
Copy link
Member Author

Choose a reason for hiding this comment

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


**Other Changes**

- Support multiple authentication #1626

**Bug Fixes**

- Fix requirement on presence of `cadl-output` folder #1622
- Fix requirement on presence of `cadl-output` folder #1622
- Fix import and _vendor for subnamespace #1649

## 2022-12-15 - 0.4.14

Expand Down