Skip to content

fix(http-client-python): preserve customized pyproject.toml fields#10987

Merged
l0lawrence merged 8 commits into
microsoft:mainfrom
l0lawrence:l0lawrence/python-pyproject-preserve-fields
Jun 19, 2026
Merged

fix(http-client-python): preserve customized pyproject.toml fields#10987
l0lawrence merged 8 commits into
microsoft:mainfrom
l0lawrence:l0lawrence/python-pyproject-preserve-fields

Conversation

@l0lawrence

Copy link
Copy Markdown
Member

Fixes #10311

Problem

The Python emitter regenerates pyproject.toml on every emit and clobbers manual edits to fields it doesn't own — for example downcasing "AI" to "Ai" in the description, dropping Python versions from the classifiers list, and replacing a custom repository URL with the generic Azure SDK one.

Fix

Extend the existing KEEP_FIELDS preservation mechanism so the emitter preserves the following from an existing pyproject.toml instead of overwriting them:

  • project.description
  • project.classifiers
  • [project.urls]

On first emit (no existing file) these are still generated as before. When the file already exists, the user's values are carried through.

Changes

  • general_serializer.py: extract description, classifiers, and urls into KEEP_FIELDS.
  • pyproject.toml.jinja2: use preserved values when present, fall back to generated defaults otherwise.
  • Added unit tests in tests/unit/test_pyproject_keep_fields.py.
  • Added a changeset entry.

Validation

  • New unit tests pass.
  • Template renders valid TOML in both branches (verified by round-tripping through tomli).
  • Black formatting passes with the repo config.

Preserve manually customized description, classifiers, and [project.urls]

fields from an existing pyproject.toml instead of overwriting them on emit.

Fixes microsoft#10311

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Jun 15, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@10987

commit: e540161

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

@typespec/http-client-python - feature ✏️

Add a keep-pyproject-fields emitter option that selects which [project] fields to preserve in an existing pyproject.toml instead of overwriting them on regeneration. Supported fields: authors, description, classifiers, urls.,> ,> yaml,> # tspconfig.yaml,> options:,> "@typespec/http-client-python":,> keep-pyproject-fields:,> authors: true,> description: true,>

@azure-sdk-automation

azure-sdk-automation Bot commented Jun 15, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Add a keep-pyproject-fields emitter option so description, classifiers, and

[project.urls] in an existing pyproject.toml are only preserved when the

option is explicitly enabled in tspconfig.yaml.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the meta:website TypeSpec.io updates label Jun 15, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@l0lawrence

Copy link
Copy Markdown
Member Author

naming question keep-pyproject-fields

and

how much do we want the user to be able to preserve?

Comment thread packages/http-client-python/emitter/src/lib.ts
l0lawrence and others added 4 commits June 16, 2026 08:34
Per review feedback, change keep-pyproject-fields from a boolean toggle to a

comma-separated list of project fields (authors, description, classifiers,

urls) so users can choose exactly which fields to preserve.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Exercise the real OptionsDict -> parse -> keep -> template render chain to

verify selecting specific fields preserves only those and regenerates the rest.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@iscai-msft iscai-msft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this!

@iscai-msft iscai-msft added this pull request to the merge queue Jun 18, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 18, 2026
@l0lawrence l0lawrence enabled auto-merge June 18, 2026 22:27
@l0lawrence l0lawrence added this pull request to the merge queue Jun 18, 2026
Merged via the queue into microsoft:main with commit 2a1a1a5 Jun 19, 2026
46 of 48 checks passed
@l0lawrence l0lawrence deleted the l0lawrence/python-pyproject-preserve-fields branch June 19, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[python] overwriting of pyproject fields

3 participants