[issue28610] Provide PDB hook to customize how to find source files

2016-11-08 Thread Xavier de Gaye

Xavier de Gaye added the comment:

This is a simple code object compiled from a source (the string), a module is 
quite different and more complex. The patch uses a fake module Loader to use 
linecache, there is no gain in going any further and pulling from the importlib 
machinery, I think.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28610] Provide PDB hook to customize how to find source files

2016-11-08 Thread Pinku Surana

Pinku Surana added the comment:

Thanks. This is clever. I've tried it out and it works. Would it be more 
appropriate to use "importlib" and "importlib.abc" to implement a custom loader 
for a string script? It looks like importlib.abc.InspectLoader does the right 
thing.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28610] Provide PDB hook to customize how to find source files

2016-11-05 Thread Xavier de Gaye

Xavier de Gaye added the comment:

This patch is an attempt at allowing the source debugging of scripts executed 
by the Python exec() function. It misses tests and documentation.

You may use it using the idiom given in the following example to avoid stepping 
into the pdb code on the first invocation of pdb.exec_script() (see the 
exec_script() doc string):

import sys

def main():
foo = 123
s = """if 1:
x = foo
x = 555
"""
exec_script(s)

if __name__ == '__main__':
if '--debug' in sys.argv[1:]:
import pdb
exec_script = pdb.exec_script
pdb.Pdb(skip=['pdb']).set_trace()
else:
exec_script = exec

main()

--
components:  -Demos and Tools
keywords: +patch
stage:  -> needs patch
versions: +Python 3.7 -Python 3.5
Added file: http://bugs.python.org/file45366/debug_script.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28610] Provide PDB hook to customize how to find source files

2016-11-04 Thread Xavier de Gaye

Xavier de Gaye added the comment:

The lazycache() function of the linecache module meets your request, I think. 
See the following debugging session using the attached script:

$ python -m pdb debug_script.py
> /path/to/cwd/debug_script.py(1)()
-> def debug_script(script):
(Pdb) n
> /path/to/cwd/debug_script.py(19)()
-> """
(Pdb) n
> /path/to/cwd/debug_script.py(20)()
-> code, globs = debug_script(s)
(Pdb) n
> /path/to/cwd/debug_script.py(21)()
-> exec(code, globs)
(Pdb) s
--Call--
> /path/to/cwd/script_name(2)()
-> x = 1
(Pdb) s
> /path/to/cwd/script_name(2)()
-> x = 1
(Pdb) s
> /path/to/cwd/script_name(3)()
-> y = 'blabla'
(Pdb) s
--Return--
> /path/to/cwd/script_name(3)()->None
-> y = 'blabla'
(Pdb) s
--Return--
> /path/to/cwd/debug_script.py(21)()->None
-> exec(code, globs)
(Pdb)

--
nosy: +xdegaye
Added file: http://bugs.python.org/file45358/debug_script.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28610] Provide PDB hook to customize how to find source files

2016-11-04 Thread Pinku Surana

New submission from Pinku Surana:

I am using Python as a hosted scripting runtime for a product. All the user 
scripts are stored in a database. I use "compile" and "exec" to run the 
scripts. I'd like to use PDB to debug scripts. Unfortunately, PDB makes a call 
to linecache, which calls tokenize.open assuming the code is in a file. I'd 
like to pass in a function that takes a filename and returns the source code in 
a string. 

At the very least, moving the call to "linecache.getline" into a separate 
method in PDB ("self.get_lines") would allow me to override that method with my 
own.

--
components: Demos and Tools, Library (Lib)
messages: 280056
nosy: Pinku Surana
priority: normal
severity: normal
status: open
title: Provide PDB hook to customize how to find source files
type: enhancement
versions: Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com