pudb icon indicating copy to clipboard operation
pudb copied to clipboard

Is it possible to open arbitrary python file not only suggested modules?

Open kiddten opened this issue 9 years ago • 13 comments

Open file explicitly by fullpath

kiddten avatar Aug 30 '16 14:08 kiddten

Something like option of originally pdb: b pathtests/test.py:777

kiddten avatar Aug 30 '16 15:08 kiddten

I don't think it's currently supported (maybe if you manually edit sys.path before opening the modules view). It should be easy to add, though, as it would just need a GUI. I'm not sure what the best GUI would be. Maybe a button in the module loader to load from a path.

asmeurer avatar Aug 30 '16 17:08 asmeurer

I'd be happy to take a patch that allows this that has a reasonable UI.

inducer avatar Aug 30 '16 19:08 inducer

Do modules actually have to be imported to be loaded, or is that just a side-effect of the way the current UI works?

asmeurer avatar Aug 30 '16 20:08 asmeurer

I don't think that's required, or, if it is, it should be possible to make it not so.

inducer avatar Aug 30 '16 20:08 inducer

My current use case: I am running django unittests with python -m pudb.run manage.py my_test.py So it is ok and you could walk through files line by line. With pbd we have great option as I describe above with explicit setting of breakpoint by full file path and line number. It could be any file. Unfortunately I can't find tests modules in list provided by m option with pudb. Any thoughts?

kiddten avatar Aug 30 '16 20:08 kiddten

I don't suppose urwid has a file browser widget. Otherwise it will just be a simple text entry box to type in the path.

asmeurer avatar Aug 30 '16 23:08 asmeurer

https://github.com/urwid/urwid/blob/master/examples/browse.py

inducer avatar Aug 31 '16 02:08 inducer

That's not part of the urwid library. I don't see it as worth pulling in just for this.

asmeurer avatar Sep 01 '16 17:09 asmeurer

Hey! So I too have this issue. If I do something like debugging a pytest test run I need to wade through a ton of pytest code before my own code is loaded and is finally able to be opened by m.

Here's my proposed solution (I don't know the code internals, though):

  • when you open the "Go to Line Number" (by pressing L) you already have a UI with the full file name
  • just make the file path editable by pressing the up arrow
  • show error dialog saying the file doesn't exist if it doesn't exist.

butla avatar Jun 19 '17 16:06 butla

I'm not 100% sure if this is true, but from a glance at the source the file has to be importable. So adding the box as you suggest should be easy, but then you just need to make sure that the file that's given can be imported somehow.

asmeurer avatar Jun 19 '17 23:06 asmeurer

What do you mean by making sure it can be imported? Because it doesn't sound trivial :-)

The idea off the top of my head is to temporarily add the file's directory to sys.path, but this won't be enough for many imports.

Also, I can tell you that found a way around this problem. I just let the program run, at the end I choose "examine" and then I have all the modules loaded, so I can find them with "m".

butla avatar Jun 20 '17 08:06 butla

I wanted this feature today to debug a complex import-time interaction. m is a bit of a problem because it both shows you the source and imports the module; I want to be able to set a breakpoint without importing.

glyph avatar Apr 03 '19 20:04 glyph