Skip to content

Commit c7442af

Browse files
committed
Make mprun python-2 compatible
1 parent 423729c commit c7442af

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
PYTHON ?= python
2+
IPYTHON ?= ipython
23

34
.PHONY: test
45

@@ -12,3 +13,4 @@ test:
1213
$(PYTHON) test/test_import.py
1314
$(PYTHON) test/test_memory_usage.py
1415
$(PYTHON) test/test_precision_import.py
16+
$(IPYTHON) test/test_ipython.py

memory_profiler.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -599,25 +599,26 @@ def show_results(prof, stream=None, precision=1):
599599
header = template.format('Line #', 'Mem usage', 'Increment',
600600
'Line Contents')
601601

602-
stream.write('Filename: ' + filename + '\n\n')
603-
stream.write(header + '\n')
604-
stream.write('=' * len(header) + '\n')
602+
stream.write(u'Filename: ' + filename + '\n\n')
603+
stream.write(header + u'\n')
604+
stream.write(u'=' * len(header) + '\n')
605605

606606
all_lines = linecache.getlines(filename)
607607
mem_old = None
608-
float_format = '{0}.{1}f'.format(precision + 4, precision)
609-
template_mem = '{0:' + float_format + '} MiB'
608+
float_format = u'{0}.{1}f'.format(precision + 4, precision)
609+
template_mem = u'{0:' + float_format + '} MiB'
610610
for (lineno, mem) in lines:
611611
if mem:
612612
inc = (mem - mem_old) if mem_old else 0
613613
mem_old = mem
614614
mem = template_mem.format(mem)
615615
inc = template_mem.format(inc)
616616
else:
617-
mem = ''
618-
inc = ''
619-
stream.write(template.format(lineno, mem, inc, all_lines[lineno - 1]))
620-
stream.write('\n\n')
617+
mem = u''
618+
inc = u''
619+
tmp = template.format(lineno, mem, inc, all_lines[lineno - 1])
620+
stream.write(unicode(tmp))
621+
stream.write(u'\n\n')
621622

622623

623624
def _func_exec(stmt, ns):

0 commit comments

Comments
 (0)