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

proud-dentist-22844

10/31/2022, 9:27 PM
Why is pant having issues inferring this
.api_models
import (I'm getting "Pants cannot infer owner" warning): https://github.com/st2sandbox/st2/blob/pants/pylint_plugins/api_models_test.py#L25 Here
/pylint_plugins
is a source root, and
/pylint_plugins/api_models_test.py
is using a relative import for
/pylint_plugins/api_models.py
:
from . import api_models
Does the dep inference not like relative imports?
1
e

enough-analyst-54434

10/31/2022, 9:39 PM
I mean, you can test that hypothesis in a heartbeat - right?
p

proud-dentist-22844

11/02/2022, 4:11 AM
Yeah. It turns out pants needed one style of imports, because it added that directory on the PYTHONPATH, but running pytest directly used a different import (w/o the dir on PYTHONPATH). When the dir is on PYTHONPATH, I have to do
import api_models
, when it is not on PYTHON_PATH, I have to do
from . import api_models
. I did a
try/except ImportError
to do both.
4 Views