From e4f05c75515f8eb4b93d2bf5b93f11f620a155d2 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Thu, 23 Jan 2025 11:46:09 +0800 Subject: [PATCH 1/2] Fix for scenario that output folder is different with namespace --- packages/http-client-python/CHANGELOG.md | 6 ++++++ .../generator/pygen/codegen/serializers/__init__.py | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/http-client-python/CHANGELOG.md b/packages/http-client-python/CHANGELOG.md index 231d016ec4e..1abc43c233e 100644 --- a/packages/http-client-python/CHANGELOG.md +++ b/packages/http-client-python/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log - @typespec/http-client-python +## 0.6.8 + +### Bug Fixes + +- Fix for scenario that output folder is different with namespace + ## 0.6.7 ### Bug Fixes diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py index 3cf6e1a7c30..0701f4602f7 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -479,7 +479,12 @@ def exec_path_compensation(self) -> Path: else Path(".") ) + def exec_path_for_test_sample(self, namespace: str) -> Path: + return self.exec_path_compensation / Path(*namespace.split(".")) + def exec_path(self, namespace: str) -> Path: + if self.code_model.options["no_namespace_folders"]: + return Path(".") return self.exec_path_compensation / Path(*namespace.split(".")) @property @@ -492,7 +497,7 @@ def _additional_folder(self) -> Path: return Path("") def _serialize_and_write_sample(self, env: Environment, namespace: str): - out_path = self.exec_path(namespace) / Path("generated_samples") + out_path = self.exec_path_for_test_sample(namespace) / Path("generated_samples") for client in self.code_model.clients: for op_group in client.operation_groups: for operation in op_group.operations: @@ -526,7 +531,7 @@ def _serialize_and_write_sample(self, env: Environment, namespace: str): def _serialize_and_write_test(self, env: Environment, namespace: str): self.code_model.for_test = True - out_path = self.exec_path(namespace) / Path("generated_tests") + out_path = self.exec_path_for_test_sample(namespace) / Path("generated_tests") general_serializer = TestGeneralSerializer(code_model=self.code_model, env=env) self.write_file(out_path / "conftest.py", general_serializer.serialize_conftest()) if not self.code_model.options["azure_arm"]: From b0c7262640ad196f6e29f28ec2201773823f53c5 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Thu, 23 Jan 2025 16:52:47 +0800 Subject: [PATCH 2/2] fix for multiapi --- .../generator/pygen/codegen/serializers/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py index 0701f4602f7..99fa85c430c 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -483,7 +483,7 @@ def exec_path_for_test_sample(self, namespace: str) -> Path: return self.exec_path_compensation / Path(*namespace.split(".")) def exec_path(self, namespace: str) -> Path: - if self.code_model.options["no_namespace_folders"]: + if self.code_model.options["no_namespace_folders"] and not self.code_model.options["multiapi"]: return Path(".") return self.exec_path_compensation / Path(*namespace.split("."))