From 44386aa54e165dfedcfcdad38114acfb299ad5d4 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 23 Jul 2025 02:05:43 +0000 Subject: [PATCH 1/3] don't overwrite existing __init__ --- .../generator/pygen/codegen/serializers/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 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 d3a3766479a..5c2f8178934 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -153,8 +153,8 @@ 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) - else: - # add pkgutil init file if no clients in this namespace + elif not self.read_file(exec_path / Path("__init__.py")): + # add pkgutil init file if no clients in this namespace and no existing __init__.py file self.write_file( exec_path / Path("__init__.py"), general_serializer.serialize_pkgutil_init_file(), From 72140e14427eb1898d519159a65d0f1dc1e6e4a9 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 23 Jul 2025 02:07:08 +0000 Subject: [PATCH 2/3] add changelog --- .../python-fix-customized-namespace-2025-6-23-2-6-58.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/python-fix-customized-namespace-2025-6-23-2-6-58.md diff --git a/.chronus/changes/python-fix-customized-namespace-2025-6-23-2-6-58.md b/.chronus/changes/python-fix-customized-namespace-2025-6-23-2-6-58.md new file mode 100644 index 00000000000..09a243cadca --- /dev/null +++ b/.chronus/changes/python-fix-customized-namespace-2025-6-23-2-6-58.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Don't overwrite existing pkgutil init file \ No newline at end of file From c32e4bdf4a66ce9abebf691d727fd4ed56efa5a9 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 23 Jul 2025 02:23:20 +0000 Subject: [PATCH 3/3] udpate --- .../generator/pygen/codegen/serializers/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 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 5c2f8178934..4c8f68b520c 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -153,12 +153,14 @@ 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) - elif not self.read_file(exec_path / Path("__init__.py")): - # add pkgutil init file if no clients in this namespace and no existing __init__.py file - self.write_file( - exec_path / Path("__init__.py"), - general_serializer.serialize_pkgutil_init_file(), + else: + # add/keep pkgutil init file if no clients in this namespace + init_path = exec_path / Path("__init__.py") + original_init_content = self.read_file(init_path) + init_content = ( + original_init_content if original_init_content else general_serializer.serialize_pkgutil_init_file() ) + self.write_file(init_path, init_content) # _utils/py.typed/_types.py/_validation.py # is always put in top level namespace