setup.py
def parse_version():
    """ Statically parse the version number from __init__.py """
    from os.path import dirname, join
    import ast
    modname = setupkw['name']
    init_fpath = join(dirname(__file__), modname, '__init__.py')
    with open(init_fpath) as file_:
        sourcecode = file_.read()
    pt = ast.parse(sourcecode)
    class VersionVisitor(ast.NodeVisitor):
        def visit_Assign(self, node):
            for target in node.targets:
                if target.id == '__version__':
                    self.version = node.value.s
    visitor = VersionVisitor()
    visitor.visit(pt)
    return visitor.version
def parse_version():
    """ Statically parse the version number from __init__.py """
    from os.path import dirname, join
    import ast
    modname = setupkw['name']
    init_fpath = join(dirname(__file__), modname, '__init__.py')
    with open(init_fpath) as file_:
        sourcecode = file_.read()
    pt = ast.parse(sourcecode)
    class VersionVisitor(ast.NodeVisitor):
        def visit_Assign(self, node):
            for target in node.targets:
                if target.id == '__version__':
                    self.version = node.value.s
    visitor = VersionVisitor()
    visitor.visit(pt)
    return visitor.version
Statically parse the version number from __init__.py