Automatic version number both in setup.py (setuptools) AND source code?

前端 未结 7 1305
没有蜡笔的小新
没有蜡笔的小新 2020-12-24 11:21

SITUATION:

I have a python library, which is controlled by git, and bundled with distutils/setuptools. And I want to automatically generate version

7条回答
  •  时光说笑
    2020-12-24 11:38

    Eric's idea was the simple way to go, just in case this is useful here is the code I used (Flask's team did it this way):

    import re
    import ast
    
    _version_re = re.compile(r'__version__\s+=\s+(.*)')
    
    with open('app_name/__init__.py', 'rb') as f:
        version = str(ast.literal_eval(_version_re.search(
            f.read().decode('utf-8')).group(1)))
    
    setup(
        name='app-name',
        version=version,
     .....
    )
    

提交回复
热议问题