early-businessperson-60137
01/09/2025, 9:29 PMpants
for our monorepo (we've heard many tales of companies who spent years migrating to bazel and then years migrating off of it....).
Our repo isn't huge, but I'm exploring what a migration would look like and hoping there might be some prior art here. We currently use pip-compile-multi (pip tools under the hood) to generate requirements.txt files for ~5-10 requirements.in files and enforce one version per third party library across our repo. Has anyone written up migration guides, or have tips and tricks about how we might mix and match during the migration so we don't need to try to merge in one massive PR?early-businessperson-60137
01/10/2025, 3:34 AM-r ../foo/requirements.txt
in requirements files. This would make migrating from pip tools easier for sure. For now I can workaround by doing a cat reqs1.txt reqs2.txt > requirements.txt
2. Migrating test targets piecemeal. I really want to use --changed-since
to not run every single test target, but I can't go through and get every single test target in the whole repo to pass in one PR. I wanted to do --changed_since=HEAD subdirectory/with/passing/tests::
but that fails because you can't use globs and --changed_since. I haven't found a workaround here yet. Is there a way perhaps to pipe output from pants changed --since=HEAD list | ...
to apply a filter? I also imagine this is needed functionality when running pants on a large monorepo where you don't want to run all affected tests in the whole repo in every CI/CD flowearly-businessperson-60137
01/10/2025, 3:37 AMpants --changed-since=origin/dev list | grep '^backend' | xargs pants test
works, but it definitely feels a bit janky. I'd love to be able to use glob syntaxearly-businessperson-60137
01/10/2025, 4:21 AMpants test
to work within a docker container with --network=None
. We run our tests from within a dockerfile so we can setup some extra dependencies (postgres, playwright), and --network=None guarantees that the tests themselves are hermetic and don't depend on the network.
I'm thinking we can probably get the target list during the build stage, but I couldn't find a command to build all the test targets in advance, so that pants test
doesn't need any network access because the .pex
targets already exist. pants package
doesn't seem to work on python_test targets. Any ideas?broad-processor-92400
01/10/2025, 4:44 AM--filter-...
options: https://www.pantsbuild.org/prerelease/docs/using-pants/advanced-target-selection, e.g.
• apply either positive or negative tags to the relevant tests and select with --filter-tag-regex=migrated
or deselect them with --filter-tag-regex=-not_yet_migrated
• use --filter-address-regex=subdirectory/with/passing/tests/.*
(or similar) for the dir-based globbingbroad-processor-92400
01/10/2025, 4:48 AMI'm thinking we can probably get the target list during the build stage, but I couldn't find a command to build all the test targets in advance, so thatI think there's two broad options: • docker container -> pants -> python tests (i.e. run pants inside the container) • pants -> docker container -> python tests (i.e. have pants run "bare metal" and coordinate a docker container) The second one is possible with "environments": https://www.pantsbuild.org/prerelease/docs/using-pants/environments... but it might not expose the required options to disable networking 🤔 so that'd be a feature request/improvement to pants. But, if you're willing to tolerate that hermeticity-hole, that might be a path forward for now?doesn't need any network access because thepants test
targets already exist..pex
doesn't seem to work on python_test targets. Any ideas?pants package
broad-processor-92400
01/10/2025, 4:53 AMpants test :: -- --some-flag-that-makes-the-actual-execution-really-fast
, so the tests are built and "executed", but that doesn't feel great.early-businessperson-60137
01/10/2025, 4:53 AMearly-businessperson-60137
01/10/2025, 4:54 AMbroad-processor-92400
01/10/2025, 4:56 AM--collect-only
)broad-processor-92400
01/10/2025, 4:57 AMdocker_environments
and then have each test carefully specify the appropriate environment.
Then, pants would spin up container(s) using the appropriate images, when running the tests in question.broad-processor-92400
01/10/2025, 4:58 AMbroad-processor-92400
01/10/2025, 4:58 AMearly-businessperson-60137
01/10/2025, 5:04 AMpants test
run?broad-processor-92400
01/10/2025, 5:05 AMearly-businessperson-60137
01/10/2025, 5:24 AMbroad-processor-92400
01/10/2025, 5:27 AMif env("CI", "0") == "1":
docker_environment(name="testing", ...)
else:
local_environment(name="testing", ...)
broad-processor-92400
01/10/2025, 5:28 AMearly-businessperson-60137
01/10/2025, 5:29 AMearly-businessperson-60137
01/10/2025, 5:32 AMpython_sources(sources=["!my_source.py", "*.py", "!test_*.py", "!*_test.py"])
early-businessperson-60137
01/10/2025, 5:32 AMbroad-processor-92400
01/10/2025, 5:38 AMsources
papercut being a pain. You may be interested in `overrides`: python_sources(..., overrides={"my_source.py": dict(dependencies=[":something_extra"], other_field_too=True, ...))
will set those fields specifically for my_source.py
without needing the separate target
(https://www.pantsbuild.org/stable/docs/using-pants/key-concepts/targets-and-build-files#target-generation briefly mentions it, and https://www.pantsbuild.org/dev/reference/targets/python_sources#overrides has some more discussion too)