如何在 setup.py 中指定多个作者/电子邮件

新手上路,请多包涵

我们为 Twitter 应用程序编写了一个小包装器,并将此信息发布到 http://pypi.python.org 。但是 setup.py 只包含一个字段用于指定作者的电子邮件/姓名。我如何在以下字段中指定多个贡献者/电子邮件列表,因为我们希望这个包列在我们的名字下,这与它在 http://rubygems.org 中的显示方式非常相似。

 author='foo',
author_email='foo.bar@gmail.com',

原文由 priya 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 851
2 个回答

据我所知, setuptools 不支持使用字符串列表来指定多个作者。最好的办法是在一个字符串中列出作者:

 author='Foo Bar, Spam Eggs',
author_email='foobar@baz.com, spameggs@joe.org',

我不确定 PyPI 是否验证了 author_email 字段,所以你可能会遇到那个问题。无论如何,我建议您将这些限制为单个作者,并在文档或描述中提及所有贡献者。

一些来源:

实际上,这已被 注册为一个错误,但似乎没有实现对多个作者的支持。 是一个替代解决方案。 以下 是如何为具有多个作者的项目提供联系电子邮件的想法。

原文由 modocache 发布,翻译遵循 CC BY-SA 4.0 许可协议

如果您需要一些细节,我只是在借鉴@modocache 的回答。

在整个回答中,我将引用 FOO-PYTHON-ENV\Lib\distutils\dist.py 文件的 python3.6 版本

重申一下,您不能在 author 字段中使用列表。原因如下:

剧透:属于 DistributionMetadata 类的两个方法是原因 –

 def _read_field(name):
    value = msg[name]
    if value == 'UNKNOWN':
        return None
    return value

def _read_list(name):
    values = msg.get_all(name, None)
    if values == []:
        return None
    return values

如果您尝试在 author 字段中添加一个列表,您将在这里遇到错误:

 class DistributionMetadata:

#*...(R E D A C T E D)...*#

    def read_pkg_file(self, file):
        """Reads the metadata values from a file object."""
    #*...(R E D A C T E D)...*#
        # ####################################
        # Note the usage of _read_field() here
        # ####################################
        self.name = _read_field('name')
        self.version = _read_field('version')
        self.description = _read_field('summary')
        # we are filling author only.
        self.author = _read_field('author')
        self.maintainer = None
        self.author_email = _read_field('author-email')
        self.maintainer_email = None
        self.url = _read_field('home-page')
        self.license = _read_field('license')
    #*...(R E D A C T E D)...*#
        # ###################################
        # Note the usage of _read_list() here
        # ###################################
        self.platforms = _read_list('platform')
        self.classifiers = _read_list('classifier')
    #*...(R E D A C T E D)...*#

&这是整个事情:

 class DistributionMetadata:
        """Dummy class to hold the distribution meta-data: name, version,
        author, and so forth.
        """

        _METHOD_BASENAMES = ("name", "version", "author", "author_email",
                     "maintainer", "maintainer_email", "url",
                     "license", "description", "long_description",
                     "keywords", "platforms", "fullname", "contact",
                     "contact_email", "classifiers", "download_url",
                     # PEP 314
                     "provides", "requires", "obsoletes",
                     )

    def __init__(self, path=None):
        if path is not None:
            self.read_pkg_file(open(path))
        else:
            self.name = None
            self.version = None
            self.author = None
            self.author_email = None
            self.maintainer = None
            self.maintainer_email = None
            self.url = None
            self.license = None
            self.description = None
            self.long_description = None
            self.keywords = None
            self.platforms = None
            self.classifiers = None
            self.download_url = None
            # PEP 314
            self.provides = None
            self.requires = None
            self.obsoletes = None

    def read_pkg_file(self, file):
        """Reads the metadata values from a file object."""
        msg = message_from_file(file)

        def _read_field(name):
            value = msg[name]
            if value == 'UNKNOWN':
                return None
            return value

        def _read_list(name):
            values = msg.get_all(name, None)
            if values == []:
                return None
            return values

        metadata_version = msg['metadata-version']
        self.name = _read_field('name')
        self.version = _read_field('version')
        self.description = _read_field('summary')
        # we are filling author only.
        self.author = _read_field('author')
        self.maintainer = None
        self.author_email = _read_field('author-email')
        self.maintainer_email = None
        self.url = _read_field('home-page')
        self.license = _read_field('license')

        if 'download-url' in msg:
            self.download_url = _read_field('download-url')
        else:
            self.download_url = None

        self.long_description = _read_field('description')
        self.description = _read_field('summary')

        if 'keywords' in msg:
            self.keywords = _read_field('keywords').split(',')

        self.platforms = _read_list('platform')
        self.classifiers = _read_list('classifier')

        # PEP 314 - these fields only exist in 1.1
        if metadata_version == '1.1':
            self.requires = _read_list('requires')
            self.provides = _read_list('provides')
            self.obsoletes = _read_list('obsoletes')
        else:
            self.requires = None
            self.provides = None
            self.obsoletes = None

原文由 Rob Truxal 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题