Skip to content

Commit 38c25dd

Browse files
committed
Inline the license-file collision check, drop the _record closure
Minor cleanup. The nested _record helper saved a handful of lines of duplication but read as extra structure for something already small. Write the check inline at each of the two sites (pre-PEP-639 license file, PEP-639 license-files loop). Also drop the Optional typing on distinfo_seen since no caller passes None, and update the error message to no longer reference the python.dist_info_install_dir() helper (which was removed earlier in this branch).
1 parent ec05306 commit 38c25dd

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

mesonpy/__init__.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -507,41 +507,38 @@ def _install_path(self, wheel_file: mesonpy._wheelfile.WheelFile, origin: Path,
507507
def _wheel_write_metadata(
508508
self,
509509
whl: mesonpy._wheelfile.WheelFile,
510-
distinfo_seen: Optional[Dict[str, str]] = None,
510+
distinfo_seen: Dict[str, str],
511511
) -> None:
512512
# add metadata
513513
whl.writestr(f'{self._distinfo_dir}/METADATA', bytes(self._metadata.as_rfc822()))
514514
whl.writestr(f'{self._distinfo_dir}/WHEEL', self.wheel)
515515
if self.entrypoints_txt:
516516
whl.writestr(f'{self._distinfo_dir}/entry_points.txt', self.entrypoints_txt)
517517

518-
def _record(target: str, origin: str) -> None:
519-
if distinfo_seen is None:
520-
return
521-
previous = distinfo_seen.get(target)
522-
if previous is not None:
523-
raise BuildError(
524-
f'Two files would be installed to {target!r} in the '
525-
f'wheel: {previous!r} and {origin!r}. Files placed in '
526-
f'.dist-info/ must have unique basenames within their '
527-
f'subdirectory; check your project.license-files list '
528-
f'and any python.dist_info_install_dir() uses.')
529-
distinfo_seen[target] = origin
530-
531518
# Add pre-PEP-639 license files.
532519
if isinstance(self._metadata.license, pyproject_metadata.License):
533520
license_file = self._metadata.license.file
534521
if license_file:
535522
target = f'{self._distinfo_dir}/{os.path.basename(license_file)}'
536-
_record(target, str(license_file))
523+
if target in distinfo_seen:
524+
raise BuildError(
525+
f'Two files would be installed to {target!r} in the wheel: '
526+
f'{distinfo_seen[target]!r} and {str(license_file)!r}. '
527+
f'Files placed in .dist-info/ must have unique paths.')
528+
distinfo_seen[target] = str(license_file)
537529
whl.write(license_file, target)
538530

539531
# Add PEP-639 license-files. Use ``getattr()`` for compatibility with pyproject-metadata < 0.9.0.
540532
license_files = getattr(self._metadata, 'license_files', None)
541533
if license_files:
542534
for f in license_files:
543535
target = f'{self._distinfo_dir}/licenses/{pathlib.Path(f).as_posix()}'
544-
_record(target, str(f))
536+
if target in distinfo_seen:
537+
raise BuildError(
538+
f'Two files would be installed to {target!r} in the wheel: '
539+
f'{distinfo_seen[target]!r} and {str(f)!r}. '
540+
f'Files placed in .dist-info/ must have unique paths.')
541+
distinfo_seen[target] = str(f)
545542
whl.write(f, target)
546543

547544
def build(self, directory: Path) -> pathlib.Path:

0 commit comments

Comments
 (0)