2424from setuptools .config import expand , pyprojecttoml , setupcfg
2525from setuptools .config ._apply_pyprojecttoml import _MissingDynamic , _some_attrgetter
2626from setuptools .dist import Distribution
27- from setuptools .errors import RemovedConfigError
27+ from setuptools .errors import InvalidConfigError , RemovedConfigError
2828from setuptools .warnings import SetuptoolsDeprecationWarning
2929
3030from .downloads import retrieve_file , urls_from_file
@@ -366,7 +366,7 @@ def base_pyproject(self, tmp_path, additional_text):
366366 pyproject .write_text (text , encoding = "utf-8" )
367367 return pyproject
368368
369- def base_pyproject_license_pep639 (self , tmp_path ):
369+ def base_pyproject_license_pep639 (self , tmp_path , additional_text = "" ):
370370 pyproject = _pep621_example_project (tmp_path , "README" )
371371 text = pyproject .read_text (encoding = "utf-8" )
372372
@@ -381,6 +381,8 @@ def base_pyproject_license_pep639(self, tmp_path):
381381 text ,
382382 count = 1 ,
383383 )
384+ if additional_text :
385+ text = f"{ text } \n { additional_text } \n "
384386 pyproject .write_text (text , encoding = "utf-8" )
385387 return pyproject
386388
@@ -396,7 +398,9 @@ def test_both_license_and_license_files_defined(self, tmp_path):
396398 license = tmp_path / "LICENSE.txt"
397399 license .write_text ("LicenseRef-Proprietary\n " , encoding = "utf-8" )
398400
399- dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
401+ msg = "'tool.setuptools.license-files' is deprecated in favor of 'project.license-files'"
402+ with pytest .warns (SetuptoolsDeprecationWarning , match = msg ):
403+ dist = pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
400404 assert set (dist .metadata .license_files ) == {"_FILE.rst" , "_FILE.txt" }
401405 assert dist .metadata .license == "LicenseRef-Proprietary\n "
402406
@@ -412,6 +416,15 @@ def test_both_license_and_license_files_defined_pep639(self, tmp_path):
412416 assert dist .metadata .license is None
413417 assert dist .metadata .license_expression == "LicenseRef-Proprietary"
414418
419+ def test_license_files_defined_twice (self , tmp_path ):
420+ # Set project.license-files and tools.setuptools.license-files
421+ setuptools_config = '[tool.setuptools]\n license-files = ["_FILE*"]'
422+ pyproject = self .base_pyproject_license_pep639 (tmp_path , setuptools_config )
423+
424+ msg = "'project.license-files' is defined already. Remove 'tool.setuptools.license-files'"
425+ with pytest .raises (InvalidConfigError , match = msg ):
426+ pyprojecttoml .apply_configuration (makedist (tmp_path ), pyproject )
427+
415428 def test_default_patterns (self , tmp_path ):
416429 setuptools_config = '[tool.setuptools]\n zip-safe = false'
417430 # ^ used just to trigger section validation
0 commit comments