| 
16 | 16 | import contextlib  | 
17 | 17 | import copy  | 
18 | 18 | import difflib  | 
 | 19 | +import fnmatch  | 
19 | 20 | import functools  | 
20 | 21 | import importlib.machinery  | 
21 | 22 | import io  | 
@@ -111,13 +112,27 @@ class InvalidLicenseExpression(Exception):  # type: ignore[no-redef]  | 
111 | 112 | }  | 
112 | 113 | 
 
  | 
113 | 114 | 
 
  | 
114 |  | -def _map_to_wheel(sources: Dict[str, Dict[str, Any]]) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]:  | 
 | 115 | +def _compile_patterns(patterns: List[str]) -> Callable[[str], bool]:  | 
 | 116 | +    if not patterns:  | 
 | 117 | +        return lambda x: False  | 
 | 118 | +    func = re.compile('|'.join(fnmatch.translate(os.path.normpath(p)) for p in patterns)).match  | 
 | 119 | +    return typing.cast(Callable[[str], bool], func)  | 
 | 120 | + | 
 | 121 | + | 
 | 122 | +def _map_to_wheel(  | 
 | 123 | +    sources: Dict[str, Dict[str, Any]],  | 
 | 124 | +    exclude: List[str]  | 
 | 125 | +) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]:  | 
115 | 126 |     """Map files to the wheel, organized by wheel installation directory."""  | 
116 | 127 |     wheel_files: DefaultDict[str, List[Tuple[pathlib.Path, str]]] = collections.defaultdict(list)  | 
117 | 128 |     packages: Dict[str, str] = {}  | 
 | 129 | +    excluded = _compile_patterns(exclude)  | 
118 | 130 | 
 
  | 
119 | 131 |     for key, group in sources.items():  | 
120 | 132 |         for src, target in group.items():  | 
 | 133 | +            if excluded(target['destination']):  | 
 | 134 | +                continue  | 
 | 135 | + | 
121 | 136 |             destination = pathlib.Path(target['destination'])  | 
122 | 137 |             anchor = destination.parts[0]  | 
123 | 138 |             dst = pathlib.Path(*destination.parts[1:])  | 
@@ -581,6 +596,9 @@ def _string_or_path(value: Any, name: str) -> str:  | 
581 | 596 |         'args': _table({  | 
582 | 597 |             name: _strings for name in _MESON_ARGS_KEYS  | 
583 | 598 |         }),  | 
 | 599 | +        'wheel': _table({  | 
 | 600 | +            'exclude': _strings,  | 
 | 601 | +        }),  | 
584 | 602 |     })  | 
585 | 603 | 
 
  | 
586 | 604 |     table = pyproject.get('tool', {}).get('meson-python', {})  | 
@@ -823,6 +841,9 @@ def __init__(  | 
823 | 841 |         # from the package, make sure the developers acknowledge this.  | 
824 | 842 |         self._allow_windows_shared_libs = pyproject_config.get('allow-windows-internal-shared-libs', False)  | 
825 | 843 | 
 
  | 
 | 844 | +        # Files to be excluded from the wheel  | 
 | 845 | +        self._excluded_files = pyproject_config.get('wheel', {}).get('exclude', [])  | 
 | 846 | + | 
826 | 847 |     def _run(self, cmd: Sequence[str]) -> None:  | 
827 | 848 |         """Invoke a subprocess."""  | 
828 | 849 |         # Flush the line to ensure that the log line with the executed  | 
@@ -906,7 +927,7 @@ def _manifest(self) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]:  | 
906 | 927 |                 sources[key][target] = details  | 
907 | 928 | 
 
  | 
908 | 929 |         # Map Meson installation locations to wheel paths.  | 
909 |  | -        return _map_to_wheel(sources)  | 
 | 930 | +        return _map_to_wheel(sources, self._excluded_files)  | 
910 | 931 | 
 
  | 
911 | 932 |     @property  | 
912 | 933 |     def _meson_name(self) -> str:  | 
 | 
0 commit comments