mirror of https://github.com/pulumi/pulumi.git
Generate `__init__.py` files for enum-only modules (#16229)
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 #16221
This commit is contained in:
parent
9f1ff9d539
commit
8e31490513
changelog/pending
pkg/codegen/python
tests/testdata/codegen/external-enum/python
|
@ -0,0 +1,4 @@
|
|||
changes:
|
||||
- type: fix
|
||||
scope: sdkgen/python
|
||||
description: Generate __init__.py files for modules that only contain enumerations
|
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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="""
|
||||
[
|
||||
|
|
|
@ -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 *
|
Loading…
Reference in New Issue