fierce-fall-70380
01/27/2025, 3:51 PMfierce-fall-70380
01/27/2025, 3:51 PMpython_sources()
python_requirements(
name="reqs",
source="requirements.txt",
)
fierce-fall-70380
01/27/2025, 3:51 PMpants roots
that it is properly inferring all the source roots via my marker_filenames
config, but pants dependents path/to/some/py_file
is not yielding any output.fierce-fall-70380
01/27/2025, 3:52 PMpants tailor
(for now).elegant-florist-94385
01/27/2025, 3:56 PMpants tailor src/python/somemodule/something::
to only tailor a piece of your repo at a time, if that's helpful?fierce-fall-70380
01/27/2025, 4:01 PMIs a BUILD file required underneath every source root?It sounds like yes...
elegant-florist-94385
01/27/2025, 4:04 PMpython_sources(sources="**/*.py")
in a build file, and then you just need one build file ever, but its not particularly friendly for maintenance in the future.
The general recommendation is to have one BUILD file per directory. I know its a bit of a hurdle when first migrating, but from my experience it fades into the background and stays out of your way fairly well.fierce-fall-70380
01/27/2025, 4:05 PMelegant-florist-94385
01/27/2025, 4:55 PMhappy-kitchen-89482
01/29/2025, 6:15 AMtailor
creates these by default, but you could also have one top-level BUILD file per source root that uses **/*.py
globs or similar.happy-kitchen-89482
01/29/2025, 6:15 AMhappy-kitchen-89482
01/29/2025, 6:17 AMtailor
does one BUILD file per dir is that in the past if you had a coarse-grained top-level BUILD file and then you wanted to change the metadata of just one file or dir, you had to then split up that BUILD file into multiple (one per subdir at least), and it was quite a hassle to do so.happy-kitchen-89482
01/29/2025, 6:18 AMoverrides=
, where you can tweak the metadata of just one file in an existing target, that might not be as necessary any morehappy-kitchen-89482
01/29/2025, 6:19 AMfierce-fall-70380
01/29/2025, 2:06 PMhappy-kitchen-89482
01/30/2025, 6:41 AMhappy-kitchen-89482
01/30/2025, 6:42 AMsources=
for the various target types, as they are not recursive globs, so youâd have to be specific about thosehappy-kitchen-89482
01/30/2025, 6:43 AMpython_sources()
and python_tests()
donât overlaphappy-kitchen-89482
01/30/2025, 6:43 AM**/
prefixeshappy-kitchen-89482
01/30/2025, 6:43 AMtailor
to handle thisfierce-fall-70380
01/30/2025, 12:24 PM__defaults__(
all=dict(
sources=(
"**/*.py",
"**/*.pyi",
"!**/test_*.py",
"!**/*_test.py",
"!**/tests.py",
"!**/conftest.py",
"!**/test_*.pyi",
"!**/*_test.pyi",
"!**/tests.pyi",
)
)
)
happy-kitchen-89482
01/30/2025, 2:32 PMfierce-fall-70380
01/30/2025, 2:50 PMfierce-fall-70380
01/30/2025, 2:52 PMambguity_resolution = "by_source_root"
.
We have quite a few duplicate module names across the repo -- e.g. base.py
, util.py
, etc. I think Pants might be having trouble with ownership identification using these recursive source rules instead of putting a BUILD file in every subfolder. Trying to confirm this theory now.fierce-fall-70380
01/30/2025, 2:55 PMfoo/a/base.py
and foo/b/base.py
, and then for a module like foo/a/bar.py
to have a statement import base
(to import the base module from the local subfolder) instead of import foo.a.base
.fierce-fall-70380
01/30/2025, 2:55 PMfierce-fall-70380
01/30/2025, 3:07 PM11:01:55.46 [WARN] The target foo/reports_summary.py imports `base`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['foo/base.py', 'foo/etest/test_foo/base.py', 'foo/etest/test_foo/test_bar/base.py', 'foo/etest/test_foo/test_qux/base.py', 'foo/sub/a_configs/base.py', 'foo/sub/b_configs/base.py', 'foo/sub/c_configs/base.py', 'foo/test/test_sub/test_c_configs/base.py'].
(sorry for having to semi-anonymize the filenames)
So basically, foo/reports_summary.py
has a line import base
which intends to import foo/base.py
. But there are a bunch of other modules named base.py underneath the foo/
subfolder hierarchy seemingly causing the issue.fierce-fall-70380
01/30/2025, 3:08 PMby_source_root: Choose the provider with the closest common ancestor to the consumer's source root.
^ I am confused though because shouldn't foo/base.py
be the "closest common ancestor" to foo/reports_summary.py
?fierce-fall-70380
01/30/2025, 3:17 PMhappy-kitchen-89482
01/30/2025, 3:24 PMhappy-kitchen-89482
01/30/2025, 3:25 PMhappy-kitchen-89482
01/30/2025, 3:25 PMfierce-fall-70380
01/30/2025, 6:40 PMfierce-fall-70380
01/30/2025, 6:41 PMrm -rf .pants.d
, maybe I was in an inconsistent state? đ¤ˇââď¸ Thanks so much for the help!happy-kitchen-89482
01/31/2025, 7:05 PMhappy-kitchen-89482
01/31/2025, 7:05 PMhappy-kitchen-89482
01/31/2025, 7:05 PMrm -rf .pants.d
shouldnât affect results at all, just performancehappy-kitchen-89482
01/31/2025, 7:06 PM