@@ -93,7 +93,7 @@ def test_apply_pyproject_equivalent_to_setupcfg(url, monkeypatch, tmp_path):
93
93
description = "Lovely Spam! Wonderful Spam!"
94
94
readme = "README.rst"
95
95
requires-python = ">=3.8"
96
- license = {file = "LICENSE.txt"}
96
+ license-files = [ "LICENSE.txt"] # Updated to be PEP 639 compliant
97
97
keywords = ["egg", "bacon", "sausage", "tomatoes", "Lobster Thermidor"]
98
98
authors = [
99
99
@@ -206,7 +206,6 @@ def test_pep621_example(tmp_path):
206
206
"""Make sure the example in PEP 621 works"""
207
207
pyproject = _pep621_example_project (tmp_path )
208
208
dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
209
- assert dist .metadata .license == "--- LICENSE stub ---"
210
209
assert set (dist .metadata .license_files ) == {"LICENSE.txt" }
211
210
212
211
@@ -294,6 +293,11 @@ def test_utf8_maintainer_in_metadata( # issue-3663
294
293
'License: MIT' ,
295
294
'License-Expression: ' ,
296
295
id = 'license-text' ,
296
+ marks = [
297
+ pytest .mark .filterwarnings (
298
+ "ignore:.project.license. as a TOML table is deprecated" ,
299
+ )
300
+ ],
297
301
),
298
302
pytest .param (
299
303
PEP639_LICENSE_EXPRESSION ,
@@ -354,47 +358,51 @@ def test_license_classifier_without_license_expression(tmp_path):
354
358
"""
355
359
pyproject = _pep621_example_project (tmp_path , "README" , text )
356
360
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
+ ):
359
367
dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
360
368
361
369
# Check license classifier is still included
362
370
assert dist .metadata .get_classifiers () == ["License :: OSI Approved :: MIT License" ]
363
371
364
372
365
373
class 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
381
381
382
382
# Sanity-check
383
- assert 'license = {file = "LICENSE.txt"} ' in text
383
+ assert 'license = "mit or apache-2.0" ' in text
384
384
assert 'license-files' not in text
385
385
assert "[tool.setuptools]" not in text
386
386
387
387
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 ,
390
390
text ,
391
391
count = 1 ,
392
392
)
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 )
396
396
return pyproject
397
397
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
+
398
406
def test_both_license_and_license_files_defined (self , tmp_path ):
399
407
setuptools_config = '[tool.setuptools]\n license-files = ["_FILE*"]'
400
408
pyproject = self .base_pyproject (tmp_path , setuptools_config )
@@ -407,8 +415,12 @@ def test_both_license_and_license_files_defined(self, tmp_path):
407
415
license = tmp_path / "LICENSE.txt"
408
416
license .write_text ("LicenseRef-Proprietary\n " , encoding = "utf-8" )
409
417
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
+ ):
412
424
dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
413
425
assert set (dist .metadata .license_files ) == {"_FILE.rst" , "_FILE.txt" }
414
426
assert dist .metadata .license == "LicenseRef-Proprietary\n "
@@ -437,17 +449,35 @@ def test_license_files_defined_twice(self, tmp_path):
437
449
def test_default_patterns (self , tmp_path ):
438
450
setuptools_config = '[tool.setuptools]\n zip-safe = false'
439
451
# ^ 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 = "" )
441
453
442
454
license_files = "LICENCE-a.html COPYING-abc.txt AUTHORS-xyz NOTICE,def" .split ()
443
455
444
456
for fname in license_files :
445
457
(tmp_path / fname ).write_text (f"{ fname } \n " , encoding = "utf-8" )
446
458
447
459
dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
460
+
448
461
assert (tmp_path / "LICENSE.txt" ).exists () # from base example
449
462
assert set (dist .metadata .license_files ) == {* license_files , "LICENSE.txt" }
450
463
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
+
451
481
452
482
class TestPyModules :
453
483
# https://github.com/pypa/setuptools/issues/4316
0 commit comments