|
15 | 15 | import warnings
|
16 | 16 | from collections import OrderedDict
|
17 | 17 | from email.generator import BytesGenerator, Generator
|
| 18 | +from glob import iglob |
18 | 19 | from io import BytesIO
|
19 | 20 | from shutil import rmtree
|
20 | 21 | from zipfile import ZIP_DEFLATED, ZIP_STORED
|
|
31 | 32 |
|
32 | 33 | safe_name = pkg_resources.safe_name
|
33 | 34 | safe_version = pkg_resources.safe_version
|
| 35 | +setuptools_major_version = int( |
| 36 | + pkg_resources.get_distribution("setuptools").version.split(".")[0] |
| 37 | +) |
34 | 38 |
|
35 | 39 | PY_LIMITED_API_PATTERN = r"cp3\d"
|
36 | 40 |
|
@@ -430,8 +434,47 @@ def _ensure_relative(self, path):
|
430 | 434 |
|
431 | 435 | @property
|
432 | 436 | def license_paths(self):
|
433 |
| - metadata = self.distribution.metadata |
434 |
| - return sorted(metadata.license_files or []) |
| 437 | + if setuptools_major_version >= 57: |
| 438 | + # Setuptools has resolved any patterns to actual file names |
| 439 | + return self.distribution.metadata.license_files or () |
| 440 | + |
| 441 | + files = set() |
| 442 | + metadata = self.distribution.get_option_dict("metadata") |
| 443 | + if setuptools_major_version >= 42: |
| 444 | + # Setuptools recognizes the license_files option but does not do globbing |
| 445 | + patterns = self.distribution.metadata.license_files |
| 446 | + else: |
| 447 | + # Prior to those, wheel is entirely responsible for handling license files |
| 448 | + if "license_files" in metadata: |
| 449 | + patterns = metadata["license_files"][1].split() |
| 450 | + else: |
| 451 | + patterns = () |
| 452 | + |
| 453 | + if "license_file" in metadata: |
| 454 | + warnings.warn( |
| 455 | + 'The "license_file" option is deprecated. Use "license_files" instead.', |
| 456 | + DeprecationWarning, |
| 457 | + ) |
| 458 | + files.add(metadata["license_file"][1]) |
| 459 | + |
| 460 | + if not files and not patterns and not isinstance(patterns, list): |
| 461 | + patterns = ("LICEN[CS]E*", "COPYING*", "NOTICE*", "AUTHORS*") |
| 462 | + |
| 463 | + for pattern in patterns: |
| 464 | + for path in iglob(pattern): |
| 465 | + if path.endswith("~"): |
| 466 | + log.debug( |
| 467 | + f'ignoring license file "{path}" as it looks like a backup' |
| 468 | + ) |
| 469 | + continue |
| 470 | + |
| 471 | + if path not in files and os.path.isfile(path): |
| 472 | + log.info( |
| 473 | + f'adding license file "{path}" (matched pattern "{pattern}")' |
| 474 | + ) |
| 475 | + files.add(path) |
| 476 | + |
| 477 | + return files |
435 | 478 |
|
436 | 479 | def egg2dist(self, egginfo_path, distinfo_path):
|
437 | 480 | """Convert an .egg-info directory into a .dist-info directory"""
|
|
0 commit comments