Skip to content

Commit 46a6e77

Browse files
authored
[python] Revert wrong code to avoid overwrite customized code when generation-subdir is set (#10545)
context: https://github.com/microsoft/typespec/pull/10323/changes#r3158779375
1 parent ef14bdf commit 46a6e77

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
Revert wrong code to avoid overwrite customized code when generation-subdir is set

packages/http-client-python/generator/pygen/codegen/serializers/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ def serialize(self) -> None:
183183
# When generation-subdir is configured, generated code goes into a subdirectory
184184
# (e.g., _generated/). We also need an __init__.py in the parent namespace dir
185185
# so that the package is discoverable by find_packages() / pip install.
186-
if self.code_model.options.get("generation-subdir"):
187-
root_dir = self.code_model.get_root_dir()
186+
root_dir = self.code_model.get_root_dir()
187+
if self.code_model.options.get("generation-subdir") and not self.read_file(
188+
root_dir / Path("__init__.py")
189+
):
188190
self.write_file(
189191
root_dir / Path("__init__.py"),
190192
general_serializer.serialize_pkgutil_init_file(),

0 commit comments

Comments
 (0)