flat-zoo-31952
01/12/2022, 10:08 PMbusy-vase-39202
01/13/2022, 12:20 AMflat-zoo-31952
01/13/2022, 1:13 AMSOURCES_DEFAULT = (
'*.py', '*.pyi', '!test_*.py', '!*_test.py', '!tests.py', '!conftest.py', '!test_*.pyi', '!*_test.pyi', '!tests.pyi',
)
READY_FILES = ["alert_rule_verifier.py"]
python_sources(
sources=READY_FILES,
)
python_sources(
name="unready",
sources=[
*SOURCES_DEFAULT,
*(f"!{name}" for name in READY_FILES),
],
tags=["unready"],
)
I suppose this could be written in a macro if it worksbitter-ability-32190
01/13/2022, 4:41 PMlint
and check
shouldn't be too hard (at least that was my experience), as the dependency inference is quite good. I just turned on unowned_dependency_behavior
and played whack-a-mole with the errors until they stopped.
(We haven't gotten there yet, but) once you have lint
, I think test
really isn't hard to migrate either š¤ .
Really the challenges are verifying the built things (docker images or Python binaries)bitter-ability-32190
01/13/2022, 4:43 PMflat-zoo-31952
01/13/2022, 5:02 PMtest
. Switching to {test, run, package} will be a long journey of integrating Pants with RPM and doing hermetic builds in lightweight containers rather than just pexes in temp dirs. And in general our dependency graph is a total mess.flat-zoo-31952
01/13/2022, 5:12 PMflat-zoo-31952
01/13/2022, 5:15 PMflat-zoo-31952
01/13/2022, 5:19 PM./pants dependees --changed-since=$MERGE_TARGET
fits in the blessed set of files we trust to run through pants, we can skip whole sections of the legacy pipelineclean-city-64472
01/13/2022, 6:34 PMclean-city-64472
01/13/2022, 6:35 PMhundreds-father-404
01/13/2022, 7:59 PMwe could use Pants to direct the CI pipeline.To do what, in particular? I agree with Joshua that
fmt
and lint
are good entry-points and realistic to run over whole repo. Unless you use Pylint, no need to teach Pants about any third-party dependencies at all.flat-zoo-31952
01/13/2022, 8:49 PMfmt
and lint
don't have to think about deps, which also makes them easy to run on changed files without Pants...
CHANGED_PY_FILES="$(git diff --name-only --diff-filter=MRA $TARGET_REF '*.py')"
which is how we do this already. So it's not much of a value-add for us to start with this.flat-zoo-31952
01/13/2022, 9:03 PMTo do what, in particular?To run only tests that are part of the transitive dependencies of the changed set of code. Something like
./pants dependees --changed-since=$TARGET_REF | xargs ./pants filter --target-type=python_test --granularity=file | cut -d: -f1
will give you paths you can pass to pytest
directlyflat-zoo-31952
01/13/2022, 9:11 PMflat-zoo-31952
01/13/2022, 9:13 PMflat-zoo-31952
01/13/2022, 9:14 PM./pants list $(git diff --name-only --diff-filter=MRAC $TARGET_REF)
which will fail if you pass it files that aren't assigned to a Pants targetflat-zoo-31952
01/13/2022, 9:20 PMtargets()
with tags š¤hundreds-father-404
01/13/2022, 9:21 PMskip_tests
+ peek
? https://www.pantsbuild.org/docs/existing-repositories#3-set-up-testsflat-zoo-31952
01/13/2022, 9:23 PMfilter
hundreds-father-404
01/13/2022, 9:26 PMskip_tests
is ./pants test ::
will Just Workflat-zoo-31952
01/13/2022, 9:30 PM./pants test
though without a good bit of work to either create a hermetic RPM-based environment on the fly, or to create some hack to make it run non-hermeticallyflat-zoo-31952
01/13/2022, 9:31 PMhundreds-father-404
01/13/2022, 9:41 PMskip_tests
isn't as useful because they all need to be skipped.
answering "does Pants know about the files in this changeset?" seems to be easy to answer withThat will answer if the changed file is known about, but you still need to answer if the dependees of that file are blessed. It might be useful to error on unrecognized imports so that you can be more confident dependencies are valid: https://www.pantsbuild.org/docs/reference-python-infer#section-unowned-dependency-behavior Maybe only create targets for blessed code? Use the new
tailor
ignore options so Pants doesn't try to add targets for those. https://www.pantsbuild.org/docs/create-initial-build-filesflat-zoo-31952
01/13/2022, 9:55 PM!inverted_patterns
but that didn't work (have it on my todo to report this as a bug/issue)flat-zoo-31952
01/13/2022, 9:56 PMflat-zoo-31952
01/13/2022, 9:57 PMflat-zoo-31952
01/13/2022, 9:58 PMhundreds-father-404
01/13/2022, 10:03 PMready
target vs. not ready
target, You'll use a macro or could use the new Target Generation plugin API to approach that. You'd use tags
to indiciate which is which, or alternatively could add a new plugin field like "blessed": https://www.pantsbuild.org/docs/target-api-extending-targets
2) Treat BUILD files like normal, i.e. what ./pants tailor
would do. But also have some targets
and put in their dependencies
what is blessed.
That then seems like a philosophical question of where the "blessed" metadata should live: do you want it centralized? Or decentralized to each directory?flat-zoo-31952
01/13/2022, 10:05 PMhundreds-father-404
01/13/2022, 10:06 PMflat-zoo-31952
01/13/2022, 10:06 PMflat-zoo-31952
01/13/2022, 10:07 PMflat-zoo-31952
01/13/2022, 10:08 PMflat-zoo-31952
01/13/2022, 10:08 PMhundreds-father-404
01/13/2022, 10:12 PMAnd the graph question becomes... "Do all paths in this transitive closure of dependees terminate in a blessed target?", just need to translate that into a query I ask pantsAre you going to explicitly list every file in the `target`'s
dependencies
? If so, you could run ./pants dependencies path/to:target_blesser
(not --transitive
) and save that list. Then, I think your earlier command of ./pants --changed-since --changed-dependees=transitive
and check that everything is in the earlier list.
And then you'll probably want to use that unowned_dependencies_behavior
optionhundreds-father-404
01/13/2022, 10:12 PMtest
, which is a non-starterflat-zoo-31952
01/13/2022, 10:24 PMpython_sources(name="sources")
files(name="conf", sources=["*.yml"])
target(name="dummy_linker", dependencies=["sources", "conf"])
flat-zoo-31952
01/13/2022, 10:24 PMflat-zoo-31952
01/13/2022, 10:25 PMflat-zoo-31952
01/13/2022, 10:39 PM./pants dependees --changed-since=$branch --transitive
must be a subset of ./pants dependencies --transitive path/to:blessed_targets
hundreds-father-404
01/13/2022, 10:43 PM./pants --chanced-since=$branch --changed-dependees=transitive list
for the first query btw. Otherwise if you use dependees
I think you want to use --closed
to ensure the input targets are included