Skip to content

Commit 5568d03

Browse files
committed
EHN: add tool.meson-python.wheel.exclude setting
1 parent 1e69e7a commit 5568d03

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

docs/reference/pyproject-settings.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ use them and examples.
6363

6464
Extra arguments to be passed to the ``meson install`` command.
6565

66+
.. option:: tool.meson-python.wheel.exclude
67+
68+
List of glob patterns matching paths of files that must be excluded from
69+
the Python wheel. The accepted glob patterns are the ones implemented by
70+
the Python :mod:`fnmatch` with case sensitive matching. The paths to be
71+
matched are as they appear in the Meson introspection data, namely they are
72+
rooted in one of the Meson install locations: ``{bindir}``, ``{datadir}``,
73+
``{includedir}``, ``{libdir_shared}``, ``{libdir_static}``, et cetera.
74+
75+
This configuration setting is measure of last resort to exclude installed
76+
files from a Python wheel. It is to be used when the project includes
77+
subprojects that do not allow fine control on the installed files. Better
78+
solutions include the use of Meson install tags and excluding subprojects
79+
to be installed via :option:`tool.meson-python.args.install`.
80+
6681

6782
__ https://docs.python.org/3/c-api/stable.html?highlight=limited%20api#stable-application-binary-interface
6883
__ https://mesonbuild.com/Python-module.html#extension_module

mesonpy/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,20 @@ class InvalidLicenseExpression(Exception): # type: ignore[no-redef]
111111
}
112112

113113

114-
def _map_to_wheel(sources: Dict[str, Dict[str, Any]]) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]:
114+
def _map_to_wheel(
115+
sources: Dict[str, Dict[str, Any]],
116+
exclude: List[str]
117+
) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]:
115118
"""Map files to the wheel, organized by wheel installation directory."""
116119
wheel_files: DefaultDict[str, List[Tuple[pathlib.Path, str]]] = collections.defaultdict(list)
117120
packages: Dict[str, str] = {}
121+
excluded = re.compile('|'.join(fnmatch.translate(x) for x in exclude)).match if exclude else lambda x: False
118122

119123
for key, group in sources.items():
120124
for src, target in group.items():
125+
if excluded(target['destination']):
126+
continue
127+
121128
destination = pathlib.Path(target['destination'])
122129
anchor = destination.parts[0]
123130
dst = pathlib.Path(*destination.parts[1:])
@@ -581,6 +588,9 @@ def _string_or_path(value: Any, name: str) -> str:
581588
'args': _table({
582589
name: _strings for name in _MESON_ARGS_KEYS
583590
}),
591+
'wheel': _table({
592+
'exclude': _strings,
593+
}),
584594
})
585595

586596
table = pyproject.get('tool', {}).get('meson-python', {})
@@ -823,6 +833,9 @@ def __init__(
823833
# from the package, make sure the developers acknowledge this.
824834
self._allow_windows_shared_libs = pyproject_config.get('allow-windows-internal-shared-libs', False)
825835

836+
# Files to be excluded from the wheel
837+
self._excluded_files = pyproject_config.get('wheel', {}).get('exclude', [])
838+
826839
def _run(self, cmd: Sequence[str]) -> None:
827840
"""Invoke a subprocess."""
828841
# Flush the line to ensure that the log line with the executed
@@ -906,7 +919,7 @@ def _manifest(self) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]:
906919
sources[key][target] = details
907920

908921
# Map Meson installation locations to wheel paths.
909-
return _map_to_wheel(sources)
922+
return _map_to_wheel(sources, self._excluded_files)
910923

911924
@property
912925
def _meson_name(self) -> str:

tests/packages/subproject/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
[build-system]
66
build-backend = 'mesonpy'
77
requires = ['meson-python']
8+
9+
[tool.meson-python.wheel]
10+
exclude = ['{datadir}/data.*']
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
excluded via tool.meson-python.wheel.exclude

tests/packages/subproject/subprojects/dep/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ project('dep')
77
py = import('python').find_installation()
88

99
py.install_sources('dep.py')
10+
11+
install_data('data.txt')

0 commit comments

Comments
 (0)