microsoft / microsoft/typespec

Preserve package dependencies/configuration during generation

Open
#7,714 3 comments 0 reactions 0 assignees View on GitHub
emitter:client:python
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

For packages that have a convenience layer, generating code from TSP shouldn't disrupt package configuration. For example, in [azure-keyvault-keys](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/keyvault/azure-keyvault-keys) we emit code into an `azure/keyvault/keys/_generated` namespace -- code outside this namespace is a convenience layer. The package's `setup.py` file is updated, which is expected and desirable, but some of the changes are incorrect and need to be reverted.

1. Dependencies that are unique to the convenience layer get removed.
1. KV Keys has a [`cryptography` dependency](https://github.com/Azure/azure-sdk-for-python/blob/098d0c96ff498b46925a6d8da1a1495b03b55899/sdk/keyvault/azure-keyvault-keys/setup.py#L64), but this is dropped by generation -- ideally, the emitter would keep track of additional dependencies like this and re-add them in the updated configuration.
2. Higher minimum requirements get decreased.
1. KV Keys has a [minimum `azure-core` requirement of 1.31.0](https://github.com/Azure/azure-sdk-for-python/blob/098d0c96ff498b46925a6d8da1a1495b03b55899/sdk/keyvault/azure-keyvault-keys/setup.py#L66), but when updating generated code recently, the emitter had a minimum requirement of 1.30.0. This lower version replaced the original dependency -- ideally, the emitter would defer to whichever requirement is stricter.
3. Some directories are removed from `find_packages` exclusions.
1. KV libraries [exclude the `samples` directory](https://github.com/Azure/azure-sdk-for-python/blob/098d0c96ff498b46925a6d8da1a1495b03b55899/sdk/keyvault/azure-keyvault-keys/setup.py#L56), but the emitter removes this entry from the configuration.
4. A `package_data` entry is added that points to the `py.typed` file of the generated directory, which we don't want.

These changes may be easier to achieve with `pyproject.toml` package configuration, compared to `setup.py`. This could motivate transitioning Python packages to the former.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.