Skip to content

Commit 2efa7f1

Browse files
dnicolodirgommers
authored andcommitted
MAINT: simplify _WheelBuilder.build()
1 parent ff3a687 commit 2efa7f1

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

mesonpy/__init__.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import functools
1919
import importlib.machinery
2020
import io
21-
import itertools
2221
import json
2322
import os
2423
import pathlib
@@ -506,30 +505,25 @@ def build(self, directory: Path) -> pathlib.Path:
506505
self._project.install()
507506

508507
wheel_file = pathlib.Path(directory, f'{self.name}.whl')
509-
510508
with mesonpy._wheelfile.WheelFile(wheel_file, 'w') as whl:
511509
self._wheel_write_metadata(whl)
512510

513-
with mesonpy._util.cli_counter(
514-
len(list(itertools.chain.from_iterable(self._wheel_files.values()))),
515-
) as counter:
516-
# install root scheme files
517-
root_scheme = 'purelib' if self.is_pure else 'platlib'
518-
for destination, origin in self._wheel_files[root_scheme]:
519-
self._install_path(whl, counter, origin, destination)
520-
521-
# install bundled libraries
522-
for destination, origin in self._wheel_files['mesonpy-libs']:
523-
destination = pathlib.Path(f'.{self._project.name}.mesonpy.libs', destination)
524-
self._install_path(whl, counter, origin, destination)
525-
526-
# install the other schemes
527-
for scheme in self._wheel_files.keys():
528-
if scheme in (root_scheme, 'mesonpy-libs'):
529-
continue
530-
for destination, origin in self._wheel_files[scheme]:
531-
destination = pathlib.Path(self.data_dir, scheme, destination)
532-
self._install_path(whl, counter, origin, destination)
511+
with mesonpy._util.cli_counter(sum(len(x) for x in self._wheel_files.values())) as counter:
512+
513+
root = 'purelib' if self.is_pure else 'platlib'
514+
515+
for path, entries in self._wheel_files.items():
516+
for dst, src in entries:
517+
518+
if path == root:
519+
pass
520+
elif path == 'mesonpy-libs':
521+
# custom installation path for bundled libraries
522+
dst = pathlib.Path(f'.{self._project.name}.mesonpy.libs', dst)
523+
else:
524+
dst = pathlib.Path(self.data_dir, path, dst)
525+
526+
self._install_path(whl, counter, src, dst)
533527

534528
return wheel_file
535529

0 commit comments

Comments
 (0)