pyobjc / source-deps /

from compiler import parseFile
from compiler.ast import Module, Stmt, Assign, AssName, Const

__version__ = '1.0'

def findVersion(fn):
    ast = parseFile(fn)
    if not isinstance(ast, Module):
        raise ValueError, "expecting Module"
    statements = ast.getChildNodes()
    if not (len(statements) == 1 and isinstance(statements[0], Stmt)):
        raise ValueError, "expecting one Stmt"
    for node in statements[0].getChildNodes():
        if not isinstance(node, Assign):
        if not len(node.nodes) == 1:
        assName = node.nodes[0]
        if not (
                isinstance(assName, AssName) and
                isinstance(node.expr, Const) and
                assName.flags == 'OP_ASSIGN' and 
       == '__version__'
        return node.expr.value
        raise ValueError, "Version not found"
if __name__ == '__main__':
    import sys
    for arg in (sys.argv[1:] or [__file__]):
        print arg, findVersion(arg)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.