[英]How to specify multiple author(s) / email(s) in setup.py
We wrote a small wrapper to a twitter app and published this information to http:\/\/pypi.python.org<\/a> .我们为 twitter 应用程序编写了一个小包装器,并将此信息发布到http:\/\/pypi.python.org<\/a> 。 But setup.py just contained a single field for specifying email \/ name of the author.但是 setup.py 只包含一个用于指定电子邮件\/作者姓名的字段。 How do I specify multiple contributors \/ email list, to the following fields since we would like this package to be listed under our names, much similar to how it shows up in http:\/\/rubygems.org<\/a> .我如何在以下字段中指定多个贡献者\/电子邮件列表,因为我们希望这个包以我们的名字列出,非常类似于它在http:\/\/rubygems.org<\/a>中的显示方式。
author='foo',
author_email='foo.bar@gmail.com',
As far as I know, setuptools
doesn't support using a list of strings in order to specify multiple authors. 据我所知, setuptools
不支持使用字符串列表来指定多个作者。 Your best bet is to list the authors in a single string: 您最好的选择是将作者列在一个字符串中:
author='Foo Bar, Spam Eggs',
author_email='foobar@baz.com, spameggs@joe.org',
I'm not sure if PyPI validates the author_email
field, so you may run into trouble with that one. 我不确定PyPI是否验证了author_email
字段,因此您可能会遇到问题。 In any case, I would recommend you limit these to a single author and mention all contributors in the documentation or description. 无论如何,我建议您将这些限制为单个作者,并在文档或说明中提及所有贡献者。
This has been registered as a bug , actually, but it seems like support for multiple authors was not implemented. 实际上,这已被注册为错误 ,但似乎没有实现对多个作者的支持。 Here is an alternative solution. 这是另一种解决方案。 Here is an idea for how to provide a contact email for a project with multiple authors. 以下是如何为具有多位作者的项目提供联系电子邮件的想法。
I'm sort of just piggybacking off of @modocache's answer, in case you want some specifics. 我有点只是抄袭@ modocache的答案,以防你需要一些细节。
Throughout this answer, I'll be refering to a python3.6 version of the FOO-PYTHON-ENV\\Lib\\distutils\\dist.py
file 在这个答案中,我将引用一个python3.6版本的FOO-PYTHON-ENV\\Lib\\distutils\\dist.py
文件
author
field. 重申一下,您不能在author
字段中使用列表。 Here's why: 原因如下: DistributionMetadata
class are the reason -- Spoiler:属于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
field: 如果您尝试在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)...*#
& Here's the whole thing: 这是整个事情:
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
Consider using flit<\/strong><\/a> to build the package, as this build system supports multiple authors and maintainers.考虑使用flit<\/strong><\/a>来构建包,因为这个构建系统支持多个作者和维护者。 Store this metadata inpyproject.toml<\/code><\/a> as follows:
将此元数据存储在
pyproject.toml<\/code><\/a>中,如下所示:
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
[project]
...
authors = [
{name = "First1 Last1", email = "name1@foo.bar"},
{name = "First2 Last2", email = "name2@foo.bar"},
]
maintainers = [
{name = "First1 Last1", email = "name1@foo.bar"},
{name = "First2 Last2", email = "name2@foo.bar"},
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.