Configure pantsbuild source roots #5724
Merged
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 part 2 of introducing
pants
, as discussed in the TSC Meetings on 12 July 2022, 02 Aug 2022 and 06 Sept 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:
pants
to the st2 repo, andpants
step-by-step.Previous pants PRs include:
Overview of this PR
This PR configures pants source roots.
https://www.pantsbuild.org/docs/initial-configuration#configure-source-roots
This is based on a lot of work in a PoC pants branch where I experimented with a several approaches to define source roots. This was the most robust, and includes a comment to document why.
We can probably simplify this config by moving the packs in
contrib/
into a separate directory likecontrib/packs/
. But that is out-of-scope until after we remove the Makefile and other CI infrastructure that expects those packs to be directly undercontrib/
.pants.toml
config filehttps://www.pantsbuild.org/docs/initial-configuration#create-pantstoml
Many important things get configured in the
pants.toml
config file, but this PR only configures[source].root_patterns
. I also tried using[source].marker_filenames
but that didn't work very well in our repo with how we symlink thecore
pack into st2tests' fixture packs.[source].root_patterns
Essentially,
[source].root_patterns
tells pants where to find python modules (eg to infer dependencies between them) and how to configurePYTHONPATH
/sys.path
.Detailed docs on pants source roots are available here:
For StackStorm, we need a root for each python module (each core lib and each runner) and each pack. Plus there are some tool/util directories that we also needed to add to source roots.
Things you can do with pantsbuild after this PR
This PR does not wire up any lockfiles, formatters, linters, etc, yet. But you can test that pants resolves the source roots correctly with
./pants roots
.$ ./pants roots . contrib/chatops contrib/core contrib/default contrib/examples contrib/examples/lib contrib/hello_st2 contrib/linux contrib/packs contrib/runners/action_chain_runner contrib/runners/announcement_runner contrib/runners/http_runner contrib/runners/inquirer_runner contrib/runners/local_runner contrib/runners/noop_runner contrib/runners/orquesta_runner contrib/runners/python_runner contrib/runners/remote_runner contrib/runners/winrm_runner pylint_plugins scripts st2actions st2api st2auth st2client st2common st2common/benchmarks/micro st2reactor st2stream st2tests st2tests/testpacks/checks st2tests/testpacks/errorcheck tools