Skip to content

Commit bc3c11f

Browse files
committed
Deduplicate the purelib/platlib branch check
The distinfo-reroute and same-package-split check both needed path in ('purelib', 'platlib'), done twice in back-to-back branches. Collapse into one outer check with two sub-branches so the condition is stated once.
1 parent a9b4286 commit bc3c11f

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

mesonpy/__init__.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,26 +158,22 @@ def _map_to_wheel(
158158
if path is None:
159159
raise BuildError(f'Could not map installation path to an equivalent wheel directory: {str(destination)!r}')
160160

161-
# Route <distinfo>/... staged under purelib or platlib into
162-
# the wheel's .dist-info/.
163-
if (
164-
path in ('purelib', 'platlib')
165-
and dst.parts
166-
and _canonicalize_distinfo(dst.parts[0]) == canonical_distinfo
167-
):
168-
path = 'distinfo'
169-
dst = pathlib.Path(*dst.parts[1:])
170-
elif path == 'purelib' or path == 'platlib':
171-
package = destination.parts[1]
172-
other = packages.setdefault(package, path)
173-
if other != path:
174-
this = os.fspath(pathlib.Path(path, *destination.parts[1:]))
175-
module = next(entry.dst for entry in wheel_files[other] if entry.dst.parts[0] == destination.parts[1])
176-
that = os.fspath(other / module)
177-
raise BuildError(
178-
f'The {package} package is split between {path} and {other}: '
179-
f'{this!r} and {that!r}, a "pure: false" argument may be missing in meson.build. '
180-
f'It is recommended to set it in "import(\'python\').find_installation()"')
161+
if path in ('purelib', 'platlib'):
162+
if dst.parts and _canonicalize_distinfo(dst.parts[0]) == canonical_distinfo:
163+
# Route <distinfo>/... into the wheel's .dist-info/.
164+
path = 'distinfo'
165+
dst = pathlib.Path(*dst.parts[1:])
166+
else:
167+
package = destination.parts[1]
168+
other = packages.setdefault(package, path)
169+
if other != path:
170+
this = os.fspath(pathlib.Path(path, *destination.parts[1:]))
171+
module = next(entry.dst for entry in wheel_files[other] if entry.dst.parts[0] == destination.parts[1])
172+
that = os.fspath(other / module)
173+
raise BuildError(
174+
f'The {package} package is split between {path} and {other}: '
175+
f'{this!r} and {that!r}, a "pure: false" argument may be missing in meson.build. '
176+
f'It is recommended to set it in "import(\'python\').find_installation()"')
181177

182178
if key == 'install_subdirs' or key == 'targets' and os.path.isdir(src):
183179
exclude_files = {os.path.normpath(x) for x in target.get('exclude_files', [])}

0 commit comments

Comments
 (0)