Skip to content

Commit 4a4b54b

Browse files
committed
ENH: remove fallback needed only with now unsupported Meson versions
1 parent eadd75b commit 4a4b54b

File tree

2 files changed

+1
-107
lines changed

2 files changed

+1
-107
lines changed

mesonpy/__init__.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -396,58 +396,6 @@ def _is_native(self, file: Union[str, pathlib.Path]) -> bool:
396396
return True
397397
return False
398398

399-
def _warn_unsure_platlib(self, origin: pathlib.Path, destination: pathlib.Path) -> None:
400-
"""Warn if we are unsure if the file should be mapped to purelib or platlib.
401-
402-
This happens when we use heuristics to try to map a file purelib or
403-
platlib but can't differentiate between the two. In which case, we place
404-
the file in platlib to be safe and warn the user.
405-
406-
If we can detect the file is architecture dependent and indeed does not
407-
belong in purelib, we will skip the warning.
408-
"""
409-
# {moduledir_shared} is currently handled in heuristics due to a Meson bug,
410-
# but we know that files that go there are supposed to go to platlib.
411-
if self._is_native(origin):
412-
# The file is architecture dependent and does not belong in puredir,
413-
# so the warning is skipped.
414-
return
415-
warnings.warn(
416-
'Could not tell if file was meant for purelib or platlib, '
417-
f'so it was mapped to platlib: {origin} ({destination})',
418-
stacklevel=2,
419-
)
420-
421-
def _map_from_heuristics(self, origin: pathlib.Path, destination: pathlib.Path) -> Optional[Tuple[str, pathlib.Path]]:
422-
"""Extracts scheme and relative destination with heuristics based on the
423-
origin file and the Meson destination path.
424-
"""
425-
warnings.warn('Using heuristics to map files to wheel, this may result in incorrect locations')
426-
sys_paths = mesonpy._introspection.SYSCONFIG_PATHS
427-
# Try to map to Debian dist-packages
428-
if mesonpy._introspection.DEBIAN_PYTHON:
429-
search_path = origin
430-
while search_path != search_path.parent:
431-
search_path = search_path.parent
432-
if search_path.name == 'dist-packages' and search_path.parent.parent.name == 'lib':
433-
calculated_path = origin.relative_to(search_path)
434-
warnings.warn(f'File matched Debian heuristic ({calculated_path}): {origin} ({destination})')
435-
self._warn_unsure_platlib(origin, destination)
436-
return 'platlib', calculated_path
437-
# Try to map to the interpreter purelib or platlib
438-
for scheme in ('purelib', 'platlib'):
439-
# try to match the install path on the system to one of the known schemes
440-
scheme_path = pathlib.Path(sys_paths[scheme]).absolute()
441-
destdir_scheme_path = self._install_dir / scheme_path.relative_to(scheme_path.anchor)
442-
try:
443-
wheel_path = pathlib.Path(origin).relative_to(destdir_scheme_path)
444-
except ValueError:
445-
continue
446-
if sys_paths['purelib'] == sys_paths['platlib']:
447-
self._warn_unsure_platlib(origin, destination)
448-
return 'platlib', wheel_path
449-
return None # no match was found
450-
451399
def _map_from_scheme_map(self, destination: str) -> Optional[Tuple[str, pathlib.Path]]:
452400
"""Extracts scheme and relative destination from Meson paths.
453401
@@ -475,15 +423,7 @@ def _map_to_wheel(
475423
for file, details in files.items(): # install path -> {destination, tag}
476424
# try mapping to wheel location
477425
meson_destination = details['destination']
478-
install_details = (
479-
# using scheme map
480-
self._map_from_scheme_map(meson_destination)
481-
# using heuristics
482-
or self._map_from_heuristics(
483-
pathlib.Path(copy_files[file]),
484-
pathlib.Path(meson_destination),
485-
)
486-
)
426+
install_details = self._map_from_scheme_map(meson_destination)
487427
if install_details:
488428
scheme, destination = install_details
489429
wheel_files[scheme].append((destination, file))

mesonpy/_introspection.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,21 @@
77
import sys
88
import sysconfig
99
import typing
10-
import warnings
1110

1211

1312
if typing.TYPE_CHECKING: # pragma: no cover
1413
from mesonpy._compat import Mapping
1514

1615

17-
def debian_python() -> bool:
18-
"""Check if we are running on Debian-patched Python."""
19-
if sys.version_info >= (3, 10):
20-
return 'deb_system' in sysconfig.get_scheme_names()
21-
try:
22-
import distutils
23-
try:
24-
import distutils.command.install
25-
except ModuleNotFoundError as exc:
26-
raise ModuleNotFoundError('Unable to import distutils, please install python3-distutils') from exc
27-
return 'deb_system' in distutils.command.install.INSTALL_SCHEMES
28-
except ModuleNotFoundError:
29-
return False
30-
31-
32-
DEBIAN_PYTHON = debian_python()
33-
34-
35-
def debian_distutils_paths() -> Mapping[str, str]:
36-
# https://ffy00.github.io/blog/02-python-debian-and-the-install-locations/
37-
assert sys.version_info < (3, 12) and DEBIAN_PYTHON
38-
39-
with warnings.catch_warnings():
40-
warnings.filterwarnings('ignore', category=DeprecationWarning)
41-
import distutils.dist
42-
43-
distribution = distutils.dist.Distribution()
44-
install_cmd = distribution.get_command_obj('install')
45-
install_cmd.install_layout = 'deb' # type: ignore[union-attr]
46-
install_cmd.finalize_options() # type: ignore[union-attr]
47-
48-
return {
49-
'data': install_cmd.install_data, # type: ignore[union-attr]
50-
'platlib': install_cmd.install_platlib, # type: ignore[union-attr]
51-
'purelib': install_cmd.install_purelib, # type: ignore[union-attr]
52-
'scripts': install_cmd.install_scripts, # type: ignore[union-attr]
53-
}
54-
55-
5616
def sysconfig_paths() -> Mapping[str, str]:
5717
sys_vars = sysconfig.get_config_vars().copy()
5818
sys_vars['base'] = sys_vars['platbase'] = sys.base_prefix
59-
if DEBIAN_PYTHON:
60-
if sys.version_info >= (3, 10, 3):
61-
return sysconfig.get_paths('deb_system', vars=sys_vars)
62-
else:
63-
return debian_distutils_paths()
6419
return sysconfig.get_paths(vars=sys_vars)
6520

6621

6722
SYSCONFIG_PATHS = sysconfig_paths()
6823

6924

7025
__all__ = [
71-
'DEBIAN_PYTHON',
7226
'SYSCONFIG_PATHS',
7327
]

0 commit comments

Comments
 (0)