diff --git a/tests/test_exception_handling.py b/tests/test_exception_handling.py index 83e6c7f4..013a9624 100644 --- a/tests/test_exception_handling.py +++ b/tests/test_exception_handling.py @@ -94,66 +94,66 @@ class ExceptionTestCase(TestCase): INITIALIZE_TB =\ -[{'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py', +[{'filename': '/zipline/core/component.py', 'line': 'self._run()', 'lineno': 204, 'method': 'run'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py', + {'filename': '/zipline/core/component.py', 'line': 'self.loop()', 'lineno': 195, 'method': '_run'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py', + {'filename': '/zipline/core/component.py', 'line': 'self.do_work()', 'lineno': 235, 'method': 'loop'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py', + {'filename': '/zipline/components/tradesimulation.py', 'line': 'self.initialize_algo()', 'lineno': 97, 'method': 'do_work'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py', + {'filename': '/zipline/components/tradesimulation.py', 'line': 'self.do_op(self.algorithm.initialize)', 'lineno': 80, 'method': 'initialize_algo'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py', + {'filename': '/zipline/components/tradesimulation.py', 'line': 'callable_op(*args, **kwargs)', 'lineno': 206, 'method': 'do_op'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/test_algorithms.py', + {'filename': '/zipline/test_algorithms.py', 'line': 'raise Exception("Algo exception in initialize")', 'lineno': 166, 'method': 'initialize'}] HANDLE_DATA_TB =\ -[{'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py', +[{'filename': '/zipline/core/component.py', 'line': 'self._run()', 'lineno': 204, 'method': 'run'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py', + {'filename': '/zipline/core/component.py', 'line': 'self.loop()', 'lineno': 195, 'method': '_run'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/core/component.py', + {'filename': '/zipline/core/component.py', 'line': 'self.do_work()', 'lineno': 235, 'method': 'loop'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py', + {'filename': '/zipline/components/tradesimulation.py', 'line': 'self.process_event(event)', 'lineno': 116, 'method': 'do_work'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py', + {'filename': '/zipline/components/tradesimulation.py', 'line': 'self.run_algorithm()', 'lineno': 164, 'method': 'process_event'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py', + {'filename': '/zipline/components/tradesimulation.py', 'line': 'self.do_op(self.algorithm.handle_data, data)', 'lineno': 186, 'method': 'run_algorithm'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/components/tradesimulation.py', + {'filename': '/zipline/components/tradesimulation.py', 'line': 'callable_op(*args, **kwargs)', 'lineno': 206, 'method': 'do_op'}, - {'filename': '/Users/fawce/projects/qexec/zipline_repo/zipline/test_algorithms.py', + {'filename': '/zipline/test_algorithms.py', 'line': 'raise Exception("Algo exception in handle_data")', 'lineno': 187, 'method': 'handle_data'}] diff --git a/zipline/protocol.py b/zipline/protocol.py index f8e4a5f2..cfe6f611 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -119,6 +119,8 @@ import numbers import datetime import pytz import traceback +import re +import os from collections import namedtuple @@ -524,8 +526,9 @@ def EXCEPTION_FRAME(exception_tb): stack_list = traceback.extract_tb(exception_tb) rlist = [] for stack in stack_list: + filename = shorten_filename(stack[0]) rstack = { - 'filename' : stack[0], + 'filename' : filename, 'lineno' : stack[1], 'method' : stack[2], 'line' : stack[3] @@ -538,6 +541,23 @@ def EXCEPTION_FRAME(exception_tb): return BT_UPDATE_FRAME('EXCEPTION', result) +def shorten_filename(filename): + if filename == None: + return None + + # check if the path contains zipeline_repo + path_re = r'(?<=zipline_repo).*' + match = re.search(path_re, filename) + + if match: + return match.group(0) + parts = filename.split('zipline_repo') + return parts[1] + else: + # return just the filename. + head, tail = os.path.split(filename) + return tail + def CANCEL_FRAME(date): result = { 'date' : EPOCH(date)