Hi all, I'm trying to play around roots <https://w...
# general
d
Hi all, I'm trying to play around roots https://www.pantsbuild.org/docs/source-roots but cannot manage it. I have two projects:
Copy code
|--news
|------src
|----------api
|--------------application.py
|----------tests
|--------------test_application.py
|--common
|------src
|----------common
|--------------utils.py
|----------tests
|--------------test_utils.py
In
application.py
I want to import function
run
from
utils.py
. I can do it only using from
from common.src.common.utils import run
but I'd like to have
from common.utils import run
(now it raises: "No module named common.utils") Command
pants roots
says:
Copy code
.
common/src
news/src
In
test_utils.py
I can import
from common.utils import run
In
test_application.py
I can import
from api.application import something
common
BUILD file looks like: (
Copy code
python_library(
    name = "common",
    sources = [
        "src/common/*.py"
    ],
    interpreter_constraints=[">=3.6.9"]
)

python_tests(
    name = "common_test",
    sources = [
        "src/tests/test_*.py"
    ],
    dependencies = [
        ":common"
    ],
    interpreter_constraints=[">=3.6.9"]
)
news
BUILD file looks like:
Copy code
python_library(
    name = "news",
    sources = [
        "src/api/*.py",
    ],
    dependencies = [
        "common:common"
    ],
    interpreter_constraints=[">=3.6.9"]
)

python_tests(
    name = "news_test",
    sources = [
        "src/tests/test_*.py"
    ],
    dependencies = [
        ":news",
        "common:common"
    ],
    interpreter_constraints=[">=3.6.9"]
)
Do you have an idea what else should be configured there?
h
👀
At first glance your source roots look set up correctly
Ah, I think your BUILD files need to be under the source roots
So you need
news/src/BUILD
and
/common/src/BUILD
If you move the BUILD files (and change the source globs appropriately) does that work?
d
Thank you for your answer 🙂 I can say: it works but now I'm not able to run all test from my root directory. Before I called it
./pants test ::
Also to run test for single project I need to run
./pants news/src:news_test
Is it possible to still work on names like
news
,
common
instead of
news/src
,
common/src
?
h
You can still do
./pants test ::
The
::
just means
all targets under the root
Generally if you want to target a single test you have to use the path from the root, so
./pants test news/src/tests::
for example. But that was true before - this is unrelated to source roots.
What is it that worked before and doesn't work now?