Pants’ dependency inference is unsuccessful for im...
# general
h
Pants’ dependency inference is unsuccessful for importing objects from
_init_.py
files. I have a file structure like:
Copy code
proj
-- src
  -- main.py
-- __init.py
Files containing:
Copy code
# __init__.py
import logging
logger = logging.getLogger(__name__)

# src/main.py
from proj import logger
I have set
[python-infer].init_files = always
but that doesn’t seem to make a difference here. Am I missing something?
Copy code
[python-infer]
ambiguity_resolution = "by_source_root"
^ doesn’t seem to help either, which I would’ve assumed would
b
What are your source roots set to? Ex: what comes up when you run
pants roots
?
h
proj
is in source roots in this scenario. I did get to the bottom of the problem though.
proj/__init__.py
wasn’t owned so when the
from proj import logger
symbol was being resolved this implied no ownership for that also.
There’s an opportunity for a more informative error message here since
[WARN] Pants cannot infer owners for the following imports in the target …
is very general. If the consumer is owned by something but its local dependency is not then it would be more helpful to point to
proj/__init__.py
not being owned rather than an ambiguity problem