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

Codegen fixes for the Python SDK #639

Merged
merged 1 commit into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
server (https://github.com/pulumi/pulumi-kubernetes/pull/636).
- Expose all Kubernetes types through the SDK
(https://github.com/pulumi/pulumi-kubernetes/pull/637).

- Use `opts` instead of `__opts__` and `resource_name` instead of `__name__` in Python SDK
(https://github.com/pulumi/pulumi-kubernetes/pull/639).

## 0.25.2 (July 11, 2019)

Expand Down
27 changes: 17 additions & 10 deletions pkg/gen/python-templates/kind.py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@

import pulumi
import pulumi.runtime
import warnings

from ... import tables, version


class {{Kind}}(pulumi.CustomResource):
{{{Comment}}}
def __init__(self, __name__, __opts__=None{{#Properties}}, {{LanguageName}}=None{{/Properties}}):
if not __name__:
def __init__(self, resource_name, opts=None{{#Properties}}, {{LanguageName}}=None{{/Properties}}, __name__=None, __opts__=None):
if __name__ is not None:
warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
resource_name = __name__
if __opts__ is not None:
warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually render these deprecation warnings in the CLI? I thought we had some issue around this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just copied what the TF bridge providers do because it seemed weirder to not do what they did in the same situation. We can do something else if it makes more sense.

Copy link
Member

Choose a reason for hiding this comment

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

This seems great, then 👍

Copy link
Member

@lukehoban lukehoban Jul 16, 2019

Choose a reason for hiding this comment

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

If we are going to match the TF providers, we should also consider renaming __name__ to resource_name:

https://github.com/pulumi/pulumi-aws/blob/master/sdk/python/pulumi_aws/athena/database.py#L28

Indeed it seems odd to make only half of this breaking change - feels like we should align or not make any change here?

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 didn't make this other breaking change because it wasn't listed in the original issue, and we therefore didn't know about it.

Is this all the changes we need to make here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lukehoban @pgavlin I've updated to include the breaking __name__ -> resource_name change as well. Please let me know if there are other things we need to put in here ASAP, as we're planning on merging soon.

opts = __opts__
if not resource_name:
raise TypeError('Missing resource name argument (for URN creation)')
if not isinstance(__name__, str):
if not isinstance(resource_name, str):
raise TypeError('Expected resource name to be a string')
if __opts__ and not isinstance(__opts__, pulumi.ResourceOptions):
if opts and not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
Expand All @@ -30,16 +37,16 @@ class {{Kind}}(pulumi.CustomResource):
__props__['{{Name}}'] = {{LanguageName}}
{{/OptionalProperties}}

if __opts__ is None:
__opts__ = pulumi.ResourceOptions()
if __opts__.version is None:
__opts__.version = version.get_version()
if opts is None:
opts = pulumi.ResourceOptions()
if opts.version is None:
opts.version = version.get_version()

super({{Kind}}, self).__init__(
"kubernetes:{{URNAPIVersion}}:{{Kind}}",
__name__,
resource_name,
__props__,
__opts__)
opts)

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pulumi
import pulumi.runtime
import warnings

from ... import tables, version

Expand All @@ -12,12 +13,18 @@ class MutatingWebhookConfiguration(pulumi.CustomResource):
MutatingWebhookConfiguration describes the configuration of and admission webhook that accept or
reject and may change the object.
"""
def __init__(self, __name__, __opts__=None, metadata=None, webhooks=None):
if not __name__:
def __init__(self, resource_name, opts=None, metadata=None, webhooks=None, __name__=None, __opts__=None):
if __name__ is not None:
warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
resource_name = __name__
if __opts__ is not None:
warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
opts = __opts__
if not resource_name:
raise TypeError('Missing resource name argument (for URN creation)')
if not isinstance(__name__, str):
if not isinstance(resource_name, str):
raise TypeError('Expected resource name to be a string')
if __opts__ and not isinstance(__opts__, pulumi.ResourceOptions):
if opts and not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
Expand All @@ -27,16 +34,16 @@ def __init__(self, __name__, __opts__=None, metadata=None, webhooks=None):
__props__['metadata'] = metadata
__props__['webhooks'] = webhooks

if __opts__ is None:
__opts__ = pulumi.ResourceOptions()
if __opts__.version is None:
__opts__.version = version.get_version()
if opts is None:
opts = pulumi.ResourceOptions()
if opts.version is None:
opts.version = version.get_version()

super(MutatingWebhookConfiguration, self).__init__(
"kubernetes:admissionregistration.k8s.io/v1beta1:MutatingWebhookConfiguration",
__name__,
resource_name,
__props__,
__opts__)
opts)

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pulumi
import pulumi.runtime
import warnings

from ... import tables, version

Expand All @@ -11,12 +12,18 @@ class MutatingWebhookConfigurationList(pulumi.CustomResource):
"""
MutatingWebhookConfigurationList is a list of MutatingWebhookConfiguration.
"""
def __init__(self, __name__, __opts__=None, items=None, metadata=None):
if not __name__:
def __init__(self, resource_name, opts=None, items=None, metadata=None, __name__=None, __opts__=None):
if __name__ is not None:
warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
resource_name = __name__
if __opts__ is not None:
warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
opts = __opts__
if not resource_name:
raise TypeError('Missing resource name argument (for URN creation)')
if not isinstance(__name__, str):
if not isinstance(resource_name, str):
raise TypeError('Expected resource name to be a string')
if __opts__ and not isinstance(__opts__, pulumi.ResourceOptions):
if opts and not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
Expand All @@ -28,16 +35,16 @@ def __init__(self, __name__, __opts__=None, items=None, metadata=None):
__props__['items'] = items
__props__['metadata'] = metadata

if __opts__ is None:
__opts__ = pulumi.ResourceOptions()
if __opts__.version is None:
__opts__.version = version.get_version()
if opts is None:
opts = pulumi.ResourceOptions()
if opts.version is None:
opts.version = version.get_version()

super(MutatingWebhookConfigurationList, self).__init__(
"kubernetes:admissionregistration.k8s.io/v1beta1:MutatingWebhookConfigurationList",
__name__,
resource_name,
__props__,
__opts__)
opts)

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pulumi
import pulumi.runtime
import warnings

from ... import tables, version

Expand All @@ -12,12 +13,18 @@ class ValidatingWebhookConfiguration(pulumi.CustomResource):
ValidatingWebhookConfiguration describes the configuration of and admission webhook that accept
or reject and object without changing it.
"""
def __init__(self, __name__, __opts__=None, metadata=None, webhooks=None):
if not __name__:
def __init__(self, resource_name, opts=None, metadata=None, webhooks=None, __name__=None, __opts__=None):
if __name__ is not None:
warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
resource_name = __name__
if __opts__ is not None:
warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
opts = __opts__
if not resource_name:
raise TypeError('Missing resource name argument (for URN creation)')
if not isinstance(__name__, str):
if not isinstance(resource_name, str):
raise TypeError('Expected resource name to be a string')
if __opts__ and not isinstance(__opts__, pulumi.ResourceOptions):
if opts and not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
Expand All @@ -27,16 +34,16 @@ def __init__(self, __name__, __opts__=None, metadata=None, webhooks=None):
__props__['metadata'] = metadata
__props__['webhooks'] = webhooks

if __opts__ is None:
__opts__ = pulumi.ResourceOptions()
if __opts__.version is None:
__opts__.version = version.get_version()
if opts is None:
opts = pulumi.ResourceOptions()
if opts.version is None:
opts.version = version.get_version()

super(ValidatingWebhookConfiguration, self).__init__(
"kubernetes:admissionregistration.k8s.io/v1beta1:ValidatingWebhookConfiguration",
__name__,
resource_name,
__props__,
__opts__)
opts)

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pulumi
import pulumi.runtime
import warnings

from ... import tables, version

Expand All @@ -11,12 +12,18 @@ class ValidatingWebhookConfigurationList(pulumi.CustomResource):
"""
ValidatingWebhookConfigurationList is a list of ValidatingWebhookConfiguration.
"""
def __init__(self, __name__, __opts__=None, items=None, metadata=None):
if not __name__:
def __init__(self, resource_name, opts=None, items=None, metadata=None, __name__=None, __opts__=None):
if __name__ is not None:
warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
resource_name = __name__
if __opts__ is not None:
warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
opts = __opts__
if not resource_name:
raise TypeError('Missing resource name argument (for URN creation)')
if not isinstance(__name__, str):
if not isinstance(resource_name, str):
raise TypeError('Expected resource name to be a string')
if __opts__ and not isinstance(__opts__, pulumi.ResourceOptions):
if opts and not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
Expand All @@ -28,16 +35,16 @@ def __init__(self, __name__, __opts__=None, items=None, metadata=None):
__props__['items'] = items
__props__['metadata'] = metadata

if __opts__ is None:
__opts__ = pulumi.ResourceOptions()
if __opts__.version is None:
__opts__.version = version.get_version()
if opts is None:
opts = pulumi.ResourceOptions()
if opts.version is None:
opts.version = version.get_version()

super(ValidatingWebhookConfigurationList, self).__init__(
"kubernetes:admissionregistration.k8s.io/v1beta1:ValidatingWebhookConfigurationList",
__name__,
resource_name,
__props__,
__opts__)
opts)

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pulumi
import pulumi.runtime
import warnings

from ... import tables, version

Expand All @@ -12,12 +13,18 @@ class CustomResourceDefinition(pulumi.CustomResource):
CustomResourceDefinition represents a resource that should be exposed on the API server. Its
name MUST be in the format <.spec.name>.<.spec.group>.
"""
def __init__(self, __name__, __opts__=None, metadata=None, spec=None, status=None):
if not __name__:
def __init__(self, resource_name, opts=None, metadata=None, spec=None, status=None, __name__=None, __opts__=None):
if __name__ is not None:
warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
resource_name = __name__
if __opts__ is not None:
warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
opts = __opts__
if not resource_name:
raise TypeError('Missing resource name argument (for URN creation)')
if not isinstance(__name__, str):
if not isinstance(resource_name, str):
raise TypeError('Expected resource name to be a string')
if __opts__ and not isinstance(__opts__, pulumi.ResourceOptions):
if opts and not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
Expand All @@ -30,16 +37,16 @@ def __init__(self, __name__, __opts__=None, metadata=None, spec=None, status=Non
__props__['metadata'] = metadata
__props__['status'] = status

if __opts__ is None:
__opts__ = pulumi.ResourceOptions()
if __opts__.version is None:
__opts__.version = version.get_version()
if opts is None:
opts = pulumi.ResourceOptions()
if opts.version is None:
opts.version = version.get_version()

super(CustomResourceDefinition, self).__init__(
"kubernetes:apiextensions.k8s.io/v1beta1:CustomResourceDefinition",
__name__,
resource_name,
__props__,
__opts__)
opts)

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pulumi
import pulumi.runtime
import warnings

from ... import tables, version

Expand All @@ -11,12 +12,18 @@ class CustomResourceDefinitionList(pulumi.CustomResource):
"""
CustomResourceDefinitionList is a list of CustomResourceDefinition objects.
"""
def __init__(self, __name__, __opts__=None, items=None, metadata=None):
if not __name__:
def __init__(self, resource_name, opts=None, items=None, metadata=None, __name__=None, __opts__=None):
if __name__ is not None:
warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
resource_name = __name__
if __opts__ is not None:
warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
opts = __opts__
if not resource_name:
raise TypeError('Missing resource name argument (for URN creation)')
if not isinstance(__name__, str):
if not isinstance(resource_name, str):
raise TypeError('Expected resource name to be a string')
if __opts__ and not isinstance(__opts__, pulumi.ResourceOptions):
if opts and not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')

__props__ = dict()
Expand All @@ -28,16 +35,16 @@ def __init__(self, __name__, __opts__=None, items=None, metadata=None):
__props__['items'] = items
__props__['metadata'] = metadata

if __opts__ is None:
__opts__ = pulumi.ResourceOptions()
if __opts__.version is None:
__opts__.version = version.get_version()
if opts is None:
opts = pulumi.ResourceOptions()
if opts.version is None:
opts.version = version.get_version()

super(CustomResourceDefinitionList, self).__init__(
"kubernetes:apiextensions.k8s.io/v1beta1:CustomResourceDefinitionList",
__name__,
resource_name,
__props__,
__opts__)
opts)

def translate_output_property(self, prop: str) -> str:
return tables._CASING_FORWARD_TABLE.get(prop) or prop
Expand Down
Loading