Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

2to3 fixes #186

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/gephi/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def main():

with PyCallGraph(output=gephi):
person = Person()
for a in xrange(10):
for a in range(10):
person.add_banana(Banana())
person.eat_bananas()

Expand Down
7 changes: 6 additions & 1 deletion examples/gephi/large.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ def main():
gephi.output_file = 'large.gdf'

with PyCallGraph(output=gephi):
from urllib2 import urlopen

try:
from urllib2 import urlopen
except ImportError: # Python 3.x
from urllib.request import urlopen

from xml.dom.minidom import parseString
parseString(urlopen('http://w3.org/').read())

Expand Down
7 changes: 6 additions & 1 deletion examples/graphviz/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
'''
Execute all pycallgraph examples in this directory.
'''
import sys
from glob import glob


examples = glob('*.py')
examples.remove('all.py')
for example in examples:
print(example)
execfile(example)

if sys.version_info[0] < 3:
execfile(example)
else:
exec(open(example).read())
2 changes: 1 addition & 1 deletion examples/graphviz/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def main():

with PyCallGraph(output=graphviz):
person = Person()
for a in xrange(10):
for a in range(10):
person.add_banana(Banana())
person.eat_bananas()

Expand Down
5 changes: 4 additions & 1 deletion examples/graphviz/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def main():
)

pycallgraph.start()
import HTMLParser # noqa
try:
import HTMLParser
except ImportError: # Python 3.x
import html.parser # noqa
pycallgraph.stop()

# Set the edge colour to black for all examples
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from submodule_one import SubmoduleOne
from submodule_two import SubmoduleTwo
from .submodule_one import SubmoduleOne
from .submodule_two import SubmoduleTwo


def main():
Expand Down
2 changes: 1 addition & 1 deletion examples/graphviz/example_with_submodules/submodule_two.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from helpers import helper
from .helpers import helper


class SubmoduleTwo(object):
Expand Down
5 changes: 3 additions & 2 deletions examples/graphviz/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
def main():
import_list = (
'pickle',
'htmllib',
'urllib2',
'glob',
'datetime',
)
graphviz = GraphvizOutput()
config = Config(include_stdlib=True)
Expand All @@ -23,5 +23,6 @@ def main():
__import__(module)



if __name__ == '__main__':
main()
7 changes: 6 additions & 1 deletion examples/graphviz/large.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ def main():
config = Config(include_stdlib=True)

with PyCallGraph(output=graphviz, config=config):
from urllib2 import urlopen

try:
from urllib2 import urlopen
except ImportError: # Python 3.x
from urllib.request import urlopen

from xml.dom.minidom import parseString
parseString(urlopen('http://w3.org/').read())

Expand Down
2 changes: 1 addition & 1 deletion examples/graphviz/recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def main():
graphviz.output_file = 'recursive.png'

with PyCallGraph(output=graphviz):
for a in xrange(1, 10):
for a in range(1, 10):
factorial(a)

if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion pycallgraph/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import sys
import six

from .output import outputters
from .globbing_filter import GlobbingFilter
Expand Down Expand Up @@ -38,7 +39,7 @@ def __init__(self, **kwargs):
self.did_init = True

# Update the defaults with anything from kwargs
[setattr(self, k, v) for k, v in kwargs.iteritems()]
[setattr(self, k, v) for k, v in six.iteritems(kwargs)]

self.create_parser()

Expand Down
6 changes: 4 additions & 2 deletions pycallgraph/output/graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import textwrap
import subprocess as sub

import six

from ..metadata import __version__
from ..exceptions import PyCallGraphException
from ..color import Color
Expand Down Expand Up @@ -151,7 +153,7 @@ def generate(self):

def attrs_from_dict(self, d):
output = []
for attr, val in d.iteritems():
for attr, val in six.iteritems(d):
output.append('%s = "%s"' % (attr, val))
return ', '.join(output)

Expand All @@ -167,7 +169,7 @@ def edge(self, edge, attr):

def generate_attributes(self):
output = []
for section, attrs in self.graph_attributes.iteritems():
for section, attrs in six.iteritems(self.graph_attributes):
output.append('{0} [ {1} ];'.format(
section, self.attrs_from_dict(attrs),
))
Expand Down
6 changes: 4 additions & 2 deletions pycallgraph/output/output.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re
import os
import six

from distutils.spawn import find_executable

from ..exceptions import PyCallGraphException
Expand All @@ -16,14 +18,14 @@ def __init__(self, **kwargs):
self.edge_label_func = self.edge_label

# Update the defaults with anything from kwargs
[setattr(self, k, v) for k, v in kwargs.iteritems()]
[setattr(self, k, v) for k, v in six.iteritems(kwargs)]

def set_config(self, config):
'''
This is a quick hack to move the config variables set in Config into
the output module config variables.
'''
for k, v in config.__dict__.iteritems():
for k, v in six.iteritems(config.__dict__):
if hasattr(self, k) and \
callable(getattr(self, k)):
continue
Expand Down
12 changes: 8 additions & 4 deletions pycallgraph/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from distutils import sysconfig
from collections import defaultdict
from threading import Thread

import six

try:
from Queue import Queue, Empty
except ImportError:
Expand Down Expand Up @@ -294,7 +297,7 @@ def groups(self):
grp = defaultdict(list)
for node in self.nodes():
grp[node.group].append(node)
for g in grp.iteritems():
for g in six.iteritems(grp):
yield g

def stat_group_from_func(self, func, calls):
Expand All @@ -312,14 +315,14 @@ def stat_group_from_func(self, func, calls):
return stat_group

def nodes(self):
for func, calls in self.func_count.iteritems():
for func, calls in six.iteritems(self.func_count):
yield self.stat_group_from_func(func, calls)

def edges(self):
for src_func, dests in self.call_dict.iteritems():
for src_func, dests in six.iteritems(self.call_dict):
if not src_func:
continue
for dst_func, calls in dests.iteritems():
for dst_func, calls in six.iteritems(dests):
edge = self.stat_group_from_func(dst_func, calls)
edge.src_func = src_func
edge.dst_func = dst_func
Expand Down Expand Up @@ -372,4 +375,5 @@ def wrapper(*rest):

return wrapper


inspect.getmodule = simple_memoize(inspect.getmodule)
1 change: 1 addition & 0 deletions requirements/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pytest-pep8
pytest-cov
python-coveralls
flake8
six