setup.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:wikidata 作者: dahlia 项目源码 文件源码
def get_version():
    module_path = os.path.join(os.path.dirname(__file__),
                               'wikidata', '__init__.py')
    module_file = open(module_path)
    try:
        module_code = module_file.read()
    finally:
        module_file.close()
    tree = ast.parse(module_code, module_path)
    for node in ast.iter_child_nodes(tree):
        if not isinstance(node, ast.Assign) or len(node.targets) != 1:
            continue
        target, = node.targets
        if isinstance(target, ast.Name) and target.id == '__version__':
            value = node.value
            if isinstance(value, ast.Str):
                return value.s
            raise ValueError('__version__ is not defined as a string literal')
    raise ValueError('could not find __version__')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号