summaryrefslogtreecommitdiff
path: root/distutils/command
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2022-02-23 11:14:26 +0000
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2022-02-23 11:24:23 +0000
commit05c961b808bfd8d2e87e569e5694694cfd35702b (patch)
tree5edcdcc904eb2d7be3f85e8002f4e6dcefedcfed /distutils/command
parent64b9948f9e9ad2f41bf47802f9e1b40be0ff198e (diff)
downloadpython-setuptools-git-05c961b808bfd8d2e87e569e5694694cfd35702b.tar.gz
Don't warn on false positive for author/maintainer's email
While I was working to support pyproject.toml metadata in setuptools, I received as a feedback from the community[^1] that setuptools warns the following message when `author_email` and `maintainer_email` are given in the form of `Person Name <email@address>`: > warning: check: missing meta-data: either (author and author_email) > or (maintainer and maintainer_email) should be supplied This can be seen as a false positive, because indeed both author's name and email are provided. This warning seems to happen because distutils define the `check` command as a subcommand for `sdist`. This change aims to remove this false positive result from the checks. [^1]: https://discuss.python.org/t/help-testing-experimental-features-in-setuptools/13821/18
Diffstat (limited to 'distutils/command')
-rw-r--r--distutils/command/check.py40
1 files changed, 31 insertions, 9 deletions
diff --git a/distutils/command/check.py b/distutils/command/check.py
index 525540b6..af311ca9 100644
--- a/distutils/command/check.py
+++ b/distutils/command/check.py
@@ -2,6 +2,8 @@
Implements the Distutils 'check' command.
"""
+from email.utils import getaddresses
+
from distutils.core import Command
from distutils.errors import DistutilsSetupError
@@ -96,19 +98,39 @@ class check(Command):
if missing:
self.warn("missing required meta-data: %s" % ', '.join(missing))
- if metadata.author:
- if not metadata.author_email:
- self.warn("missing meta-data: if 'author' supplied, " +
- "'author_email' should be supplied too")
- elif metadata.maintainer:
- if not metadata.maintainer_email:
- self.warn("missing meta-data: if 'maintainer' supplied, " +
- "'maintainer_email' should be supplied too")
- else:
+ if not (
+ self._check_contact("author", metadata) or
+ self._check_contact("maintainer", metadata)
+ ):
self.warn("missing meta-data: either (author and author_email) " +
"or (maintainer and maintainer_email) " +
"should be supplied")
+ def _check_contact(self, kind, metadata):
+ """
+ Returns True if the contact's name is specified and False otherwise.
+ This function will warn if the contact's email is not specified.
+ """
+ name = getattr(metadata, kind) or ''
+ email = getattr(metadata, kind + '_email') or ''
+
+ msg = ("missing meta-data: if '{}' supplied, " +
+ "'{}' should be supplied too")
+
+ if name and email:
+ return True
+
+ if name:
+ self.warn(msg.format(kind, kind + '_email'))
+ return True
+
+ addresses = [(alias, addr) for alias, addr in getaddresses([email])]
+ if any(alias and addr for alias, addr in addresses):
+ # The contact's name can be encoded in the email: `Name <email>`
+ return True
+
+ return False
+
def check_restructuredtext(self):
"""Checks if the long string fields are reST-compliant."""
data = self.distribution.get_long_description()