-
-
Notifications
You must be signed in to change notification settings - Fork 745
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 pants-plugins/sample_conf
to streamline regenerating conf/st2.conf.sample
#5860
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pull-request-size
bot
added
the
size/L
PR that changes 100-499 lines. Requires some effort to review.
label
Jan 5, 2023
cognifloyd
requested review from
arm4b,
rush-skills,
amanda11,
nzlosh,
winem and
a team
January 5, 2023 08:32
cognifloyd
changed the title
Add
Add Jan 5, 2023
pants-plugins/sample_conf
to streamline regenerating conf/st2.conf/sample
pants-plugins/sample_conf
to streamline regenerating conf/st2.conf.sample
cognifloyd
force-pushed
the
pants-plugins-sample_conf
branch
from
January 5, 2023 08:35
21d936f
to
21d80d7
Compare
amanda11
reviewed
Jan 5, 2023
amanda11
approved these changes
Jan 5, 2023
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
rush-skills
approved these changes
Jan 10, 2023
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
cognifloyd
force-pushed
the
pants-plugins-sample_conf
branch
from
January 10, 2023 22:19
713a867
to
280d15c
Compare
codegen cannot update workspace files. It only puts files under dist/codegen. So, we will use fmt instead to make sure this gets updated as needed.
cognifloyd
force-pushed
the
pants-plugins-sample_conf
branch
from
January 10, 2023 23:30
280d15c
to
a54e76e
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
This is another part of introducing pants, as discussed in various TSC meetings.
Related PRs can be found in:
Overview of this PR
This PR improves the DX (developer experience) by wiring up the
fmt
andlint
goals to generateconf/st2.conf.sample
if needed (or for lint, warn that it needs to be done).This includes creating a
sample_conf
plugin for pants that adds asample_conf
target.Developer Experience
Today, if someone changes one of the files used to generate
conf/st2.conf.sample
, they will probably forget to run the Makefile target the regenerates them:make configgen
.I've missed running that several times. CI complains as part of the
ci-checks
Makefile target, with instructions toPlease run "make configgen"
. This also gets regenerated any time someone runs thelint
ortests
Makefile targets, which might be surprising (tests generally shouldn't handle codegen).With this PR, we add
st2.conf.sample
generation into thefmt
goal. This also adds it to thelint
goal which will tell people iffmt
needs to run to update any code (or in this case, regenerate the sample conf file). Then, we only need simple instructions that say something like:Fine grained results cache
After someone runs
./pants fmt ::
once, they will benefit from the pants' results cache. For the sample_conf plugin, here's what that means:First, the
sample_conf
target inconf/
depends ontools/config_gen.py
:st2/conf/BUILD
Lines 6 to 9 in 1faea8f
If the
config_gen
script changes, then pants now knows that the sample conf file need to be regenerated. Or, in other words, theconfig_gen.py
file is part of the cache key forconf/st2.conf.sample
. If that file changes, then pants will re-run the generator.For many of our scripts, we can depend on pants' python dependency inference to grab the other files. But, this script uses importlib instead of standard imports, so we need to add the dependencies manually (aside: there is a feature that tries to use strings for dep inference, but it is not enabled by default, and I have not tested to see how many false positives it will find across our repo). In the future, hopefully we can remove or simplify this.
st2/tools/BUILD
Lines 1 to 24 in 1faea8f
Please note the explicit dependency on
//:auth_backends
. Nothing in our code base directly imports from the auth backends. But, we ship with a default set of backends, so we need to make sure that their settings are included in the sample conf file's auth section. This is defined here:st2/BUILD
Lines 43 to 49 in 1faea8f
Then, I ran into one more dependency issue.
st2-auth-ldap
does not declare a dependency on ourst2auth
module, in part because that is an implicit dep for auth modules. We should probably make that explicit at some point, but that might require publishing more wheels on pypi. That's messy, but pants meets us where we are in this mess. 😄 So, we can tell pants that any time we grab thest2-auth-ldap
package, it requires something in thest2auth
module, like this:st2/BUILD
Lines 34 to 39 in 1faea8f
Then, once all of those deps that pants can't infer (for now) are recorded, pants is able to invalidate the st2.conf.sample cache if any of the dependency python source files (including all that get imported directly or transitively by
tools/config_gen.py
).This PR actually only wires up the
fmt
goal and took advantage of the fact that pants also runs formatters whenever it runs linters, which are side-effect free. And because pants runs the formatters in a sandbox, it doesn't have to materialize any changes during lint.Continuing the example, since pants cached the results when running the
lint
goal, runningfmt
will be very fast. Pants will just materialize the already-generated schemas from its cache.Developing pants plugins
Pants has extensive documentation on the plugin API, including how to create targets, how to write rules, and there's even a mini tutorial about how to add a formatter (adding formatters is a very common thing for plugins to do).