Skip to content

Commit 3202415

Browse files
committed
fix handling of extras
Ensure extras are properly canonicalized, so corresponding `Provides-Dist` markers will match with the list of extras returned by pkg_resources.
1 parent f385549 commit 3202415

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

tests/test_metadata.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ def test_pkginfo_to_metadata(tmpdir):
66
('Metadata-Version', '2.1'),
77
('Name', 'spam'),
88
('Version', '0.1'),
9-
('Provides-Extra', 'test'),
9+
('Requires-Dist', 'pywin32; sys_platform=="win32"'),
1010
('Provides-Extra', 'signatures'),
11+
('Requires-Dist', 'pyxdg; (sys_platform!="win32") and extra == \'signatures\''),
12+
('Provides-Extra', 'empty_extra'),
1113
('Provides-Extra', 'faster-signatures'),
1214
('Requires-Dist', "ed25519ll; extra == 'faster-signatures'"),
15+
('Provides-Extra', 'rest'),
16+
('Requires-Dist', "docutils (>=0.8); extra == 'rest'"),
1317
('Requires-Dist', "keyring; extra == 'signatures'"),
1418
('Requires-Dist', "keyrings.alt; extra == 'signatures'"),
15-
('Requires-Dist', 'pyxdg; (sys_platform!="win32") and extra == \'signatures\''),
19+
('Provides-Extra', 'test'),
1620
('Requires-Dist', "pytest (>=3.0.0); extra == 'test'"),
1721
('Requires-Dist', "pytest-cov; extra == 'test'"),
1822
]
@@ -22,20 +26,31 @@ def test_pkginfo_to_metadata(tmpdir):
2226
Metadata-Version: 0.0
2327
Name: spam
2428
Version: 0.1
29+
Provides-Extra: empty+extra
2530
Provides-Extra: test
31+
Provides-Extra: reST
2632
Provides-Extra: signatures
33+
Provides-Extra: Signatures
2734
Provides-Extra: faster-signatures""")
2835

2936
egg_info_dir = tmpdir.ensure_dir('test.egg-info')
3037
egg_info_dir.join('requires.txt').write("""\
38+
[empty+extra]
39+
40+
[:sys_platform=="win32"]
41+
pywin32
42+
3143
[faster-signatures]
3244
ed25519ll
3345
46+
[reST]
47+
docutils>=0.8
48+
3449
[signatures]
3550
keyring
3651
keyrings.alt
3752
38-
[signatures:sys_platform!="win32"]
53+
[Signatures:sys_platform!="win32"]
3954
pyxdg
4055
4156
[test]

wheel/metadata.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ def generate_requirements(extras_require):
4646
"""
4747
for extra, depends in extras_require.items():
4848
condition = ''
49-
if extra and ':' in extra: # setuptools extra:condition syntax
49+
extra = extra or ''
50+
if ':' in extra: # setuptools extra:condition syntax
5051
extra, condition = extra.split(':', 1)
51-
extra = pkg_resources.safe_extra(extra)
5252

53+
extra = pkg_resources.safe_extra(extra)
5354
if extra:
5455
yield 'Provides-Extra', extra
5556
if condition:
@@ -69,6 +70,9 @@ def pkginfo_to_metadata(egg_info_path, pkginfo_path):
6970
"""
7071
pkg_info = read_pkg_info(pkginfo_path)
7172
pkg_info.replace_header('Metadata-Version', '2.1')
73+
# Those will be regenerated from `requires.txt`.
74+
del pkg_info['Provides-Extra']
75+
del pkg_info['Requires-Dist']
7276
requires_path = os.path.join(egg_info_path, 'requires.txt')
7377
if os.path.exists(requires_path):
7478
with open(requires_path) as requires_file:

0 commit comments

Comments
 (0)