Skip to content

Commit

Permalink
pw_build: Error out when copying two .whl with the same name
Browse files Browse the repository at this point in the history
collect_wheels.py is used by the "pw_python_wheels" template to collect
all the .whl files from a series of directories and copy them to a
single output directory. The source directories could have .whl files
with the same name in different directories, but there can only be one
of those in the output directory.

This patch makes collect_wheels.py fail when trying to copy two files
with the same name.

Change-Id: Ia0464711c86257fe8bca2195186473426b1754f2
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/110651
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Alex Deymo <deymo@google.com>
  • Loading branch information
deymo authored and CQ Bot Account committed Sep 29, 2022
1 parent d3044a8 commit 339dadf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pw_build/py/pw_build/collect_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pathlib import Path
import shutil
import sys
from typing import Dict

_LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -45,12 +46,20 @@ def copy_wheels(prefix, suffix_file, out_dir):
if not out_dir.exists():
out_dir.mkdir()

copied_files: Dict[str, Path] = dict()
for suffix in suffix_file.readlines():
path = prefix / suffix.strip()
_LOG.debug('Searching for wheels in %s', path)
if path == out_dir:
continue
for wheel in path.glob('**/*.whl'):
if wheel.name in copied_files:
_LOG.error('Attempting to override %s with %s',
copied_files[wheel.name], wheel)
raise FileExistsError(
f'{wheel.name} conflict: '
f'{copied_files[wheel.name]} and {wheel}')
copied_files[wheel.name] = wheel
_LOG.debug('Copying %s to %s', wheel, out_dir)
shutil.copy(wheel, out_dir)

Expand Down

0 comments on commit 339dadf

Please sign in to comment.