I'm having trouble with first-party imports. My pr...
# general
e
I'm having trouble with first-party imports. My project layout is
Copy code
.
├── auth
│   ├── __init__.py
│   └── flask_auth.py
└── events_service
    ├── __init__.py
    └── app.py
The error is:
Copy code
Pants cannot infer owners for the following imports in the target event_service/app.py:

  * auth.token_auth (line: 4)
This package from
auth/__init__.py
:
Copy code
from .flask_auth import token_auth
It looks like packages defined in ``__init__.py`` files is not detected.
b
sorry for the trouble. What's your source root configuration in
pants.toml
?
e
Copy code
> pants roots
auth
event_service
./pants.toml
Copy code
[source]
root_patterns = [
  "/auth",
  "/event_service",
]
I changed event_service/app.py from
Copy code
from auth import token_auth
to
Copy code
from auth.flask_auth import token
and
pants dependencies event_service/app.py
succeeded. Reverting my app.py change leaves it in a working state.
(So I kinda broke the repro)
b
Ah, hm, I suspect your source-roots aren't communicating what you hope to pants. A source root defines a directory that holds packages, not the packages themselves. For instance, with your current roots, pants will understand
import flask_auth
as referring to
flask_auth.py
, because it's an immediate child of a source root. It looks like it should be
from auth import flask_token
, i.e. "auth" is the package name. Thus, I think a
root_pattern = ["/"]
might be what you need.
e
Ah I see. Yep that's probably it. I do need to restructure the folders a bit - they were all separate git projects before.
👍 1
Thanks for the help!
👍 1
source root defines a directory that holds packages, not the packages themselves
Great explanation
👍 1