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

ambitious-student-81104

07/27/2022, 4:26 PM
has anyone had success adding
pdb
with
./pants check
? there are some mypy errors that i’d like to drop into pdb to see. Things I’ve tried that didn’t work: 1. adding
pdb = True
in
mypy.ini
2. adding this in
pants.toml
Copy code
[mypy]
args = ["--pdb"]
b

bitter-ability-32190

07/27/2022, 4:28 PM
I think I'd probably use
./pants --no-process-cleanup check --only=mypy ...
, then look for the logged sandbox dir and crack it open. There will be a
./__run.sh
you can run to launch the process. That way you get rid of Pants-in-the-middle and can poke at the process itself
a

ambitious-student-81104

07/27/2022, 4:31 PM
wow sounds rad, thanks I’ll try
b

bitter-ability-32190

07/27/2022, 4:32 PM
--no-process-cleanup
is my favorite little feature. Allows for much debugging and hacking 🙂
👌 1
a

ambitious-student-81104

07/27/2022, 4:32 PM
hmm, i didn’t see the logged sandbox dir though
b

bitter-ability-32190

07/27/2022, 4:33 PM
Likely because pants cached the work. Add a newline or a comment to a file and try again 😉
a

ambitious-student-81104

07/27/2022, 4:34 PM
added a line but still doesn’t show the sandbox dir 🤔 @hundreds-father-404 any thoughts?
b

bitter-ability-32190

07/27/2022, 4:34 PM
Added a line and hit "save"? And your editor didn't strip it?
whats your command? are you seeing other INFO logs?
a

ambitious-student-81104

07/27/2022, 4:36 PM
yeah it’s saved
Copy code
❯ ./pants --no-process-cleanup check --only=mypy foo/test.py
12:36:29.56 [ERROR] Completed: Typecheck using MyPy - mypy failed (exit code 1).
cbds/test.py:3:7: error: Module has no attribute "bar"  [attr-defined]
    print(foo.bar)
          ^
Found 1 error in 1 file (checked 1 source file)



✕ mypy failed.
b

bitter-ability-32190

07/27/2022, 4:37 PM
Try adding a comment, just in case 😉
a

ambitious-student-81104

07/27/2022, 4:47 PM
yeah i tried that before adding a line of code but it still doesn’t give a sandbox dir 😞
b

bitter-ability-32190

07/27/2022, 5:01 PM
Thats very strange 😮 Are you filtering the log lines? Try also adding
-linfo
like
./pants -linfo --no-process-cleanup
...
f

freezing-lamp-12123

07/27/2022, 5:05 PM
the
__run.sh
is the real nugget, compared to bazel (last i tried at least) where you had to go through asome steps to get a very complicated shell script to copy/paste and run as a oneliner — always questioned whether or not everything was right
b

bitter-ability-32190

07/27/2022, 5:06 PM
(Plus the path to the executable thing in bazel was horrific)
/home/{name}/.cache/bazel/_bazel_{name}/6b497f0d8f4c2590b427029c1f772dc1/execroot/__main__/bazel-out/k8-fastbuild/bin/p1/p2/p3/p4/p5/targetname.runfiles/__main__/p1/p2/p3/p4/p5/filename.py
f

freezing-lamp-12123

07/27/2022, 5:15 PM
blissfully forgot that part
😂 1
h

happy-kitchen-89482

07/27/2022, 8:58 PM
after debugging this via the sandbox dir, I couldn't get
--pdb
to work even after eliminating Pants and Pex...
literally it did not do anything on a plain
mypy
command line
So now i'm confused...
b

bitter-ability-32190

07/27/2022, 10:56 PM
I think it only works for exceptional cases?
h

happy-kitchen-89482

07/27/2022, 10:58 PM
Yes, I've introduced purposeful errors
b

bitter-ability-32190

07/27/2022, 11:01 PM
Like a mypy crash
I know a few examples where you can crash mypy, but I'm on mobile. Check back in T-2 hours 🙈
Try: t = (1, 2, 3, 4) a, b, c = t
h

happy-kitchen-89482

07/27/2022, 11:05 PM
Oh I see
not for just typechecking errors
@ambitious-student-81104 are you trying to debug mypy crashes or typechecking errors ?
a

ambitious-student-81104

07/27/2022, 11:18 PM
Mypy! The one resolves with correcting the source root. But I'd like to be able to pdb mypy too
h

happy-kitchen-89482

07/28/2022, 12:25 AM
Are you able to make
--pdb
do what you want outside of Pants? So far I have not
Deliberately breaking code and running
mypy --pdb
on it doesn't have any effect that I can see
b

bitter-ability-32190

07/28/2022, 12:38 AM
Copy code
t = [1, 2, 3, 4]
a, b, c = *t
...
Copy code
joshuacannon@CEPHANDRIUS:~/work/place$ mypy --strict --pdb foo.py
foo.py:2: error: Can use starred expression only as assignment target
foo.py:2: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
<https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build>
If this issue continues with mypy master, please report a bug at <https://github.com/python/mypy/issues>
version: 0.980+dev.b0e59b29be239ce35cffcef20639709259ee48df
Dropping into pdb
> /home/joshuacannon/.local/pipx/venvs/mypy/lib/python3.8/site-packages/mypy/types.py(2316)accept()
-> assert isinstance(visitor, SyntheticTypeVisitor)
(Pdb)
Copy code
$ echo -e "t = [1, 2, 3, 4]\na, b, c = *t" > src/python/pants/version2.py
$ ./pants --mypy-args="--pdb" check --only=mypy src/python/pants/version2.py
...
> /tmp/pants-sandbox-1waKR0/mypy/types.py(2289)accept()
(Pdb)
Traceback (most recent call last):
  File "mypy/checker.py", line 431, in accept
  File "mypy/nodes.py", line 1165, in accept
  File "mypy/checker.py", line 2220, in visit_assignment_stmt
  File "mypy/checker.py", line 2279, in check_assignment
  File "mypy/checker.py", line 2871, in check_assignment_to_multiple_lvalues
  File "mypy/checker.py", line 2919, in check_multi_assignment
  File "mypy/checker.py", line 3104, in check_multi_assignment_from_iterable
  File "mypy/checker.py", line 3097, in type_is_iterable
  File "mypy/subtypes.py", line 97, in is_subtype
  File "mypy/subtypes.py", line 158, in _is_subtype
  File "mypy/types.py", line 2289, in accept
AssertionError:

src/python/pants/version2.py:2: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
<https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build>
Please report a bug at <https://github.com/python/mypy/issues>
version: 0.961
Dropping into pdb
src/python/pants/version2.py:2: : note: use --pdb to drop into pdb
So it'll drop into Pdb, but also exits for whatever reason (using both pantsd and
--no-pantsd
h

happy-kitchen-89482

07/28/2022, 6:12 PM
Huh, OK that works for me now
🤷‍♂️
Running
./__mypy_runner.sh
in the sandbox also works
(drops me into pdb)
Yeah, I think this would be tough to get working, we'd have to run mypy as in InteractiveProcess I think?
a la pytest debugging
maybe not "tough", but not nothing
Some refactoring might be needed to deal with the partitioning
b

bitter-ability-32190

07/28/2022, 6:27 PM
Yeah, I'm not sure how much we should try to get this working. It is a bit of a fringe case, and
-no-process-cleanup
gets us closeish. The issue being
mypy
isn't unique and could be run in parallel.
Unless you mean we should try and detect the
--pdb
flag? 🤔
2 Views