From 018e5c6cb431791aff40e5eb8267b133ce31dae9 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 29 Apr 2026 13:45:28 +0800 Subject: [PATCH 1/3] revert wrong code about generation-subdir --- .../generator/pygen/codegen/serializers/__init__.py | 9 --------- 1 file changed, 9 deletions(-) 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 a95b1fd2f27..7092019f5d0 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -180,15 +180,6 @@ def serialize(self) -> None: elif client_namespace_type.clients: # add clients folder if there are clients in this namespace self._serialize_client_and_config_files(client_namespace, client_namespace_type.clients, env) - # When generation-subdir is configured, generated code goes into a subdirectory - # (e.g., _generated/). We also need an __init__.py in the parent namespace dir - # so that the package is discoverable by find_packages() / pip install. - if self.code_model.options.get("generation-subdir"): - root_dir = self.code_model.get_root_dir() - self.write_file( - root_dir / Path("__init__.py"), - general_serializer.serialize_pkgutil_init_file(), - ) else: # add pkgutil init file if no clients in this namespace self.write_file( From 40f2703f6b4680f14eddfa2a8ac4d78f9e2312b6 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 29 Apr 2026 13:46:55 +0800 Subject: [PATCH 2/3] revert wrong code about generation-subdir --- .chronus/changes/revert-wrong-code-2026-3-29-13-46-47.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/revert-wrong-code-2026-3-29-13-46-47.md diff --git a/.chronus/changes/revert-wrong-code-2026-3-29-13-46-47.md b/.chronus/changes/revert-wrong-code-2026-3-29-13-46-47.md new file mode 100644 index 00000000000..49c3d6012e0 --- /dev/null +++ b/.chronus/changes/revert-wrong-code-2026-3-29-13-46-47.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Revert wrong code to avoid overwrite customized code when generation-subdir is set \ No newline at end of file From 65ebbbb79f80138ba95c187a2cf3492b7b69583c Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 29 Apr 2026 06:31:25 +0000 Subject: [PATCH 3/3] update --- .../generator/pygen/codegen/serializers/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 7092019f5d0..37657b08b29 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -180,6 +180,17 @@ def serialize(self) -> None: elif client_namespace_type.clients: # add clients folder if there are clients in this namespace self._serialize_client_and_config_files(client_namespace, client_namespace_type.clients, env) + # When generation-subdir is configured, generated code goes into a subdirectory + # (e.g., _generated/). We also need an __init__.py in the parent namespace dir + # so that the package is discoverable by find_packages() / pip install. + root_dir = self.code_model.get_root_dir() + if self.code_model.options.get("generation-subdir") and not self.read_file( + root_dir / Path("__init__.py") + ): + self.write_file( + root_dir / Path("__init__.py"), + general_serializer.serialize_pkgutil_init_file(), + ) else: # add pkgutil init file if no clients in this namespace self.write_file(