bitter-tiger-53933
04/13/2022, 10:44 AM-- pants.toml
-- helloworld1
-- src
-- functions
-- BUILD
-- plus.py
-- helloworld2
-- src
-- functions
-- BUILD
-- plus.py
-- helloworld3
--src
-- functions
-- BUILD
-- plus.py
-- multiply.py
-- function_tests
-- BUILD
--test_plus.py
In helloworld3/src/function_tests/test_plus.py
I have
from src.functions.plus import foo
I need this import to be from the helloworld3/src
path.
When i run the test file test_plus.py I get this error
ModuleNotFoundError: No module named 'src.functions'
I'm also getting warnings like
`The target helloworld3/src/function_tests/test_plus:tests imports helloworld3.src.functions.plus.foo
, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use:`
['helloworld3/src/functions/core/plus.py', 'helloworld2/src/functions/core/plus.py', 'helloworld1/src/functions/core/plus.py'].
I have a pants.toml in the root folder which has
[source]
root_patterns = [
'/helloworld1/',
'/helloworld2/',
'/helloworld3/',
]
Is this the correct way of setting things up? What am I doing wrong? I think my understanding of pants targets and sources hasn't 'clicked' yet, hopefully you can also help to make that right 🙂 Thanks in advance!
Obviously i've replaced the real filenames with fake names. If that is not enough then please do shout and I'll look into creating a stripped down example monorepo with this error on github.enough-analyst-54434
04/13/2022, 3:32 PMsrc.functions.plus
- that's a problem generally before even involving Pants. Does that naming duplication actually reflect what you're trying to achieve? Python does support namespace packages where a package can have sub-packages and modules added to it from many locations on disk (src.functions
is one of those here), but there is no such thing as a namespace module. Languages like c# have partial classes that allow something like this, but not Python.enough-analyst-54434
04/13/2022, 3:39 PMenough-analyst-54434
04/13/2022, 3:40 PMbitter-tiger-53933
04/13/2022, 4:24 PMhundreds-father-404
04/13/2022, 4:33 PMbitter-tiger-53933
04/13/2022, 4:39 PMenough-analyst-54434
04/13/2022, 4:40 PMsrc/functions/core/plus.py
identical in all 3 locations?enough-analyst-54434
04/13/2022, 4:40 PMenough-analyst-54434
04/13/2022, 4:40 PMenough-analyst-54434
04/13/2022, 4:41 PMhappy-kitchen-89482
04/13/2022, 4:47 PMrefined-addition-53644
04/21/2022, 9:21 AMtests
package in multiple python packages inside a mono-repo. I have tests at same hierarchy for 3 packages and inside tests folder I have some test resources which I am importing like
from tests.testdata import some_data
It's not necessary that testdata
exists inside every tests
folder of these 3 packages though.
What would be the pants way to handle this?
I am having weird issues where pants can't find some packages etc, but not sure if this is connected or not.happy-kitchen-89482
04/21/2022, 2:59 PMtests
package defined in multiple source roots?happy-kitchen-89482
04/21/2022, 3:00 PMsome_data
in your example) don't conflictrefined-addition-53644
04/21/2022, 3:02 PMtests
I am talking about? yeah every source_root
has its own tests
directoryhappy-kitchen-89482
04/21/2022, 3:07 PMhappy-kitchen-89482
04/21/2022, 3:08 PMtests.testdata.some_data
is unique, you should be OKhappy-kitchen-89482
04/21/2022, 3:08 PM