Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: email formatting #87

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import collections
import copy
import dataclasses
import email.utils
import os
import os.path
import pathlib
Expand Down Expand Up @@ -319,11 +320,11 @@ def _name_list(self, people: list[tuple[str, str]]) -> str:
)

def _email_list(self, people: list[tuple[str, str]]) -> str:
return ', '.join([
'{}{}'.format(name, f' <{_email}>' if _email else '')
return ', '.join(
email.utils.formataddr((name, _email))
for name, _email in people
if _email
])
)

def _build_extra_req(
self,
Expand Down
25 changes: 25 additions & 0 deletions tests/test_rfc822.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,28 @@ def test_convert_optional_dependencies():
'foo; (os_name == "nt" or sys_platform == "win32") and extra == "test"',
'bar; os_name == "posix" and sys_platform == "linux" and extra == "test"',
]


def test_convert_author_email():
metadata = pyproject_metadata.StandardMetadata.from_pyproject(
{
'project': {
'name': 'example',
'version': '0.1.0',
'authors': [
{
'name': 'John Doe, Inc.',
'email': '[email protected]',
},
{
'name': 'Kate Doe, LLC.',
'email': '[email protected]',
}
],
},
}
)
message = metadata.as_rfc822()
assert message.headers['Author-Email'] == [
'"John Doe, Inc." <[email protected]>, "Kate Doe, LLC." <[email protected]>'
]
Loading