summaryrefslogtreecommitdiff
path: root/setuptools/dist.py
diff options
context:
space:
mode:
authorIan Wienand <iwienand@redhat.com>2018-04-30 19:08:58 +1000
committerIan Wienand <iwienand@redhat.com>2018-05-17 07:22:25 +1000
commit07cd2e4e716264fd51aededcb77cefe37aafb25a (patch)
tree08c8395e42ab13e3d66ea5f903840993909aefb6 /setuptools/dist.py
parent1252d1b3b34261acd6c8051c4fe97f206a7118b7 (diff)
downloadpython-setuptools-git-07cd2e4e716264fd51aededcb77cefe37aafb25a.tar.gz
Allow setting long_description_content_type externally
Some tools, such as PBR, might want to set long_description_content_type during the parent object's Distribution.__init__() call (during distutils setup_keywords entry points). However, that field is currently unconditionally overwritten after these calls, erasing the value. We would rather not duplicate the existing method of copying into dist.metadata as done with project_urls. This preserves the fields within Distribution.metadata described by self._DISTUTIULS_UNUPPORTED_METADATA, or otherwise takes it from arguments. A test case that simulates setting the long description and overriding the arguments is added.
Diffstat (limited to 'setuptools/dist.py')
-rw-r--r--setuptools/dist.py36
1 files changed, 23 insertions, 13 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 321ab6b7..6ee4a97f 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -328,6 +328,12 @@ class Distribution(Distribution_parse_config_files, _Distribution):
distribution for the included and excluded features.
"""
+ _DISTUTILS_UNSUPPORTED_METADATA = {
+ 'long_description_content_type': None,
+ 'project_urls': dict,
+ 'provides_extras': set,
+ }
+
_patched_dist = None
def patch_missing_pkg_info(self, attrs):
@@ -353,25 +359,29 @@ class Distribution(Distribution_parse_config_files, _Distribution):
self.require_features = []
self.features = {}
self.dist_files = []
+ # Filter-out setuptools' specific options.
self.src_root = attrs.pop("src_root", None)
self.patch_missing_pkg_info(attrs)
- self.project_urls = attrs.get('project_urls', {})
self.dependency_links = attrs.pop('dependency_links', [])
self.setup_requires = attrs.pop('setup_requires', [])
for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
vars(self).setdefault(ep.name, None)
- _Distribution.__init__(self, attrs)
-
- # The project_urls attribute may not be supported in distutils, so
- # prime it here from our value if not automatically set
- self.metadata.project_urls = getattr(
- self.metadata, 'project_urls', self.project_urls)
- self.metadata.long_description_content_type = attrs.get(
- 'long_description_content_type'
- )
- self.metadata.provides_extras = getattr(
- self.metadata, 'provides_extras', set()
- )
+ _Distribution.__init__(self, {
+ k: v for k, v in attrs.items()
+ if k not in self._DISTUTILS_UNSUPPORTED_METADATA
+ })
+
+ # Fill-in missing metadata fields not supported by distutils.
+ # Note some fields may have been set by other tools (e.g. pbr)
+ # above; they are taken preferrentially to setup() arguments
+ for option, default in self._DISTUTILS_UNSUPPORTED_METADATA.items():
+ for source in self.metadata.__dict__, attrs:
+ if option in source:
+ value = source[option]
+ break
+ else:
+ value = default() if default else None
+ setattr(self.metadata, option, value)
if isinstance(self.metadata.version, numbers.Number):
# Some people apparently take "version number" too literally :)