@@ -217,6 +217,16 @@ def test_all_fields(script: PipTestEnvironment) -> None:
217217 """
218218 Test that all the fields are present
219219 """
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+
220230 result = script .pip ("show" , "pip" )
221231 lines = result .stdout .splitlines ()
222232 expected = {
@@ -226,7 +236,7 @@ def test_all_fields(script: PipTestEnvironment) -> None:
226236 "Home-page" ,
227237 "Author" ,
228238 "Author-email" ,
229- "License " ,
239+ f" { license_str } " ,
230240 "Location" ,
231241 "Editable project location" ,
232242 "Requires" ,
@@ -410,3 +420,27 @@ def test_show_populate_homepage_from_project_urls(
410420 result = script .pip ("show" , "simple" , cwd = pkg_path )
411421 lines = result .stdout .splitlines ()
412422 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