Skip to content

[python] Fix import for generation-subdir#10303

Merged
msyyc merged 10 commits intomainfrom
fix-import-generation-subdir
Apr 9, 2026
Merged

[python] Fix import for generation-subdir#10303
msyyc merged 10 commits intomainfrom
fix-import-generation-subdir

Conversation

@msyyc
Copy link
Copy Markdown
Contributor

@msyyc msyyc commented Apr 8, 2026

Description

Fix import generation when using a generation subdirectory (generation-subdir). This ensures imports are correctly resolved for generated code in subdirectories.

Changes

  • Fix import resolution in generator/pygen/codegen/serializers/__init__.py
  • Update regenerate-common.ts script
  • Add test cases for generation-subdir scenarios

Changelog

changeKind: fix
packages:
  - @typespec/http-client-python

@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 Apr 8, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 8, 2026

Open in StackBlitz

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

commit: 601bba8

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

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

fix import for _validation.py/_types.py when "generation-subdir" is configured

@azure-sdk
Copy link
Copy Markdown
Collaborator

azure-sdk commented Apr 8, 2026

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@msyyc msyyc requested a review from m-nash as a code owner April 9, 2026 02:58
@microsoft-github-policy-service microsoft-github-policy-service bot added ide Issues for VS, VSCode, Monaco, etc. emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp eng labels Apr 9, 2026
@msyyc msyyc force-pushed the fix-import-generation-subdir branch from 6dc7451 to 34539c7 Compare April 9, 2026 03:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Python emitter import generation when generation-subdir is used so that generated code in subdirectories can correctly resolve shared modules like _validation.py and _types.py.

Changes:

  • Write _validation.py and _types.py into the generation-subdir output directory to match where operation/client code is generated.
  • Extend CI regeneration scripts/config to generate additional generation-subdir test packages and add a shared preprocess() helper.
  • Add new sync/async mock-api tests that import and exercise generated clients under generation.<subdir>._generated.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/http-client-python/generator/pygen/codegen/serializers/init.py Writes _validation.py / _types.py into generation_dir to fix relative imports under generation-subdir.
packages/http-client-python/eng/scripts/ci/regenerate.ts Switches to shared preprocess() and trims local emitter options.
packages/http-client-python/eng/scripts/ci/regenerate-common.ts Adds multi-output emitter configs (arrays) for new generation-subdir scenarios; introduces shared preprocess().
packages/http-client-python/tests/mock_api/shared/test_generation_subdir_for_generated_code.py New sync test covering generated code under generation-subdir.
packages/http-client-python/tests/mock_api/shared/test_generation_subdir2_for_generated_code.py New sync test validating _validation.py / _types.py usage under generation-subdir.
packages/http-client-python/tests/mock_api/shared/asynctests/test_generation_subdir_for_generated_code_async.py Async variant of generation-subdir coverage.
packages/http-client-python/tests/mock_api/shared/asynctests/test_generation_subdir2_for_generated_code_async.py Async variant validating _validation.py / _types.py under generation-subdir.
packages/http-client-python/tests/conftest.py Suppresses mock server output during tests.
packages/http-client-python/tests/mock_api/unbranded/test_unbranded.py Removes the “microsoft” sensitive-word assertion from generated unbranded outputs.
.chronus/changes/fix-import-generation-subdir-2026-3-8-12-7-49.md Adds a changelog entry for the fix.
Comments suppressed due to low confidence (1)

packages/http-client-python/tests/mock_api/unbranded/test_unbranded.py:58

  • The PR removes the "microsoft" sensitive-word assertion from test_sensitive_word() but this change isn’t mentioned in the PR description and significantly changes what the test is validating. Please either update the PR description to cover this behavioral change (and why it’s needed) or keep an equivalent assertion (updated expected set if needed) so we still detect unexpected "microsoft" occurrences in generated unbranded outputs.
def test_sensitive_word():
    check_folder = (Path(os.path.dirname(__file__)) / "../../generated/unbranded").resolve()
    assert [] == check_sensitive_word(check_folder, "azure")

Comment thread packages/http-client-python/tests/conftest.py
Comment thread packages/http-client-python/eng/scripts/ci/regenerate-common.ts Outdated
@msyyc msyyc enabled auto-merge April 9, 2026 07:31
@msyyc msyyc added this pull request to the merge queue Apr 9, 2026
Merged via the queue into main with commit 4ba1822 Apr 9, 2026
36 checks passed
@msyyc msyyc deleted the fix-import-generation-subdir branch April 9, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp emitter:client:python Issue for the Python client emitter: @typespec/http-client-python eng ide Issues for VS, VSCode, Monaco, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants