@@ -128,6 +128,44 @@ def _init_colors() -> Dict[str, str]:
128
128
assert all (re .match (_EXTENSION_SUFFIX_REGEX , x ) for x in _EXTENSION_SUFFIXES )
129
129
130
130
131
+ # Maps wheel installation paths to Meson installation path placeholders.
132
+ # See https://docs.python.org/3/library/sysconfig.html#installation-paths
133
+ _SCHEME_MAP = {
134
+ 'scripts' : ('{bindir}' ,),
135
+ 'purelib' : ('{py_purelib}' ,),
136
+ 'platlib' : ('{py_platlib}' , '{moduledir_shared}' ),
137
+ 'headers' : ('{includedir}' ,),
138
+ 'data' : ('{datadir}' ,),
139
+ # our custom location
140
+ 'mesonpy-libs' : ('{libdir}' , '{libdir_shared}' )
141
+ }
142
+
143
+
144
+ def _map_meson_destination (destination : str ) -> Tuple [Optional [str ], pathlib .Path ]:
145
+ """Map a Meson installation path to a wheel installation location.
146
+
147
+ Return a (wheel path identifier, subpath inside the wheel path) tuple.
148
+
149
+ """
150
+ parts = pathlib .Path (destination ).parts
151
+ for folder , placeholders in _SCHEME_MAP .items ():
152
+ if parts [0 ] in placeholders :
153
+ return folder , pathlib .Path (* parts [1 :])
154
+ warnings .warn (f'Could not map installation path to an equivalent wheel directory: { destination !r} ' )
155
+ return None , pathlib .Path (destination )
156
+
157
+
158
+ def _map_to_wheel (sources : Dict [str , Dict [str , Any ]]) -> DefaultDict [str , List [Tuple [pathlib .Path , str ]]]:
159
+ """Map files to the wheel, organized by wheel installation directrory."""
160
+ wheel_files = collections .defaultdict (list )
161
+ for group in sources .values ():
162
+ for src , target in group .items ():
163
+ directory , path = _map_meson_destination (target ['destination' ])
164
+ if directory is not None :
165
+ wheel_files [directory ].append ((path , src ))
166
+ return wheel_files
167
+
168
+
131
169
def _showwarning (
132
170
message : Union [Warning , str ],
133
171
category : Type [Warning ],
@@ -180,40 +218,25 @@ class MesonBuilderError(Error):
180
218
class _WheelBuilder ():
181
219
"""Helper class to build wheels from projects."""
182
220
183
- # Maps wheel scheme names to Meson placeholder directories
184
- _SCHEME_MAP : ClassVar [Dict [str , Tuple [str , ...]]] = {
185
- 'scripts' : ('{bindir}' ,),
186
- 'purelib' : ('{py_purelib}' ,),
187
- 'platlib' : ('{py_platlib}' , '{moduledir_shared}' ),
188
- 'headers' : ('{includedir}' ,),
189
- 'data' : ('{datadir}' ,),
190
- # our custom location
191
- 'mesonpy-libs' : ('{libdir}' , '{libdir_shared}' )
192
- }
193
-
194
221
def __init__ (
195
222
self ,
196
223
project : Project ,
197
224
metadata : Optional [pyproject_metadata .StandardMetadata ],
198
225
source_dir : pathlib .Path ,
199
- install_dir : pathlib .Path ,
200
226
build_dir : pathlib .Path ,
201
227
sources : Dict [str , Dict [str , Any ]],
202
- copy_files : Dict [str , str ],
203
228
) -> None :
204
229
self ._project = project
205
230
self ._metadata = metadata
206
231
self ._source_dir = source_dir
207
- self ._install_dir = install_dir
208
232
self ._build_dir = build_dir
209
233
self ._sources = sources
210
- self ._copy_files = copy_files
211
234
212
235
self ._libs_build_dir = self ._build_dir / 'mesonpy-wheel-libs'
213
236
214
237
@cached_property
215
238
def _wheel_files (self ) -> DefaultDict [str , List [Tuple [pathlib .Path , str ]]]:
216
- return self . _map_to_wheel (self ._sources , self . _copy_files )
239
+ return _map_to_wheel (self ._sources )
217
240
218
241
@property
219
242
def _has_internal_libs (self ) -> bool :
@@ -396,38 +419,6 @@ def _is_native(self, file: Union[str, pathlib.Path]) -> bool:
396
419
return True
397
420
return False
398
421
399
- def _map_from_scheme_map (self , destination : str ) -> Optional [Tuple [str , pathlib .Path ]]:
400
- """Extracts scheme and relative destination from installation paths."""
401
- parts = pathlib .Path (destination ).parts
402
- for scheme , placeholders in self ._SCHEME_MAP .items ():
403
- if parts [0 ] in placeholders :
404
- return scheme , pathlib .Path (* parts [1 :])
405
- return None
406
-
407
- def _map_to_wheel (
408
- self ,
409
- sources : Dict [str , Dict [str , Any ]],
410
- copy_files : Dict [str , str ],
411
- ) -> DefaultDict [str , List [Tuple [pathlib .Path , str ]]]:
412
- """Map files to the wheel, organized by scheme."""
413
- wheel_files = collections .defaultdict (list )
414
- for files in sources .values (): # entries in intro-install_plan.json
415
- for file , details in files .items (): # install path -> {destination, tag}
416
- # try mapping to wheel location
417
- meson_destination = details ['destination' ]
418
- install_details = self ._map_from_scheme_map (meson_destination )
419
- if install_details :
420
- scheme , destination = install_details
421
- wheel_files [scheme ].append ((destination , file ))
422
- continue
423
- # not found
424
- warnings .warn (
425
- 'File could not be mapped to an equivalent wheel directory: '
426
- '{} ({})' .format (copy_files [file ], meson_destination )
427
- )
428
-
429
- return wheel_files
430
-
431
422
def _install_path (
432
423
self ,
433
424
wheel_file : mesonpy ._wheelfile .WheelFile ,
@@ -522,7 +513,7 @@ def build(self, directory: Path) -> pathlib.Path:
522
513
self ._install_path (whl , counter , origin , destination )
523
514
524
515
# install the other schemes
525
- for scheme in self . _SCHEME_MAP :
516
+ for scheme in _SCHEME_MAP :
526
517
if scheme in (root_scheme , 'mesonpy-libs' ):
527
518
continue
528
519
for destination , origin in self ._wheel_files [scheme ]:
@@ -580,7 +571,7 @@ def build_editable(self, directory: Path, verbose: bool = False) -> pathlib.Path
580
571
)
581
572
582
573
# install non-code schemes
583
- for scheme in self . _SCHEME_MAP :
574
+ for scheme in _SCHEME_MAP :
584
575
if scheme in ('purelib' , 'platlib' , 'mesonpy-libs' ):
585
576
continue
586
577
for destination , origin in self ._wheel_files [scheme ]:
@@ -831,10 +822,8 @@ def _wheel_builder(self) -> _WheelBuilder:
831
822
self ,
832
823
self ._metadata ,
833
824
self ._source_dir ,
834
- self ._install_dir ,
835
825
self ._build_dir ,
836
826
self ._install_plan ,
837
- self ._copy_files ,
838
827
)
839
828
840
829
def build_commands (self , install_dir : Optional [pathlib .Path ] = None ) -> Sequence [Sequence [str ]]:
@@ -902,17 +891,6 @@ def _install_plan(self) -> Dict[str, Dict[str, Dict[str, str]]]:
902
891
903
892
return install_plan
904
893
905
- @property
906
- def _copy_files (self ) -> Dict [str , str ]:
907
- """Files that Meson will copy on install and the target location."""
908
- copy_files = {}
909
- for origin , destination in self ._info ('intro-installed' ).items ():
910
- destination_path = pathlib .Path (destination ).absolute ()
911
- copy_files [origin ] = os .fspath (
912
- self ._install_dir / destination_path .relative_to (destination_path .anchor )
913
- )
914
- return copy_files
915
-
916
894
@property
917
895
def _meson_name (self ) -> str :
918
896
"""Name in meson.build."""
0 commit comments