After making some proof of concept for a self-cont...
# general
r
After making some proof of concept for a self-contained subproject I'm trying to run
./pants check subproject/some/deep/test/directory::
, but the tool complains that a test directory in a completely different subproject isn't covered by the source roots. Is there a way to diagnose why Pants is complaining about this? I tried
./pants dependencies subproject::
and it has the same problem.
I set
[source].root_patterns = []
in the toml and
[source].marker_filenames = ["SOURCE_ROOT"]
. Only
subproject
and a directory that wraps it have SOURCE_ROOTs.
h
I suspect that what’s going on is this: in order to do dependency inference, Pants has to look at all .py files that might provide dependencies, so it needs source roots for everything.
You can tell Pants to ignore that other test directory entirely for now
r
That works, although I'm not sure why these libraries are being picked up at all if the source roots exclude them and the project I'm working on aren't using them (AFAIK)
It's just those two for some reason. I'm wondering if there's a spurious dependency resolution
h
Pants has to build a map of possible suppliers of any imported symbol, so it sees those .py files and wants to know what symbols they might provide, which requires the source root
That’s what powers dependency inference and allows you not to have to manually write deps into BUILD files
r
Hmm alright. That's a bit strange. I would think the purpose of (lack of) source roots is to say explicitly "I don't want these files to be considered in the universe of possible dependency resolutions". It seems like for incremental adoption we'd have to exclude everything to be safe.
👍 1
h
Yeah, I can see how that’s confusing. And possibly that is how source roots should work.
Right now they are a more passive concept where the idea is that everything not pants-ignored is under consideration, and some subset of those things may have the concept of a “source root”, in which case we look up the source root for that thing as needed
The fact that you would expect source roots to be more of a definition of “this is what I want Pants to even care about” is very helpful feedback!
r
What's the current use case of source roots? To disambiguate how absolute package imports should be resolved?
h
Exactly, it’s to know what the corresponding sys.path entry should be so that the code in the file can be imported
r
Gotcha. It does seem like a fairly distinct concept from Pants build coverage. Created https://github.com/pantsbuild/pants/issues/16946 to suggest a solution here.
👀 1
🙏 1