@@ -93,7 +93,7 @@ def test_apply_pyproject_equivalent_to_setupcfg(url, monkeypatch, tmp_path):
9393description = "Lovely Spam! Wonderful Spam!"
9494readme = "README.rst"
9595requires-python = ">=3.8"
96- license = {file = "LICENSE.txt"}
96+ license-files = [ "LICENSE.txt"] # Updated to be PEP 639 compliant
9797keywords = ["egg", "bacon", "sausage", "tomatoes", "Lobster Thermidor"]
9898authors = [
9999@@ -206,7 +206,6 @@ def test_pep621_example(tmp_path):
206206 """Make sure the example in PEP 621 works"""
207207 pyproject = _pep621_example_project (tmp_path )
208208 dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
209- assert dist .metadata .license == "--- LICENSE stub ---"
210209 assert set (dist .metadata .license_files ) == {"LICENSE.txt" }
211210
212211
@@ -294,6 +293,11 @@ def test_utf8_maintainer_in_metadata( # issue-3663
294293 'License: MIT' ,
295294 'License-Expression: ' ,
296295 id = 'license-text' ,
296+ marks = [
297+ pytest .mark .filterwarnings (
298+ "ignore:.project.license. as a TOML table is deprecated" ,
299+ )
300+ ],
297301 ),
298302 pytest .param (
299303 PEP639_LICENSE_EXPRESSION ,
@@ -354,47 +358,51 @@ def test_license_classifier_without_license_expression(tmp_path):
354358 """
355359 pyproject = _pep621_example_project (tmp_path , "README" , text )
356360
357- msg = "License classifiers are deprecated(?:.|\n )*MIT License"
358- with pytest .warns (SetuptoolsDeprecationWarning , match = msg ):
361+ msg1 = "License classifiers are deprecated(?:.|\n )*MIT License"
362+ msg2 = ".project.license. as a TOML table is deprecated"
363+ with (
364+ pytest .warns (SetuptoolsDeprecationWarning , match = msg1 ),
365+ pytest .warns (SetuptoolsDeprecationWarning , match = msg2 ),
366+ ):
359367 dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
360368
361369 # Check license classifier is still included
362370 assert dist .metadata .get_classifiers () == ["License :: OSI Approved :: MIT License" ]
363371
364372
365373class TestLicenseFiles :
366- def base_pyproject (self , tmp_path , additional_text ):
367- pyproject = _pep621_example_project (tmp_path , "README" )
368- text = pyproject .read_text (encoding = "utf-8" )
369-
370- # Sanity-check
371- assert 'license = {file = "LICENSE.txt"}' in text
372- assert "[tool.setuptools]" not in text
373-
374- text = f"{ text } \n { additional_text } \n "
375- pyproject .write_text (text , encoding = "utf-8" )
376- return pyproject
377-
378- def base_pyproject_license_pep639 (self , tmp_path , additional_text = "" ):
379- pyproject = _pep621_example_project (tmp_path , "README" )
380- text = pyproject .read_text (encoding = "utf-8" )
374+ def base_pyproject (
375+ self ,
376+ tmp_path ,
377+ additional_text = "" ,
378+ license_toml = 'license = {file = "LICENSE.txt"}\n ' ,
379+ ):
380+ text = PEP639_LICENSE_EXPRESSION
381381
382382 # Sanity-check
383- assert 'license = {file = "LICENSE.txt"} ' in text
383+ assert 'license = "mit or apache-2.0" ' in text
384384 assert 'license-files' not in text
385385 assert "[tool.setuptools]" not in text
386386
387387 text = re .sub (
388- r"(license = {file = \"LICENSE.txt\"} )\n" ,
389- ( "license = \" licenseref-Proprietary \" \n license-files = [ \" _FILE* \" ] \n " ) ,
388+ r"(license = .* )\n" ,
389+ license_toml ,
390390 text ,
391391 count = 1 ,
392392 )
393- if additional_text :
394- text = f"{ text } \n { additional_text } \n "
395- pyproject . write_text ( text , encoding = "utf-8" )
393+ assert license_toml in text # sanity check
394+ text = f"{ text } \n { additional_text } \n "
395+ pyproject = _pep621_example_project ( tmp_path , "README" , pyproject_text = text )
396396 return pyproject
397397
398+ def base_pyproject_license_pep639 (self , tmp_path , additional_text = "" ):
399+ return self .base_pyproject (
400+ tmp_path ,
401+ additional_text = additional_text ,
402+ license_toml = 'license = "licenseref-Proprietary"'
403+ '\n license-files = ["_FILE*"]\n ' ,
404+ )
405+
398406 def test_both_license_and_license_files_defined (self , tmp_path ):
399407 setuptools_config = '[tool.setuptools]\n license-files = ["_FILE*"]'
400408 pyproject = self .base_pyproject (tmp_path , setuptools_config )
@@ -407,8 +415,12 @@ def test_both_license_and_license_files_defined(self, tmp_path):
407415 license = tmp_path / "LICENSE.txt"
408416 license .write_text ("LicenseRef-Proprietary\n " , encoding = "utf-8" )
409417
410- msg = "'tool.setuptools.license-files' is deprecated in favor of 'project.license-files'"
411- with pytest .warns (SetuptoolsDeprecationWarning , match = msg ):
418+ msg1 = "'tool.setuptools.license-files' is deprecated in favor of 'project.license-files'"
419+ msg2 = ".project.license. as a TOML table is deprecated"
420+ with (
421+ pytest .warns (SetuptoolsDeprecationWarning , match = msg1 ),
422+ pytest .warns (SetuptoolsDeprecationWarning , match = msg2 ),
423+ ):
412424 dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
413425 assert set (dist .metadata .license_files ) == {"_FILE.rst" , "_FILE.txt" }
414426 assert dist .metadata .license == "LicenseRef-Proprietary\n "
@@ -437,17 +449,35 @@ def test_license_files_defined_twice(self, tmp_path):
437449 def test_default_patterns (self , tmp_path ):
438450 setuptools_config = '[tool.setuptools]\n zip-safe = false'
439451 # ^ used just to trigger section validation
440- pyproject = self .base_pyproject (tmp_path , setuptools_config )
452+ pyproject = self .base_pyproject (tmp_path , setuptools_config , license_toml = "" )
441453
442454 license_files = "LICENCE-a.html COPYING-abc.txt AUTHORS-xyz NOTICE,def" .split ()
443455
444456 for fname in license_files :
445457 (tmp_path / fname ).write_text (f"{ fname } \n " , encoding = "utf-8" )
446458
447459 dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
460+
448461 assert (tmp_path / "LICENSE.txt" ).exists () # from base example
449462 assert set (dist .metadata .license_files ) == {* license_files , "LICENSE.txt" }
450463
464+ def test_deprecated_file_expands_to_text (self , tmp_path ):
465+ """Make sure the old example with ``license = {text = ...}`` works"""
466+
467+ assert 'license-files = ["LICENSE.txt"]' in PEP621_EXAMPLE # sanity check
468+ text = PEP621_EXAMPLE .replace (
469+ 'license-files = ["LICENSE.txt"]' ,
470+ 'license = {file = "LICENSE.txt"}' ,
471+ )
472+ pyproject = _pep621_example_project (tmp_path , pyproject_text = text )
473+
474+ msg = ".project.license. as a TOML table is deprecated"
475+ with pytest .warns (SetuptoolsDeprecationWarning , match = msg ):
476+ dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
477+
478+ assert dist .metadata .license == "--- LICENSE stub ---"
479+ assert set (dist .metadata .license_files ) == {"LICENSE.txt" } # auto-filled
480+
451481
452482class TestPyModules :
453483 # https://github.com/pypa/setuptools/issues/4316
0 commit comments