-
-
Notifications
You must be signed in to change notification settings - Fork 776
Use black (via pantsbuild) #5774
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
Conversation
|
|
||
| python_sources( | ||
| name="test_content_version", | ||
| skip_black=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in a git submodule, so we don't want black to try to change anything across the git boundaries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a comment mentioning the git submodule at the top of this file:
st2/st2tests/st2tests/fixtures/packs/BUILD
Lines 1 to 2 in 3e5d8df
| # The files in test_content_version* targets are in ./test_content_version | |
| # which is a git submodule. |
I suppose we can extend that comment if needed, because there are 3 targets that cover that git submodule. The shell_sources target has skip_shellcheck=True for similar reasons: don't complain about things across the git boundaries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can have a comment here to explain this one off disable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| python_sources( | ||
| name="test_content_version", | ||
| skip_black=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth a comment?
amanda11
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - but I think the vote is looking like preference for .lock extension on lockfiles.
|
👍 |
Helps with supply chain security too :) |
Background
This is another part of introducing
pants, as discussed in the TSC Meetings on 12 July 2022, 02 Aug 2022, 06 Sept 2022, and 04 Oct 2022. Pants has fine-grained per-file caching of results for lint, fmt (like black), test, etc. It also has lockfiles that work well for monorepos that have multiple python packages. With these lockfiles CI should not break when any of our dependencies or our transitive dependencies release new versions, because CI will continue to use the locked version until we explicitly relock with updates.To keep PRs as manageable/reviewable as possible, introducing pants will take a series of PRs. I do not know yet how many PRs; I will break this up into logical steps with these goals:
pantsto the st2 repo, andpantsstep-by-step.Other pants PRs include:
pants_ignoreand bump pants to v2.14.0rc1 #5733BUILDfiles with./pants tailor ::#5738Overview of this PR
This configures pants to use
blackwhen running thefmtandlintgoals.By default, pants uses
black==22.6.0, but I told it to use the version we have it pinned to:black==22.3.0:st2/test-requirements.txt
Line 8 in 83904f6
Pants uses a lockfile for each tool it uses to ensure we get consistent results. Since I changed
[black].versioninpants.toml, pants errors, saying that the lockfile (in this case the<default>lockfile distributed with pants) is out-of-date. Note how the message is very helpful in explaining exactly what has to happen to fix this:There will be a variety of lockfiles, so I created a directory to keep them all together somewhere other than the root directory of the project. I used
lockfiles/, but we could also use something likebuild-support/python/(other pants-based projects use something like this). I figure this is good enough for now. We can choose a different directory later, and reorganize the lockfiles, and possibly files like those underlint-configs/, into something that feels even cleaner.NOTE: it is not safe to manually change the lockfiles. If we need to change any dependencies (including transitive deps), we need to use pants to regenerate the applicable lockfiles. Therefore, 442 lines of this change are auto-generated - you can review them for sanity, but we should not change them manually.
I also updated to the latest pants 2.14.0rc3, the latest 2.14 release candidate.
Relevant Pants documentation
./pants fmtgoal./pants generate-lockfilesgoal./pants lintgoalpython_sourcespython_sourceThings you can do with pantsbuild
I needed to generate the
lockfiles/blacklockfile, which I did with this:This is the first PR that adds a
fmtbackend. So, now you can run./pants fmt ::to reformat files, or./pants lint ::to see if black would make changes onfmt(the GHA Lint workflow runs./pants lint ::). Note how pants says "black made no changes" more than once - that is because it runs tools concurrently wherever possible.