172172 ),
173173 "README.rst" : "UTF-8 描述 説明" ,
174174 },
175+ "licenses-dist" : {
176+ "setup.cfg" : cleandoc (
177+ """
178+ [metadata]
179+ name = licenses-dist
180+ version = 1.0
181+ license_files = **/LICENSE
182+ """
183+ ),
184+ "LICENSE" : "" ,
185+ "src" : {
186+ "vendor" : {"LICENSE" : "" },
187+ },
188+ },
175189}
176190
177191
@@ -238,6 +252,11 @@ def dummy_dist(tmp_path_factory):
238252 return mkexample (tmp_path_factory , "dummy-dist" )
239253
240254
255+ @pytest .fixture
256+ def licenses_dist (tmp_path_factory ):
257+ return mkexample (tmp_path_factory , "licenses-dist" )
258+
259+
241260def test_no_scripts (wheel_paths ):
242261 """Make sure entry point scripts are not generated."""
243262 path = next (path for path in wheel_paths if "complex_dist" in path )
@@ -297,7 +316,8 @@ def test_licenses_default(dummy_dist, monkeypatch, tmp_path):
297316 bdist_wheel_cmd (bdist_dir = str (tmp_path )).run ()
298317 with ZipFile ("dist/dummy_dist-1.0-py3-none-any.whl" ) as wf :
299318 license_files = {
300- "dummy_dist-1.0.dist-info/" + fname for fname in DEFAULT_LICENSE_FILES
319+ "dummy_dist-1.0.dist-info/licenses/" + fname
320+ for fname in DEFAULT_LICENSE_FILES
301321 }
302322 assert set (wf .namelist ()) == DEFAULT_FILES | license_files
303323
@@ -311,7 +331,7 @@ def test_licenses_deprecated(dummy_dist, monkeypatch, tmp_path):
311331 bdist_wheel_cmd (bdist_dir = str (tmp_path )).run ()
312332
313333 with ZipFile ("dist/dummy_dist-1.0-py3-none-any.whl" ) as wf :
314- license_files = {"dummy_dist-1.0.dist-info/DUMMYFILE" }
334+ license_files = {"dummy_dist-1.0.dist-info/licenses/licenses/ DUMMYFILE" }
315335 assert set (wf .namelist ()) == DEFAULT_FILES | license_files
316336
317337
@@ -334,9 +354,29 @@ def test_licenses_override(dummy_dist, monkeypatch, tmp_path, config_file, confi
334354 bdist_wheel_cmd (bdist_dir = str (tmp_path )).run ()
335355 with ZipFile ("dist/dummy_dist-1.0-py3-none-any.whl" ) as wf :
336356 license_files = {
337- "dummy_dist-1.0.dist-info/" + fname for fname in {"DUMMYFILE" , "LICENSE" }
357+ "dummy_dist-1.0.dist-info/licenses/" + fname
358+ for fname in {"licenses/DUMMYFILE" , "LICENSE" }
338359 }
339360 assert set (wf .namelist ()) == DEFAULT_FILES | license_files
361+ metadata = wf .read ("dummy_dist-1.0.dist-info/METADATA" ).decode ("utf8" )
362+ assert "License-File: licenses/DUMMYFILE" in metadata
363+ assert "License-File: LICENSE" in metadata
364+
365+
366+ def test_licenses_preserve_folder_structure (licenses_dist , monkeypatch , tmp_path ):
367+ monkeypatch .chdir (licenses_dist )
368+ bdist_wheel_cmd (bdist_dir = str (tmp_path )).run ()
369+ print (os .listdir ("dist" ))
370+ with ZipFile ("dist/licenses_dist-1.0-py3-none-any.whl" ) as wf :
371+ default_files = {name .replace ("dummy_" , "licenses_" ) for name in DEFAULT_FILES }
372+ license_files = {
373+ "licenses_dist-1.0.dist-info/licenses/LICENSE" ,
374+ "licenses_dist-1.0.dist-info/licenses/src/vendor/LICENSE" ,
375+ }
376+ assert set (wf .namelist ()) == default_files | license_files
377+ metadata = wf .read ("licenses_dist-1.0.dist-info/METADATA" ).decode ("utf8" )
378+ assert "License-File: src/vendor/LICENSE" in metadata
379+ assert "License-File: LICENSE" in metadata
340380
341381
342382def test_licenses_disabled (dummy_dist , monkeypatch , tmp_path ):
0 commit comments