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

Remind users they should be setting a Python min version. #12287

Merged
merged 7 commits into from Mar 30, 2023

Conversation

RobbieMcKinstry
Copy link
Contributor

@RobbieMcKinstry RobbieMcKinstry commented Feb 27, 2023

Description

This PR adds a log line during SDKGen if the user does not include a minimum
Python version. IMO, we should expect all Python packages to list a minimum
Python version to provide greater clarity to our users.

In the current version of this PR, this warning is printing during module
generating; we might prefer to ensure its only printed once per package instead
of once per module.

Additionally, this turns accessing the minimum Python version into a checked error from an unchecked error, increasing safety.

Fixes: #12286

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

@RobbieMcKinstry
Copy link
Contributor Author

RobbieMcKinstry commented Feb 27, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@pulumi-bot
Copy link
Contributor

pulumi-bot commented Feb 27, 2023

Changelog

[uncommitted] (2023-03-30)

Features

  • [sdkgen/python] In codegen, use 3.7 as a default if not provided.
    #12287

pkg/codegen/python/gen.go Outdated Show resolved Hide resolved
This commit introduces a log line to remind users they
should be setting the Python minimum version in their schema.
This refactor makes accessing the min version a checked error,
increasing safety.
@RobbieMcKinstry RobbieMcKinstry force-pushed the mckinstry/refactor-py-metadata-gen branch from 657d217 to 53d647c Compare March 28, 2023 20:31
Prefer a top-level function over a method for minPythonVersion,
because minPythonVersion is a validation step, and thus should be
colocated with validation code. It's not a concern of the PackageInfo.
pkg/codegen/python/gen.go Outdated Show resolved Hide resolved
@@ -2210,6 +2222,21 @@ func genPackageMetadata(
return w.String(), nil
}

// errNoMinimumPythonVersion is a non-fatal error indicating that the schema
Copy link
Member

Choose a reason for hiding this comment

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

Probably overkill for a != "" check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this blocking feedback? I want a checked error because

  1. we've already missed checking this field once
  2. we're about to check it in a second place, with the advent of the pyproject.toml file.

That's kind of the whole point of this PR, really.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough, it doesn't feel very "Go-ish" but then Go is horrible so I won't block approval on 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.

Thanks! I had a similar discussion with @abhinav around the API limitations which (in my eyes) necessitate adding this fn on a public field.

bors bot added a commit that referenced this pull request Mar 30, 2023
12287: Remind users they should be setting a Python min version. r=RobbieMcKinstry a=RobbieMcKinstry

<!--- 
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

This PR adds a log line during SDKGen if the user does not include a minimum
Python version. IMO, we should expect all Python packages to list a minimum
Python version to provide greater clarity to our users.

In the current version of this PR, this warning is printing during module
generating; we might prefer to ensure its only printed once per package instead
of once per module.

Additionally, this turns accessing the minimum Python version into a checked error from an unchecked error, increasing safety.

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

Fixes: #12286

## 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: Robbie McKinstry <robbie@pulumi.com>
@RobbieMcKinstry
Copy link
Contributor Author

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 30, 2023

Already running a review

Copy link
Member

@Frassle Frassle left a comment

Choose a reason for hiding this comment

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

I very much like that we now fill in a sensible default for setup.py files, good change.
I'm less sure about needing to tell everyone that they ought to set this version in their schemas. I'd consider setting this field to be a edge use case where users know better than our sdk generation because they're doing something custom.
I've said it elsewhere but to repeat it here, I think a good schema design would result in not having to set any language specific settings (we don't have that today, but we should be moving towards that, not away).

@RobbieMcKinstry
Copy link
Contributor Author

RobbieMcKinstry commented Mar 30, 2023

I'm less sure about needing to tell everyone that they ought to set this version in their schemas.

Are you concerned about the log level? Suppose it was DEBUG instead of WARN.

I think if we're changing the value that users provide, we should emit a log somewhere telling them we're overriding their value.
How does that sound? That sounds like a reasonable in-between to me.

@Frassle
Copy link
Member

Frassle commented Mar 30, 2023

I think if we're changing the value that users provide, we should emit a log somewhere telling them we're overriding their value.

I agree with that statement. But in this case we're not changing the value that users provide. Either they give us a min version and we stick that in setup.py, or they don't and we put in a sensible default. I don't think we need to log for every default, but if you think we should (and like I can see arguments for that) then that's fine but then we should be consistent and be logging for lots of other defaults we set as well not just this.

@RobbieMcKinstry
Copy link
Contributor Author

That makes sense to me. My life is still made easier by this PR as long as we keep the checked error. I'm refactoring now.

@bors
Copy link
Contributor

bors bot commented Mar 30, 2023

Canceled.

@RobbieMcKinstry
Copy link
Contributor Author

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 30, 2023

Build succeeded:

@bors bors bot merged commit 2972de9 into master Mar 30, 2023
47 of 52 checks passed
@bors bors bot deleted the mckinstry/refactor-py-metadata-gen branch March 30, 2023 17:05
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.

Python SDKGen: Turn Missing Metadata fields into Logged Recoverable Errors
4 participants