Skip to content

Conversation

@msyyc
Copy link
Contributor

@msyyc msyyc commented Oct 11, 2025

fix Azure/azure-sdk-tools#11791

@github-actions
Copy link
Contributor

github-actions bot commented Oct 11, 2025

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

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

Add logic to clear output folder

@azure-sdk
Copy link
Collaborator

azure-sdk commented Oct 11, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

# pylint: disable=too-many-branches
def serialize(self) -> None:
# remove existing folders when generate from tsp
if self.code_model.is_tsp and self.code_model.is_azure_flavor:
Copy link
Member

@tadelesh tadelesh Oct 13, 2025

Choose a reason for hiding this comment

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

Shall we just filter the .py files with Code generated by Microsoft (R) Python Code Generator. to make the clean up much easier and more robust?

Copy link
Contributor Author

@msyyc msyyc Oct 13, 2025

Choose a reason for hiding this comment

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

We shall be very very careful about remove the .py file under generated SDK folder to avoid delete users' custom patched code. For example, if users copy the license title without any change then add their customized code, then your filter logic lose function.

Here are my thoughts:
(1) autorest.python has native flag --clear-output-folder of autorest core so don't need we do it in emitter
(2) for unbranded, we can't monitor users' code so it is better not add removal logic for now
(3) for azure, we could review their PR to make sure users don't add customized code randomly.

Copy link
Member

Choose a reason for hiding this comment

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

Another option is we know the names of all of our generated files, so we can keep a list of the generated files and delete those on regeneration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iscai-msft Current logic is very similar as your solution that emitter will ONLY delete files under target output folder.

await regenerate({ flavor: "azure", ...flags });
await regenerate({ flavor: "unbranded", ...flags });
} else {
await preprocess(flags);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not comfortable with adding test code in the regen script. Is there any better way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need logic to add the files before regeneration then test whether those files are kept or removed after regeneration. For now I can't find better way to do that.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is where we should put the preprocess call. This seems we only want to do it when we call regenerate with flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iscai-msft / @tadelesh I could also put preprocess before regenerate instead of inner it. Does it make sense? (e.g. I could convert preprocess to sync API then put it here)

Copy link
Member

Choose a reason for hiding this comment

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

I meant more like line 473 if we always wanted it. Can we also add to_be_deleted.py to the gitignore so we don't accidentally commit it? Pipelines should still fail if it doesn't get deleted

@msyyc msyyc added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Oct 13, 2025
@msyyc msyyc requested a review from tadelesh October 13, 2025 05:20
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Support some pre-process steps in the emitter

4 participants