So I just spent several hours rewriting hundreds o...
# general
f
So I just spent several hours rewriting hundreds of imports in our monorepo to be relative to the outer source root. I'm now down to a handful of inference warnings that I'm struggling to resolve. đź§µ
Here is one inference error:
Copy code
13:28:57.24 [WARN] Pants cannot infer owners for the following imports in the target fooserv/itest_fooserv/fooserv_itest_helper.py:

  * email_first (line: 50)

If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/2.24/docs/using-pants/troubleshooting-common-issues#import-errors-and-missing-dependencies> for common problems.
Here are the imports on line 50:
Copy code
from web import email_first, login, mfa
Note:
Copy code
ACAM-M-RWLH: acam$ pants list fooserv/web/email_first.py fooserv/web/login.py fooserv/web/mfa.py
fooserv/web/email_first.py
fooserv/web/login.py
fooserv/web/mfa.py
ACAM-M-RWLH: acam$
I've confirmed the contents of email_first.py don't matter (I still get the inference error if I replace it with a zero byte file). There are also no other modules with the same name over the whole monorepo.
m
Could you try adding
__init__.py
? That might fix it...
f
Yep there's already a
web/__init__.py
...
m
Maybe try
-ldebug --keep-sandboxes=always
to see if that gives any insight?
f
I'll try it. By the way does
--keep-sandboxes
work when using just the pants binary / scie-pants? Or do you have to run it from the git repo for that to work? I've tried that option before but never received any output confirming the sandbox would be kept or where it's located.
m
I think it works for most cases... I haven't found a case when it doesn't...
👍 1
f
Ok this is interesting. I changed the import line to add another (unused) import from that same directory, and now that's the one it complains about:
Copy code
-from web import email_first, login, mfa
+from web import logo, email_first, login, mfa
Copy code
15:14:05.54 [WARN] Pants cannot infer owners for the following imports in the target fooserv/itest_fooserv/fooserv_itest_helper.py:

  * logo (line: 50)

If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/2.24/docs/using-pants/troubleshooting-common-issues#import-errors-and-missing-dependencies> for common problems.
This really smells like a bug ...
m
Ah... I think your import path is incorrect. Does this work?
Copy code
from fooserv.web import logo
f
No because
/
is not a source root.
Ok yeah, I rearranged the imports, and now it's complaining about
mfa
instead:
Copy code
-from web import email_first, login, mfa
+from web import mfa, email_first, login
🤔
m
I think it just complains at the import it first hit.
f
It is not that simple because
from web import login, mfa
works without error!
So strange. Have to run, back in awhile ... thanks for the help @microscopic-knife-5995
> This really smells like a bug ... 🚨 If I move the
web
imports line closer to the top of the import statements, I don't get the inference error. That definitely seems like a bug.
Maybe try
-ldebug --keep-sandboxes=always
to see if that gives any insight?
According to the docs, when you run with
--keep-sandboxes
you are supposed to see a message like:
Copy code
21:26:13.55 [INFO] preserving local process execution dir `"/private/var/folders/hm/qjjq4w3n0fsb07kp5bxbn8rw0000gn/T/process-executionQgIOjb"` for "Run isort on 1 file."
That message is never printed for me when using the
pants dependents
goal, though.
h
FWIW
--keep-sandboxes
should always work, and log the locations of the sandboxes to the console
pants dependents
doesn’t run any subprocesses, so there are no sandboxes to speak of
And yes, if the order of imports is affecting the result then that does smell buggy
I assume
fooserv/
is your package root? so that
web
is a top-level package?
Would you be able to create a small toy repo that reproduces the issue? It will be hard to debug without a consistent repro. I fear that since rearranging the imports affects the behavior, this is going to be difficult to reproduces independently…
Alternatively we can walk you through how to run Pants from source to debug this
f
@fast-nail-55400 pointed me at that new debug option in the other thread; going to try that now.
@happy-kitchen-89482 Thanks for the info. Turns out it was PEBKAC (I botched a manual edit to the import statements in this one module after a rebase conflict, whoops).