Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python codegen omits __init__.py when only enums are present #16221

Closed
thomas11 opened this issue May 17, 2024 · 1 comment · Fixed by #16229
Closed

Python codegen omits __init__.py when only enums are present #16221

thomas11 opened this issue May 17, 2024 · 1 comment · Fixed by #16229
Assignees
Labels
area/codegen SDK-gen, program-gen, convert kind/bug Some behavior is incorrect or out of spec language/python resolution/fixed This issue was fixed
Milestone

Comments

@thomas11
Copy link
Contributor

In pulumi-command v0.11.0, a new enum Logging was introduced to be used an input and output type. It worked in all languages but Python. In Python, programs failed with

AttributeError: module 'pulumi_command.common' has no attribute 'Logging'

@lunaris determined that the problem was a missing init.py for the module containing the enum, so the symbols weren't being re-exported.

Codegen generates an init.py if it thinks the module is "not empty". This checks for resources, functions, and types, but not, it seems, enums.

Schema and Python SDK can be seen at the v0.11.0 tag.

@thomas11 thomas11 added area/codegen SDK-gen, program-gen, convert needs-triage Needs attention from the triage team python Pull requests that update Python code labels May 17, 2024
@justinvp justinvp added language/python and removed python Pull requests that update Python code labels May 17, 2024
iwahbe pushed a commit to pulumi/pulumi-command that referenced this issue May 17, 2024
The `Logging` enum defined in the `common` package was not correctly
exposed in the Python SDK due to pulumi/pulumi#16221, causing the error
```
AttributeError: module 'pulumi_command.common' has no attribute 'Logging'
```

As a workaround, this PR moves the Logging enum into both the `local`
and the `remote` package. This duplicates some code but keeps the
packages separated. As the provider is not GA yet, we could reverse this
once the upstream is fixed, at the cost of a breaking change.

Tested a local `pulumi up`.

Fixes #445
lunaris added a commit that referenced this issue May 20, 2024
The current Python code generator does not emit `__init__.py` files for
modules that only contain enumerations. This is problematic in cases
such as #16221, whereby
`pulumi-command` wishes to define an enumeration to be shared across
modules, in a module with no other types or resources. In such cases, an
SDK is generated that does not type check, since the enumeration types
are not exported appropriately. This commit addresses this by generating
`__init__.py` files in these cases as expected.
lunaris added a commit that referenced this issue May 20, 2024
The current Python code generator does not emit `__init__.py` files for
modules that only contain enumerations. This is problematic in cases
such as #16221, whereby
`pulumi-command` wishes to define an enumeration to be shared across
modules, in a module with no other types or resources. In such cases, an
SDK is generated that does not type check, since the enumeration types
are not exported appropriately. This commit addresses this by generating
`__init__.py` files in these cases as expected.
@justinvp justinvp removed the needs-triage Needs attention from the triage team label May 20, 2024
@justinvp justinvp added this to the 0.105 milestone May 20, 2024
lunaris added a commit that referenced this issue May 20, 2024
The current Python code generator does not emit `__init__.py` files for
modules that only contain enumerations. This is problematic in cases
such as #16221, whereby
`pulumi-command` wishes to define an enumeration to be shared across
modules, in a module with no other types or resources. In such cases, an
SDK is generated that does not type check, since the enumeration types
are not exported appropriately. This commit addresses this by generating
`__init__.py` files in these cases as expected.
github-merge-queue bot pushed a commit that referenced this issue May 20, 2024
The current Python code generator does not emit `__init__.py` files for
modules that only contain enumerations. This is problematic in cases
such as #16221, whereby
`pulumi-command` wishes to define an enumeration to be shared across
modules, in a module with no other types or resources. In such cases, an
SDK is generated that does not type check, since the enumeration types
are not exported appropriately. This commit addresses this by generating
`__init__.py` files in these cases as expected.

Fixes #16221
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label May 20, 2024
@pulumi-bot pulumi-bot reopened this May 20, 2024
@pulumi-bot
Copy link
Contributor

Cannot close issue:

  • does not have required labels: kind/

Please fix these problems and try again.

@Frassle Frassle added the kind/bug Some behavior is incorrect or out of spec label May 20, 2024
@Frassle Frassle closed this as completed May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codegen SDK-gen, program-gen, convert kind/bug Some behavior is incorrect or out of spec language/python resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants