diff --git a/.chronus/changes/python-preserveCondaPyproject-2026-0-27-16-36-38.md b/.chronus/changes/python-preserveCondaPyproject-2026-0-27-16-36-38.md new file mode 100644 index 00000000000..c97a909642a --- /dev/null +++ b/.chronus/changes/python-preserveCondaPyproject-2026-0-27-16-36-38.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Don't remove azure-sdk tool definitions from pyproject.toml \ No newline at end of file diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py index 2a015351cd4..54fe489920d 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py @@ -75,9 +75,11 @@ def external_lib_version_map(self, file_content: str, additional_version_map: di # If parsing the pyproject.toml fails, we assume the it does not exist or is incorrectly formatted. return result - # Keep "azure-sdk-build" and "packaging" configuration - if "tool" in loaded_pyproject_toml and "azure-sdk-build" in loaded_pyproject_toml["tool"]: - result["KEEP_FIELDS"]["tool.azure-sdk-build"] = loaded_pyproject_toml["tool"]["azure-sdk-build"] + # Keep "azure-sdk-*" and "packaging" configuration + if "tool" in loaded_pyproject_toml: + for key in loaded_pyproject_toml["tool"]: + if key.startswith("azure-sdk"): + result["KEEP_FIELDS"][f"tool.{key}"] = loaded_pyproject_toml["tool"][key] if "packaging" in loaded_pyproject_toml: result["KEEP_FIELDS"]["packaging"] = loaded_pyproject_toml["packaging"] diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 index c609d79b486..5cc41d91cb9 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 @@ -109,13 +109,17 @@ exclude = [ [tool.setuptools.package-data] pytyped = ["py.typed"] {% endif %} -{% if KEEP_FIELDS and KEEP_FIELDS.get('tool.azure-sdk-build') %} +{% if KEEP_FIELDS %} +{% for field_key, field_val in KEEP_FIELDS.items() %} +{% if field_key.startswith('tool.azure-sdk') %} -[tool.azure-sdk-build] -{% for key, val in KEEP_FIELDS.get('tool.azure-sdk-build').items() %} +[{{ field_key }}] +{% for key, val in field_val.items() %} {{ key }} = {{ val|tojson }} {% endfor %} {% endif %} +{% endfor %} +{% endif %} {% if KEEP_FIELDS and KEEP_FIELDS.get('packaging') %} [packaging]