Is it possible to get lines from Python tracebacks in eggs? -


in python packaging: hate, hate, hate everywhere, armin says:

[...] python tracebacks no longer included source lines traceback. there no technical limitation why should not able show correct line numbers there. bug in python interpreter.

i'm seeing issue eggs in virtualenv:

traceback (most recent call last):   file "/users/example/venv/current/bin/my_script", line 37, in <module>     sys.exit(demo.scripts.foo.main())   file "build/bdist.linux-x86_64/egg/example/demo/scripts/my_script.py", line 90, in main   file "build/bdist.linux-x86_64/egg/example/demo/lib/bar.py", line 18, in func_x   file "build/bdist.linux-x86_64/egg/example/demo/lib/bar.py", line 55, in func_y attributeerror: 'tuple' object has no attribute 'sort' 

since known bug, there workarounds? there issue in python bug tracker (i can't find one)?

this proof of concept

 import os  import sys  import traceback  import linecache    def recurse(depth=10):      if depth:          recurse(depth-1)      os.path.join(none, none)    def locate_filename(filename):       def generate_segments():          parts = filename.split(os.sep)          in xrange(len(parts) - 1, 0, -1):              yield os.sep.join(os.path.join(parts[i:]))       segment in generate_segments():          path in sys.path:              candidate = os.path.join(path, segment)              if os.path.exists(candidate):                  return candidate    try:      recurse()  except:      _, _, tb = sys.exc_info()      filename, lineno, functionname, _ in traceback.extract_tb(tb):          print filename, lineno, functionname          relocated_filename = locate_filename(filename)          if relocated_filename:              print linecache.getline(relocated_filename, lineno) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -