Hi everyone, I'm setting up a monorepo with Pantsb...
# general
r
Hi everyone, I'm setting up a monorepo with Pantsbuild and encountering an issue with source roots. My project structure looks like this:
Copy code
src/python/libs/lib1
src/python/libs/lib2
src/python/machines/p1
src/python/machines/p2
src/python/machines/p3
The source roots are configured as
/src/automation/python/*/*/
. Running
pants dependencies
on any of the libs correctly infers all first-party and third-party dependencies. However, running the same command on any of the projects results in warnings that Pants cannot infer owners for certain imports. Here's the specific issue: • The projects (
p1
,
p2
,
p3
) have very similar structures and contain files with the same filenames. • When these files are imported in the projects, Pants throws warnings that it cannot infer the owners of these imports, likely due to the filename duplication across the projects. How can I set up the source roots or configure Pants to resolve these imports correctly?
h
That depends on what the correct inference is... Within a source root Pants should resolve ambiguity by selecting the symbol from the same source root. But if you have genuinely ambiguous cross-source-root deps then how can Pants know which one you mean?
In that case you probably need a manual dependency in the BUILD file
An example of your case would be helpful though
r
Hi Benjy, Thanks for your quick response! To clarify, all the
BUILD
files for the
p
projects look the same and are structured like this:
Copy code
python_sources(
    name="p160",
    sources=[
        "main.py",
        "src/*.py",
        "src/**/*.py",
    ],
    dependencies=[
        "src/automation/python/libs/gutils:gutils",
        "src/automation/python/libs/gvision:gvision",
        "src/automation/python/machines/shared:shared",
        "3rdparty/python:default-requirements#PyQt5",
        "3rdparty/python:default-requirements#pyLucidIo",
    ],
)
For example, all
p
projects have src/app.py
I guess I can solve this by renaming the
src
folder to something unique per project
h
Well,
src
is above your source root, so that won't help
you ideally would like to have unique import paths
But in the existing setup, which dep inference is failing? What is a specific example of a dependency that shouldn't be ambiguous but Pants sees as ambiguous?