https://pantsbuild.org/ logo
#general
Title
# general
c

clever-father-91273

02/27/2023, 12:18 PM
Hi everyone, I'm new to Pants and I'm having some trouble with setting up the resolves. I would appreciate some advice! In my root dir, I have two submodules, let's call them
project
and
utils
. Both contain python code and have their own requirements.txt files.
project/requirements.txt
includes utils' requirements:
-r ../utils/requirements.txt
since project's code imports utility functions. This setup has been working fine (I have been able to run
pants test
command) until I decided to set up the resolves for the two submodules. When I run
pants test
, I'm constantly getting the following error:
ModuleNotFoundError: No module named utils
. This comes from one of the `project`'s test scripts which tries to import a function from the utils directory. I have been able to include `utils`' dependencies to `project`'s resolve by using the
parametrize
keyword, but I'm unable to include the
utils
submodule itself. Thanks in advance for any help!
r

refined-addition-53644

02/27/2023, 12:20 PM
Hey! Most probably a source root issue. Can you tell us what is/are your source roots?
c

clever-father-91273

02/27/2023, 12:21 PM
The Pants source is at the root dir,
root_patterns=["/"]
. Is this what you meant?
r

refined-addition-53644

02/27/2023, 12:22 PM
Yeah
c

clever-father-91273

02/27/2023, 12:22 PM
This is intended so that, in the `project`'s python files, I can
from utils import ....
r

refined-addition-53644

02/27/2023, 12:26 PM
That root pattern looks fine then. Now I guess somewhere your resolves' parametrization isn't working. What resolve do you use for the tests?
c

clever-father-91273

02/27/2023, 12:28 PM
In
project/tests/BUILD
I have
python_tests
with
resolve="project"
and
dependencies=["utils:reqs"]
r

refined-addition-53644

02/27/2023, 1:00 PM
I am out of solutions. Let's wait for someone from pants core members who might have better idea
h

happy-kitchen-89482

02/27/2023, 5:43 PM
Hi! It sounds like you want a single resolve for both sets of requirements (since one is a strict subset of the other)?
How are you setting up the resolves in pants.toml?
c

clever-father-91273

02/27/2023, 6:34 PM
Hi Benjy, I actually need separate resolves to acomodate submodules that will be added in the future. But I managed to solve my problem by adding
utils:utils
to project's test dependencies. Thanks!
h

happy-kitchen-89482

02/27/2023, 9:13 PM
Ah, cool!
Can you explain more about the separate resolves? Usually you only need separate resolves when the two are incompatible, but in your case one is a subset of the other, so they would have to be compatible?
c

clever-father-91273

02/28/2023, 10:17 AM
Sure! What I'm trying to do is to gradually move to a monorepo architecture from multiple repositories. In the example I provided there are only two submodules whose requirements are compatible, but in the future I will be adding more that might be conflicting, so I wanted to have a robust setup already.
h

happy-kitchen-89482

02/28/2023, 3:24 PM
Makes sense!
In the long run you might benefit from consolidating down to fewer resolves (1 is best!), but this is a good way to start merging repos!
3 Views