@@ -217,6 +217,21 @@ def test_all_fields(script: PipTestEnvironment) -> None:
217
217
"""
218
218
Test that all the fields are present
219
219
"""
220
+ # future-compat: once pip adopts PEP 639 in pyproject.toml and
221
+ # its build backend produces metadata 2.4 or greater,
222
+ # it will display "License-Expression" rather than License
223
+ verbose = script .pip ("show" , "--verbose" , "pip" ).stdout
224
+ match = re .search (r"Metadata-Version:\s(\d+\.\d+)" , verbose )
225
+ if match is not None :
226
+ metadata_version = match .group (1 )
227
+ metadata_version_tuple = tuple (map (int , metadata_version .split ("." )))
228
+ if metadata_version_tuple >= (2 , 4 ) and "License-Expression" in verbose :
229
+ license_str = "License-Expression"
230
+ else :
231
+ license_str = "License"
232
+ else :
233
+ license_str = "License"
234
+
220
235
result = script .pip ("show" , "pip" )
221
236
lines = result .stdout .splitlines ()
222
237
expected = {
@@ -226,7 +241,7 @@ def test_all_fields(script: PipTestEnvironment) -> None:
226
241
"Home-page" ,
227
242
"Author" ,
228
243
"Author-email" ,
229
- "License " ,
244
+ f" { license_str } " ,
230
245
"Location" ,
231
246
"Editable project location" ,
232
247
"Requires" ,
@@ -410,3 +425,29 @@ def test_show_populate_homepage_from_project_urls(
410
425
result = script .pip ("show" , "simple" , cwd = pkg_path )
411
426
lines = result .stdout .splitlines ()
412
427
assert "Home-page: https://example.com" in lines
428
+
429
+
430
+ def test_show_license_expression (script : PipTestEnvironment , data : TestData ) -> None :
431
+ """
432
+ Show License-Expression if present in metadata >= 2.4.
433
+ """
434
+ wheel_file = data .packages .joinpath ("license.dist-0.1-py2.py3-none-any.whl" )
435
+ script .pip ("install" , "--no-index" , wheel_file )
436
+ result = script .pip ("show" , "license.dist" )
437
+ lines = result .stdout .splitlines ()
438
+ assert "License-Expression: MIT AND MIT-0" in lines
439
+ assert "License: The legacy license declaration" not in lines
440
+
441
+
442
+ def test_show_license_for_metadata_24 (
443
+ script : PipTestEnvironment , data : TestData
444
+ ) -> None :
445
+ """
446
+ Show License if License-Expression is not there for metadata >= 2.4.
447
+ """
448
+ wheel_file = data .packages .joinpath ("license.dist-0.2-py2.py3-none-any.whl" )
449
+ script .pip ("install" , "--no-index" , wheel_file )
450
+ result = script .pip ("show" , "license.dist" )
451
+ lines = result .stdout .splitlines ()
452
+ assert "License-Expression: " not in lines
453
+ assert "License: The legacy license declaration" in lines
0 commit comments