Created
May 31, 2012 18:51
-
-
Save dholth/2845385 to your computer and use it in GitHub Desktop.
Find entry points the hard and wrong way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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