Closed eliasdorneles closed 4 years ago
If you try to run a module that doesn't exist, you get an error like
Traceback (most recent call last):
File "/Users/aaronmeurer/Documents/pudb/pudb/__init__.py", line 167, in runscript
dbg._runmodule(mainpyfile)
File "/Users/aaronmeurer/Documents/pudb/pudb/debugger.py", line 491, in _runmodule
mod_name, mod_spec, code = runpy._get_module_details(module_name)
File "/Users/aaronmeurer/anaconda3/lib/python3.7/runpy.py", line 136, in _get_module_details
raise error("No module named %s" % mod_name)
ImportError: No module named fdjkslf
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/aaronmeurer/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Users/aaronmeurer/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/aaronmeurer/Documents/pudb/pudb/__main__.py", line 31, in <module>
main()
File "/Users/aaronmeurer/Documents/pudb/pudb/run.py", line 25, in main
steal_output=options.steal_output)
File "/Users/aaronmeurer/Documents/pudb/pudb/__init__.py", line 125, in runmodule
runscript(*args, **kwargs)
File "/Users/aaronmeurer/Documents/pudb/pudb/__init__.py", line 176, in runscript
dbg.interaction(None, sys.exc_info())
File "/Users/aaronmeurer/Documents/pudb/pudb/debugger.py", line 389, in interaction
self.stack, index = self.get_shortened_stack(frame, tb)
File "/Users/aaronmeurer/Documents/pudb/pudb/debugger.py", line 350, in get_shortened_stack
stack, index = self.get_stack(frame, tb)
File "/Users/aaronmeurer/anaconda3/lib/python3.7/bdb.py", line 520, in get_stack
if f is self.botframe:
AttributeError: 'Debugger' object has no attribute 'botframe'
Only the top-level ImportError message should be shown. I think somewhere it needs to catch the ImportError and give up.
It's a little disappointing to see that pudb is still using optparse instead of argparse, but I guess that can be fixed in a separate issue.
I noticed that it allows more than one script argument, even though only the first one is processed. This is an issue also in master, so maybe it doesn't need to be fixed here, but when we do we should not allow any script arguments if -m
is used (unless we instead want to support debugging one script after the other).
Actually, scrap that. It is passing the "second" script as the argv, like it should.
For the ImportError, we may want to just print the error message instead showing the full traceback, like how python -m
does.
For the ImportError, we may want to just print the error message instead showing the full traceback, like how
python -m
does.
Makes sense, will do!
Makes sense, will do!
Be sure to test both cases: a module that doesn't exist, and a package that does exist but doesn't have __main__.py
.
Be sure to test both cases: a module that doesn't exist, and a package that does exist but doesn't have
__main__.py
.
Just did, in both cases it works the same as python -m
.
I've tested the new code. It seems to work. I noticed that if you pass it -m but give it a file instead of a module, it just executes the file without running the debugger. I'm not sure if this is intentional, although it does seem to match python -m
and pdb -m
behavior.
I've tested the new code. It seems to work. I noticed that if you pass it -m but give it a file instead of a module, it just executes the file without running the debugger. I'm not sure if this is intentional, although it does seem to match
python -m
andpdb -m
behavior.
Oh, I hadn't tested that case. Well, it seems okay to leave it like that?
Cool. Thanks @asmeurer for taking another look. In it goes.
And thanks @eliasdorneles for your contribution!
Awesome, thank you both!
Thanks for taking the time to work through the issues here. And I'm also happy to see the command line code now use argparse instead of optparse.
do we have the latest release version with this PR merged?
Thanks for the reminder. 2020.1, out now.
Hello,
Here is an implementation for the
-m module
switch (see https://github.com/inducer/pudb/issues/389).Does this look good?