summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Holth <dholth@fastmail.fm>2016-06-26 22:47:55 -0400
committerDaniel Holth <dholth@fastmail.fm>2016-06-26 22:47:55 -0400
commitb96985e04be87bc062129be3e7fc23ea932fd524 (patch)
tree517fc63b01e56c6ca5443e4214aed24adcc9eaeb
parent00e5569e02c60b083f4f6c6a887b41a775f79423 (diff)
downloadwheel-b96985e04be87bc062129be3e7fc23ea932fd524.tar.gz
refactor wheel.metadata.pkginfo_to_metadata
Added a reuseable generate_requirements(extras_require) function.
-rw-r--r--wheel/metadata.py37
1 files changed, 25 insertions, 12 deletions
diff --git a/wheel/metadata.py b/wheel/metadata.py
index 47b15ce..6710677 100644
--- a/wheel/metadata.py
+++ b/wheel/metadata.py
@@ -236,6 +236,29 @@ def convert_requirements(requirements):
extras = "[%s]" % extras
yield (parsed_requirement.project_name + extras + spec)
+def generate_requirements(extras_require):
+ """
+ Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
+ and ('Provides-Extra', 'extra') tuples.
+
+ extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
+ using the empty extra {'': [requirements]} to hold install_requires.
+ """
+ for extra, depends in extras_require.items():
+ condition = ''
+ if extra and ':' in extra: # setuptools extra:condition syntax
+ extra, condition = extra.split(':', 1)
+ extra = pkg_resources.safe_extra(extra)
+ if extra:
+ yield ('Provides-Extra', extra)
+ if condition:
+ condition += " and "
+ condition += "extra == '%s'" % extra
+ if condition:
+ condition = '; ' + condition
+ for new_req in convert_requirements(depends):
+ yield ('Requires-Dist', new_req + condition)
+
def pkginfo_to_metadata(egg_info_path, pkginfo_path):
"""
Convert .egg-info directory with PKG-INFO to the Metadata 1.3 aka
@@ -249,18 +272,8 @@ def pkginfo_to_metadata(egg_info_path, pkginfo_path):
requires = requires_file.read()
for extra, reqs in sorted(pkg_resources.split_sections(requires),
key=lambda x: x[0] or ''):
- condition = ''
- if extra and ':' in extra: # setuptools extra:condition syntax
- extra, condition = extra.split(':', 1)
- if extra:
- pkg_info['Provides-Extra'] = extra
- if condition:
- condition += " and "
- condition += 'extra == %s' % repr(extra)
- if condition:
- condition = '; ' + condition
- for new_req in sorted(convert_requirements(reqs)):
- pkg_info['Requires-Dist'] = new_req + condition
+ for item in generate_requirements({extra: reqs}):
+ pkg_info[item[0]] = item[1]
description = pkg_info['Description']
if description: