我正在寻找的是:
python setup.py show-version
这样我就可以为版本创建一个git标签,作为构建和发布结构作业的一部分。
由于这不存在,我最终得到了:
import setuptools
original = sys.modules['setuptools']
class Fake(object):
def __call__(self, *args, **kw):
self.args, self.kw = args, kw
fake_setuptools = ModuleType('fake_setuptools')
for name in dir(setuptools):
setattr(fake_setuptools, name, Fake())
sys.modules['setuptools'] = fake_setuptools
with open('setup.py') as source:
exec(source.read())
print(fake_setuptools.setup.kw['version'])
坦率地说,这太可怕了!
我该怎么做?
答案 0 :(得分:3)
Setuptools为安装脚本调用提供了--version标志。
$ python setup.py --version
答案 1 :(得分:0)
或者,如果您需要包中的其他元数据,jaraco.packaging提供show
命令,可用于显示包中的任意数量的属性。
答案 2 :(得分:-1)
可以从setup.py获取大量信息,包括我正在寻找的内容:
$ python setup.py --help
...
Information display options (just display information, ignore any commands)
--help-commands list all available commands
--name print package name
--version (-V) print package version
--fullname print <package name>-<version>
--author print the author's name
--author-email print the author's email address
--maintainer print the maintainer's name
--maintainer-email print the maintainer's email address
--contact print the maintainer's name if known, else the author's
--contact-email print the maintainer's email address if known, else the
author's
--url print the URL for this package
--license print the license of the package
--licence alias for --license
--description print the package description
--long-description print the long package description
--platforms print the list of platforms
--classifiers print the list of classifiers
--keywords print the list of keywords
--provides print the list of packages/modules provided
--requires print the list of packages/modules required
--obsoletes print the list of packages/modules made obsolete