|
2 | 2 |
|
3 | 3 | Implements the Distutils 'check' command.
|
4 | 4 | """
|
| 5 | +from email.utils import getaddresses |
| 6 | + |
5 | 7 | from distutils.core import Command
|
6 | 8 | from distutils.errors import DistutilsSetupError
|
7 | 9 |
|
@@ -96,19 +98,39 @@ def check_metadata(self):
|
96 | 98 |
|
97 | 99 | if missing:
|
98 | 100 | self.warn("missing required meta-data: %s" % ', '.join(missing))
|
99 |
| - if metadata.author: |
100 |
| - if not metadata.author_email: |
101 |
| - self.warn("missing meta-data: if 'author' supplied, " + |
102 |
| - "'author_email' should be supplied too") |
103 |
| - elif metadata.maintainer: |
104 |
| - if not metadata.maintainer_email: |
105 |
| - self.warn("missing meta-data: if 'maintainer' supplied, " + |
106 |
| - "'maintainer_email' should be supplied too") |
107 |
| - else: |
| 101 | + if not ( |
| 102 | + self._check_contact("author", metadata) or |
| 103 | + self._check_contact("maintainer", metadata) |
| 104 | + ): |
108 | 105 | self.warn("missing meta-data: either (author and author_email) " +
|
109 | 106 | "or (maintainer and maintainer_email) " +
|
110 | 107 | "should be supplied")
|
111 | 108 |
|
| 109 | + def _check_contact(self, kind, metadata): |
| 110 | + """ |
| 111 | + Returns True if the contact's name is specified and False otherwise. |
| 112 | + This function will warn if the contact's email is not specified. |
| 113 | + """ |
| 114 | + name = getattr(metadata, kind) or '' |
| 115 | + email = getattr(metadata, kind + '_email') or '' |
| 116 | + |
| 117 | + msg = ("missing meta-data: if '{}' supplied, " + |
| 118 | + "'{}' should be supplied too") |
| 119 | + |
| 120 | + if name and email: |
| 121 | + return True |
| 122 | + |
| 123 | + if name: |
| 124 | + self.warn(msg.format(kind, kind + '_email')) |
| 125 | + return True |
| 126 | + |
| 127 | + addresses = [(alias, addr) for alias, addr in getaddresses([email])] |
| 128 | + if any(alias and addr for alias, addr in addresses): |
| 129 | + # The contact's name can be encoded in the email: `Name <email>` |
| 130 | + return True |
| 131 | + |
| 132 | + return False |
| 133 | + |
112 | 134 | def check_restructuredtext(self):
|
113 | 135 | """Checks if the long string fields are reST-compliant."""
|
114 | 136 | data = self.distribution.get_long_description()
|
|
0 commit comments