5959EXAMPLES = {
6060 "dummy-dist" : {
6161 "setup.py" : SETUPPY_EXAMPLE ,
62- "licenses " : {"DUMMYFILE" : "" },
62+ "licenses_dir " : {"DUMMYFILE" : "" },
6363 ** dict .fromkeys (DEFAULT_LICENSE_FILES | OTHER_IGNORED_FILES , "" ),
6464 },
6565 "simple-dist" : {
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,33 +316,34 @@ 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
304324
305325def test_licenses_deprecated (dummy_dist , monkeypatch , tmp_path ):
306326 dummy_dist .joinpath ("setup.cfg" ).write_text (
307- "[metadata]\n license_file=licenses /DUMMYFILE" , encoding = "utf-8"
327+ "[metadata]\n license_file=licenses_dir /DUMMYFILE" , encoding = "utf-8"
308328 )
309329 monkeypatch .chdir (dummy_dist )
310330
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_dir/ DUMMYFILE" }
315335 assert set (wf .namelist ()) == DEFAULT_FILES | license_files
316336
317337
318338@pytest .mark .parametrize (
319339 ("config_file" , "config" ),
320340 [
321- ("setup.cfg" , "[metadata]\n license_files=licenses /*\n LICENSE" ),
322- ("setup.cfg" , "[metadata]\n license_files=licenses /*, LICENSE" ),
341+ ("setup.cfg" , "[metadata]\n license_files=licenses_dir /*\n LICENSE" ),
342+ ("setup.cfg" , "[metadata]\n license_files=licenses_dir /*, LICENSE" ),
323343 (
324344 "setup.py" ,
325345 SETUPPY_EXAMPLE .replace (
326- ")" , " license_files=['licenses /DUMMYFILE', 'LICENSE'])"
346+ ")" , " license_files=['licenses_dir /DUMMYFILE', 'LICENSE'])"
327347 ),
328348 ),
329349 ],
@@ -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_dir/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_dir/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