Hi all, I'm having problems with setting up pants ...
# general
p
Hi all, I'm having problems with setting up pants to work with a git submodule project - looks like dependencies specified in BUILD files for python sources using "overrides" are not prefixed with the subproject root? We are migrating to adopt pants in our project, before moving all of them to a single monorepo. We have one common code library already moved to pants. In our service, we use that common library as a git submodule, having a layout similar to the following:
Copy code
<root>
└── serviceA
    └──  (python sources, importing lib/moduleA.py)
└── common-lib (git submodule, already migrated to pants)
    └── src
        └── moduleA.py
        └── moduleB.py
    └── tests
        └── test_moduleA.py
    └── BUILD
    └── pants.toml
└── pants.toml
└── BUILD
pants.toml in submodule is ignored by pants (as expected). pants.toml in the root of the service repo contains the following:
Copy code
subproject_roots = [
  "/common-lib",
]

[source]
root_patterns = [
  "/service",
  "/common-lib",
]
Now, I understand that subproject_roots are intended to tweak the dependencies paths used in submodule's BUILD files by appending /common-lib to the path, if required. But it looks like this mechanism doesn't work, when I use "overrides" as below:
Copy code
python_tests(
    name="tests",
    overrides={
        "test_moduleA.py": {
            "dependencies": [
                "src/moduleB.py"
            ]
        }
    },
)
When running
pants test ::
from the root dir, I get the following error:
Copy code
ResolveError: The file or directory 'src/moduleB.py' does not exist on disk in the workspace, so the address 'src/moduleB.py' from the `dependencies` field from the target common-lib/tests/test_moduleA.py:tests cannot be resolved.
Now, I can change directory to common-lib and run
pants test ::
from there, and it works fine. But I was wondering if that could become a problem, if I will have at some point to specify some dependency using "overrides" in build file for some lib module that I actually need in the service. Is this the expected behavior? Thanks in advance for any help!
r
Where did you read about
subproject_roots?
I have never heard about it. What pants version is it? Also two
pants.toml
is completely new for me.
I'm using 2.16rc0, but it was added much earlier I think
Also two
pants.toml
is completely new for me.
this is only because our common-lib (built by pants) is a submodule of another git repo with a service, managed by pants as well. So, the nested pants.toml for submodule is ignored when building the service repo with pants.
But since your root repo still makes use of dependencies from subproject, you need those BUILD files to be processed by root pants config...
This is a temporary solution before we promote submodule to a full directory in the service repo as we slowly move to monorepo...
m
I'm having the same issue, someone know what is going wrong?
c
wow, TIL as I too wasn’t aware of this subproject roots option. Thanks! I wouldn’t be surprised if support for this option was overlooked when adding support for overrides. If you could provide minimal repro case in a github project along with an issue, that would be gold for us to work with solving this.