【问题标题】:How can I find out what version is passed to setup in setup.py?如何在 setup.py 中找出传递给 setup 的版本?
【发布时间】:2015-11-26 15:51:52
【问题描述】:

我正在寻找的是这样的:

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'])

坦率地说,这太可怕了!

我该怎么做?

【问题讨论】:

    标签: python setuptools


    【解决方案1】:

    Setuptools 为设置脚本调用提供了一个 --version 标志。

    $ python setup.py --version
    

    【讨论】:

      【解决方案2】:

      或者,如果您需要包中的其他元数据,jaraco.packaging 提供了一个show 命令,可用于显示包中任意数量的属性。

      【讨论】:

      • 不知道除了阅读 --help 之外还需要什么,不敢相信我错过了:-S
      【解决方案3】:

      可以从 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
      

      【讨论】:

        猜你喜欢
        • 2010-12-13
        • 1970-01-01
        • 1970-01-01
        • 2010-10-15
        • 1970-01-01
        • 1970-01-01
        • 2021-02-23
        • 1970-01-01
        • 2017-03-16
        相关资源
        最近更新 更多