@@ -217,6 +217,16 @@ 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 ).group (1 )
225
+ if tuple (map (int , match .split ('.' ))) >= (2 , 4 ) and "License-Expression" in verbose :
226
+ license_str = "License-Expression"
227
+ else :
228
+ license_str = "License"
229
+
220
230
result = script .pip ("show" , "pip" )
221
231
lines = result .stdout .splitlines ()
222
232
expected = {
@@ -226,7 +236,7 @@ def test_all_fields(script: PipTestEnvironment) -> None:
226
236
"Home-page" ,
227
237
"Author" ,
228
238
"Author-email" ,
229
- "License " ,
239
+ f" { license_str } " ,
230
240
"Location" ,
231
241
"Editable project location" ,
232
242
"Requires" ,
@@ -410,3 +420,27 @@ def test_show_populate_homepage_from_project_urls(
410
420
result = script .pip ("show" , "simple" , cwd = pkg_path )
411
421
lines = result .stdout .splitlines ()
412
422
assert "Home-page: https://example.com" in lines
423
+
424
+
425
+ def test_show_license_expression (script : PipTestEnvironment , data : TestData ) -> None :
426
+ """
427
+ Show License-Expression if present in metadata >= 2.4.
428
+ """
429
+ wheel_file = data .packages .joinpath ("license.dist-0.1-py2.py3-none-any.whl" )
430
+ script .pip ("install" , "--no-index" , wheel_file )
431
+ result = script .pip ("show" , "license.dist" )
432
+ lines = result .stdout .splitlines ()
433
+ assert "License-Expression: MIT AND MIT-0" in lines
434
+ assert "License: The legacy license declaration" not in lines
435
+
436
+
437
+ def test_show_license_for_metadata_24 (script : PipTestEnvironment , data : TestData ) -> None :
438
+ """
439
+ Show License if License-Expression is not there for metadata >= 2.4.
440
+ """
441
+ wheel_file = data .packages .joinpath ("license.dist-0.2-py2.py3-none-any.whl" )
442
+ script .pip ("install" , "--no-index" , wheel_file )
443
+ result = script .pip ("show" , "license.dist" )
444
+ lines = result .stdout .splitlines ()
445
+ assert "License-Expression: " not in lines
446
+ assert "License: The legacy license declaration" in lines
0 commit comments