Generate `__init__.py` files for enum-only modules ()

The current Python code generator does not emit `__init__.py` files for
modules that only contain enumerations. This is problematic in cases
such as https://github.com/pulumi/pulumi/issues/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 
This commit is contained in:
Will Jones 2024-05-20 15:16:49 +01:00 committed by GitHub
parent 9f1ff9d539
commit 8e31490513
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 1 deletions

View File

@ -0,0 +1,4 @@
changes:
- type: fix
scope: sdkgen/python
description: Generate __init__.py files for modules that only contain enumerations

View File

@ -638,7 +638,7 @@ func (mod *modContext) hasTypes(input bool) bool {
func (mod *modContext) isEmpty() bool {
if len(mod.extraSourceFiles) > 0 || len(mod.functions) > 0 || len(mod.resources) > 0 || len(mod.types) > 0 ||
mod.isConfig {
len(mod.enums) > 0 || mod.isConfig {
return false
}
for _, child := range mod.children {

View File

@ -4,6 +4,7 @@
"pulumi_example/__init__.py",
"pulumi_example/_utilities.py",
"pulumi_example/component.py",
"pulumi_example/local/__init__.py",
"pulumi_example/local/_enums.py",
"pulumi_example/provider.py",
"pulumi_example/pulumi-plugin.json",

View File

@ -7,6 +7,14 @@ import typing
# Export this package's modules as members:
from .component import *
from .provider import *
# Make subpackages available:
if typing.TYPE_CHECKING:
import pulumi_example.local as __local
local = __local
else:
local = _utilities.lazy_import('pulumi_example.local')
_utilities.register(
resource_modules="""
[

View File

@ -0,0 +1,8 @@
# coding=utf-8
# *** WARNING: this file was generated by test. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***
from .. import _utilities
import typing
# Export this package's modules as members:
from ._enums import *