def parse_version(package):
from os.path import dirname, join, exists<EOL>import ast<EOL>_candiates = [<EOL>join(dirname(__file__), package + '<STR_LIT>'),<EOL>join(dirname(__file__), package, '<STR_LIT>'),<EOL>]<EOL>_found = [init_fpath for init_fpath in _candiates if exists(init_fpath)]<EOL>if len(_found) > <NUM_LIT:0>:<EOL><INDENT>init_fpath = _found[<NUM_LIT:0>]<EOL><DEDENT>elif len(_found) > <NUM_LIT:1>:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>elif len(_found) == <NUM_LIT:0>:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>with open(init_fpath, '<STR_LIT:r>') as file_:<EOL><INDENT>sourcecode = file_.read()<EOL><DEDENT>pt = ast.parse(sourcecode)<EOL>class VersionVisitor(ast.NodeVisitor):<EOL><INDENT>def visit_Assign(self, node):<EOL><INDENT>for target in node.targets:<EOL><INDENT>if getattr(target, '<STR_LIT:id>', None) == '<STR_LIT>':<EOL><INDENT>self.version = node.value.s<EOL><DEDENT><DEDENT><DEDENT><DEDENT>visitor = VersionVisitor()<EOL>visitor.visit(pt)<EOL>return visitor.version<EOL>
Statically parse the version number from __init__.py

CommandLine:
    python -c "import setup; print(setup.parse_version('ubelt'))"