Skip to content

Helpers to generate python lockfile rules#17480

Merged
benjyw merged 19 commits intopantsbuild:mainfrom
lilatomic:feature/helper-lockfiles
Mar 9, 2023
Merged

Helpers to generate python lockfile rules#17480
benjyw merged 19 commits intopantsbuild:mainfrom
lilatomic:feature/helper-lockfiles

Conversation

@lilatomic
Copy link
Contributor

@lilatomic lilatomic commented Nov 7, 2022

Breakout from #16412

Adds helpers to generate common python lockfile rules. includes:

  • tool that can just use GeneratePythonLockfile.from_tool
  • tool that needs to gather interpreter constraints
  • tool that needs to install 1st-party plugins

I threw together some documentation, but I'm not sure where these would go or even if they're what we want.
I'm also not sure how we want to fail generating rules if the fields we need aren't present. For example, for tools which need interpreter constraints, their FieldSet needs to have an InterpreterConstraintsField attribute; how should we warn if that field isn't present?

Talking things over with @thejcannon , we think that we'd need to do some prework to support a design similar to the other rule generators. Having a declarative field on the class would be ideal. However, we would need to tether a tool to its fieldset to support usecases 2 and 3, which is where the prework would come in.
This MR now deals only with the first case. This is basically 60% of usecases and probably most of the uses in plugins.

@lilatomic lilatomic force-pushed the feature/helper-lockfiles branch from 485e4c4 to 1773456 Compare November 7, 2022 06:20
@lilatomic lilatomic force-pushed the feature/helper-lockfiles branch from 5bf81e7 to cac4900 Compare November 17, 2022 05:24
@lilatomic lilatomic force-pushed the feature/helper-lockfiles branch from 55e8fe7 to 951ab9f Compare January 7, 2023 20:12
@lilatomic lilatomic marked this pull request as ready for review January 7, 2023 22:58
@thejcannon
Copy link
Member

Is there a chance I could convince you to rewrite history here so commits could be reviewed in order?
Something like:

  • First commit makes the core change
  • Second commit changes the core tests
  • Third commit is all the replacements out in the world

That'd make it much easier to review 😄

@lilatomic lilatomic force-pushed the feature/helper-lockfiles branch from b9a2e7f to 574f1f2 Compare January 10, 2023 03:51
@lilatomic
Copy link
Contributor Author

sure, makes sense. full history available here

@lilatomic lilatomic force-pushed the feature/helper-lockfiles branch from 574f1f2 to 3af161e Compare January 10, 2023 04:06
@benjyw
Copy link
Contributor

benjyw commented Jan 10, 2023

Will try and review properly today, but I love the idea so far! Take that, boilerplate.

@lilatomic
Copy link
Contributor Author

I think that CI failure isn't related to this MR? (failure is in Scala)

@stuhood stuhood added the category:internal CI, fixes for not-yet-released features, etc. label Jan 11, 2023
@stuhood
Copy link
Member

stuhood commented Jan 11, 2023

I think that CI failure isn't related to this MR? (failure is in Scala)

Yea, looks like a flake. Have added a category label and restarted this.

@lilatomic
Copy link
Contributor Author

I'm not sure which test failed? there's 100% pass but it says it failed?

@kaos
Copy link
Member

kaos commented Jan 11, 2023

I'm not sure which test failed? there's 100% pass but it says it failed?

looks like another flake.. kicked it again.

Copy link
Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

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

This looks great! And the proof of the pudding is in the eating. If all the tests pass, I'm happy pretty much by definition...

...


def rules():
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for writing up these great docs!

@benjyw benjyw requested review from kaos and thejcannon January 12, 2023 20:36
@benjyw
Copy link
Contributor

benjyw commented Jan 12, 2023

Throwing a couple more reviewers on, for perspective.

@lilatomic
Copy link
Contributor Author

If all the tests pass, I'm happy pretty much by definition...

There weren't that many tests for this with the other tools. I guess since most of this was boilerplate, people didn't feel the need to test it? But with the tests for Cowsay and Flake8 I think we're well-covered.

@benjyw
Copy link
Contributor

benjyw commented Jan 14, 2023

And presumably you've manually tested generate-lockfiles and so on?

@lilatomic
Copy link
Contributor Author

I've run ./pants generate-lockfiles and then ./pants fmt test check lint --changed-since==main and none of the tools exploded.

@benjyw
Copy link
Contributor

benjyw commented Jan 15, 2023

@thejcannon @kaos I'll merge this on Tuesday if no comments from you before then. Thanks!!

@thejcannon
Copy link
Member

Yeah sorry, been in the hospital since my last comment. Tuesday is my first day back at work, so I'll try and squeeze in this PR.

@benjyw
Copy link
Contributor

benjyw commented Jan 15, 2023

Not urgent!!

Copy link
Member

@kaos kaos left a comment

Choose a reason for hiding this comment

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

lgtm!

@lilatomic lilatomic force-pushed the feature/helper-lockfiles branch from 3af161e to 609bed2 Compare January 17, 2023 04:54
Copy link
Member

@thejcannon thejcannon left a comment

Choose a reason for hiding this comment

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

We're close, I can taste it. I can't thank you enough for getting this together, I'm VERY excited at the prospect of more boilerplate-reducers.

if self == LockfileRules.NONE:
return

yield from lockfile.rules()
Copy link
Member

Choose a reason for hiding this comment

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

I still don't think this is necessary. I understand it's useful for tests, but let's not pollute the code and confuse authors (and removing this removes the need for None).

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 thought so too. They're registered in the Python backend so they should be included. But the core doesn't register them, because it doesn't pull in the full python backend; it selectively pulls in YAPF and Black for updating build files. These would have then pulled in the lockfile.rules().
I've pulled this up to the root register in core, hopefully that gets the tests passing.

Copy link
Member

Choose a reason for hiding this comment

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

In that case, I think the black/yapf backends should be re-registering these rules.

@lilatomic lilatomic force-pushed the feature/helper-lockfiles branch 2 times, most recently from 4164ab6 to a98e001 Compare March 9, 2023 03:14
They were already transitively imported through their subsystems.
This MR pulls them up explicitly,
so we need to allow that in the visibility rules
@lilatomic lilatomic force-pushed the feature/helper-lockfiles branch from a98e001 to cd88e04 Compare March 9, 2023 03:20
@lilatomic
Copy link
Contributor Author

I think that's a flaky test? It seems to work fine locally...

@benjyw
Copy link
Contributor

benjyw commented Mar 9, 2023

Yeah, that test is flaky, I will look into fixing or kililng it. Meanwhile I've restarted that shard.

@benjyw benjyw merged commit 6b1b304 into pantsbuild:main Mar 9, 2023
@benjyw
Copy link
Contributor

benjyw commented Mar 9, 2023

Merged, finally! Thanks again for the contribution and for your patience!

stuhood added a commit that referenced this pull request Mar 9, 2023
#17480 and #18431 collided, such that a new file was not re-formatted by
the new version of `black`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:internal CI, fixes for not-yet-released features, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants