|
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,20 @@ 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 _map_to_wheel( |
| 116 | + sources: Dict[str, Dict[str, Any]], |
| 117 | + exclude: List[str] |
| 118 | +) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]: |
115 | 119 | """Map files to the wheel, organized by wheel installation directory.""" |
116 | 120 | wheel_files: DefaultDict[str, List[Tuple[pathlib.Path, str]]] = collections.defaultdict(list) |
117 | 121 | packages: Dict[str, str] = {} |
| 122 | + excluded = re.compile('|'.join(fnmatch.translate(x) for x in exclude)).match if exclude else lambda x: False |
118 | 123 |
|
119 | 124 | for key, group in sources.items(): |
120 | 125 | for src, target in group.items(): |
| 126 | + if excluded(target['destination']): |
| 127 | + continue |
| 128 | + |
121 | 129 | destination = pathlib.Path(target['destination']) |
122 | 130 | anchor = destination.parts[0] |
123 | 131 | dst = pathlib.Path(*destination.parts[1:]) |
@@ -581,6 +589,9 @@ def _string_or_path(value: Any, name: str) -> str: |
581 | 589 | 'args': _table({ |
582 | 590 | name: _strings for name in _MESON_ARGS_KEYS |
583 | 591 | }), |
| 592 | + 'wheel': _table({ |
| 593 | + 'exclude': _strings, |
| 594 | + }), |
584 | 595 | }) |
585 | 596 |
|
586 | 597 | table = pyproject.get('tool', {}).get('meson-python', {}) |
@@ -823,6 +834,9 @@ def __init__( |
823 | 834 | # from the package, make sure the developers acknowledge this. |
824 | 835 | self._allow_windows_shared_libs = pyproject_config.get('allow-windows-internal-shared-libs', False) |
825 | 836 |
|
| 837 | + # Files to be excluded from the wheel |
| 838 | + self._excluded_files = pyproject_config.get('wheel', {}).get('exclude', []) |
| 839 | + |
826 | 840 | def _run(self, cmd: Sequence[str]) -> None: |
827 | 841 | """Invoke a subprocess.""" |
828 | 842 | # Flush the line to ensure that the log line with the executed |
@@ -906,7 +920,7 @@ def _manifest(self) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]: |
906 | 920 | sources[key][target] = details |
907 | 921 |
|
908 | 922 | # Map Meson installation locations to wheel paths. |
909 | | - return _map_to_wheel(sources) |
| 923 | + return _map_to_wheel(sources, self._excluded_files) |
910 | 924 |
|
911 | 925 | @property |
912 | 926 | def _meson_name(self) -> str: |
|
0 commit comments