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

Add json_dumps to python sdk #11607

Merged
merged 1 commit into from Dec 14, 2022
Merged

Add json_dumps to python sdk #11607

merged 1 commit into from Dec 14, 2022

Conversation

Frassle
Copy link
Member

@Frassle Frassle commented Dec 9, 2022

Description

Following on with adding to json functions to each SDK, this one is for Python.
It even handles nested Outputs via our _sync_await helper.

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

@Frassle Frassle requested a review from kpitzen December 9, 2022 13:41
@pulumi-bot
Copy link
Contributor

pulumi-bot commented Dec 9, 2022

Changelog

[uncommitted] (2022-12-14)

Features

  • [sdk/python] Add json_dumps to python sdk.
    #11607

@staticmethod
def jsonDumps(obj: Input[object], *, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None,
default=None, sort_keys=False, **kw) -> "Output[str]":
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 want to use the default behavior from json.dumps or should we consider changing some of the defaults to give more predictable results when passing the result as an input to some other resource, e.g. having sort_keys default to True? Otherwise, if someone is passing the result of this along elsewhere, they very likely need to specify sort_keys=True themselves.

I know these toJson methods we're adding to the SDKs are "just doing what the underlying language do and aren't consistent across SDKs", so we will have different behavior across SDKs. But maybe we should still consider changing some aspects of the default behavior in each to work best with Pulumi within the language?

Copy link
Member

Choose a reason for hiding this comment

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

idk, I flip flop each way the more I think about it. Just doing the default is easy to explain. But also having to caveat certain languages, e.g. "in Python, be sure to pass sort_keys=True", is also not great.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I'd err to just literally being a wrapper over the language built in functionality to start and seeing if usability issues like that come up.

@Frassle Frassle force-pushed the fraser/pythonJsonDumps branch 2 times, most recently from 068c444 to d3f449f Compare December 9, 2022 20:16
Copy link
Member

@justinvp justinvp left a comment

Choose a reason for hiding this comment

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

LGTM otherwise

sdk/python/lib/pulumi/output.py Outdated Show resolved Hide resolved
sdk/python/lib/pulumi/output.py Outdated Show resolved Hide resolved
@Frassle
Copy link
Member Author

Frassle commented Dec 14, 2022

bors merge

@bors
Copy link
Contributor

bors bot commented Dec 14, 2022

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

bors bot added a commit that referenced this pull request Dec 14, 2022
11607: Add jsonDumps to python sdk r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Following on with adding to json functions to each SDK, this one is for Python.
It even handles nested Outputs via our _sync_await helper.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
@bors
Copy link
Contributor

bors bot commented Dec 14, 2022

Canceled.

@Frassle Frassle changed the title Add jsonDumps to python sdk Add json_dumps to python sdk Dec 14, 2022
@Frassle
Copy link
Member Author

Frassle commented Dec 14, 2022

bors merge

bors bot added a commit that referenced this pull request Dec 14, 2022
11607: Add json_dumps to python sdk r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Following on with adding to json functions to each SDK, this one is for Python.
It even handles nested Outputs via our _sync_await helper.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
@bors
Copy link
Contributor

bors bot commented Dec 14, 2022

Canceled.

@Frassle
Copy link
Member Author

Frassle commented Dec 14, 2022

bors merge

bors bot added a commit that referenced this pull request Dec 14, 2022
11607: Add json_dumps to python sdk r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Following on with adding to json functions to each SDK, this one is for Python.
It even handles nested Outputs via our _sync_await helper.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
@bors
Copy link
Contributor

bors bot commented Dec 14, 2022

Build failed:

@Frassle
Copy link
Member Author

Frassle commented Dec 14, 2022

bors merge

@bors
Copy link
Contributor

bors bot commented Dec 14, 2022

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

bors bot added a commit that referenced this pull request Dec 14, 2022
11607: Add json_dumps to python sdk r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Following on with adding to json functions to each SDK, this one is for Python.
It even handles nested Outputs via our _sync_await helper.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
@bors
Copy link
Contributor

bors bot commented Dec 14, 2022

Canceled.

@Frassle
Copy link
Member Author

Frassle commented Dec 14, 2022

bors merge

bors bot added a commit that referenced this pull request Dec 14, 2022
11607: Add json_dumps to python sdk r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Following on with adding to json functions to each SDK, this one is for Python.
It even handles nested Outputs via our _sync_await helper.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
@bors
Copy link
Contributor

bors bot commented Dec 14, 2022

Build failed:

@Zaid-Ajaj
Copy link
Contributor

bors retry

bors bot added a commit that referenced this pull request Dec 14, 2022
11607: Add json_dumps to python sdk r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Following on with adding to json functions to each SDK, this one is for Python.
It even handles nested Outputs via our _sync_await helper.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
@Frassle
Copy link
Member Author

Frassle commented Dec 14, 2022

oh derp some of the type annotations are wrong

@bors
Copy link
Contributor

bors bot commented Dec 14, 2022

Canceled.

@Frassle
Copy link
Member Author

Frassle commented Dec 14, 2022

bors merge

@bors
Copy link
Contributor

bors bot commented Dec 14, 2022

Build succeeded:

@bors bors bot merged commit 3dc5b7b into master Dec 14, 2022
@bors bors bot deleted the fraser/pythonJsonDumps branch December 14, 2022 14:40
@justinvp justinvp mentioned this pull request Jan 21, 2023
31 tasks
@lukehoban lukehoban mentioned this pull request Mar 27, 2023
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants