Skip to content

Instantly share code, notes, and snippets.

@dholth
Created May 31, 2012 18:51
Show Gist options
  • Save dholth/2845385 to your computer and use it in GitHub Desktop.
Save dholth/2845385 to your computer and use it in GitHub Desktop.
Find entry points the hard and wrong way
def getname(t):
if isinstance(t, ast.Attribute):
return getname(t.value)
elif isinstance(t, ast.Name):
return t.id
else:
return t
class EntryPointsVisitor(ast.NodeVisitor):
def visit_Assign(self, node):
try:
names = [getname(t) for t in node.targets]
entry_points = 'entry_points' in names
if not entry_points:
self.generic_visit(node)
else:
print ast.dump(node)
except AttributeError, e:
import pdb; pdb.set_trace()
def visit_Call(self, node):
global non_text_ep
if not (isinstance(node.func, ast.Name) and node.func.id == 'setup'):
self.generic_visit(node)
else:
for keyword in node.keywords:
if keyword.arg == 'entry_points':
if isinstance(keyword.value, ast.Str):
entry_points_text.append(keyword.value.s)
else:
non_text_ep += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment