@@ -178,6 +178,29 @@ def _map_to_wheel(sources: Dict[str, Dict[str, Any]]) -> DefaultDict[str, List[T
178
178
return wheel_files
179
179
180
180
181
+ def _is_native (file : Path ) -> bool :
182
+ """Check if file is a native file."""
183
+
184
+ with open (file , 'rb' ) as f :
185
+ if sys .platform == 'linux' :
186
+ return f .read (4 ) == b'\x7f ELF' # ELF
187
+ elif sys .platform == 'darwin' :
188
+ return f .read (4 ) in (
189
+ b'\xfe \xed \xfa \xce ' , # 32-bit
190
+ b'\xfe \xed \xfa \xcf ' , # 64-bit
191
+ b'\xcf \xfa \xed \xfe ' , # arm64
192
+ b'\xca \xfe \xba \xbe ' , # universal / fat (same as java class so beware!)
193
+ )
194
+ elif sys .platform == 'win32' :
195
+ return f .read (2 ) == b'MZ'
196
+
197
+ # For unknown platforms, check for file extensions.
198
+ _ , ext = os .path .splitext (file )
199
+ if ext in ('.so' , '.a' , '.out' , '.exe' , '.dll' , '.dylib' , '.pyd' ):
200
+ return True
201
+ return False
202
+
203
+
181
204
def _showwarning (
182
205
message : Union [Warning , str ],
183
206
category : Type [Warning ],
@@ -276,6 +299,16 @@ def _has_extension_modules(self) -> bool:
276
299
# Assume that all code installed in {platlib} is Python ABI dependent.
277
300
return bool (self ._manifest .get ('platlib' ))
278
301
302
+ @cached_property
303
+ def _pure (self ) -> bool :
304
+ """Whether the wheel is architecture independent"""
305
+ if self ._manifest ['platlib' ]:
306
+ return False
307
+ for _ , file in self ._manifest ['scripts' ]:
308
+ if _is_native (file ):
309
+ return False
310
+ return True
311
+
279
312
@property
280
313
def normalized_name (self ) -> str :
281
314
return self ._metadata .name .replace ('-' , '_' )
@@ -288,7 +321,7 @@ def basename(self) -> str:
288
321
@property
289
322
def tag (self ) -> mesonpy ._tags .Tag :
290
323
"""Wheel tags."""
291
- if self .is_pure :
324
+ if self ._pure :
292
325
return mesonpy ._tags .Tag ('py3' , 'none' , 'any' )
293
326
if not self ._has_extension_modules :
294
327
# The wheel has platform dependent code (is not pure) but
@@ -318,20 +351,6 @@ def _license_file(self) -> Optional[pathlib.Path]:
318
351
return license_ .file
319
352
return None
320
353
321
- @cached_property
322
- def is_pure (self ) -> bool :
323
- """Is the wheel "pure" (architecture independent)?"""
324
- # XXX: I imagine some users might want to force the package to be
325
- # non-pure, but I think it's better that we evaluate use-cases as they
326
- # arise and make sure allowing the user to override this is indeed the
327
- # best option for the use-case.
328
- if self ._manifest ['platlib' ]:
329
- return False
330
- for _ , file in self ._manifest ['scripts' ]:
331
- if self ._is_native (file ):
332
- return False
333
- return True
334
-
335
354
@property
336
355
def wheel (self ) -> bytes :
337
356
"""Return WHEEL file for dist-info."""
@@ -341,7 +360,7 @@ def wheel(self) -> bytes:
341
360
Root-Is-Purelib: {is_purelib}
342
361
Tag: {tag}
343
362
''' ).strip ().format (
344
- is_purelib = 'true' if self .is_pure else 'false' ,
363
+ is_purelib = 'true' if self ._pure else 'false' ,
345
364
tag = self .tag ,
346
365
).encode ()
347
366
@@ -398,34 +417,11 @@ def top_level_modules(self) -> Collection[str]:
398
417
modules .add (name )
399
418
return modules
400
419
401
- def _is_native (self , file : Union [str , pathlib .Path ]) -> bool :
402
- """Check if file is a native file."""
403
- self ._project .build () # the project needs to be built for this :/
404
-
405
- with open (file , 'rb' ) as f :
406
- if sys .platform == 'linux' :
407
- return f .read (4 ) == b'\x7f ELF' # ELF
408
- elif sys .platform == 'darwin' :
409
- return f .read (4 ) in (
410
- b'\xfe \xed \xfa \xce ' , # 32-bit
411
- b'\xfe \xed \xfa \xcf ' , # 64-bit
412
- b'\xcf \xfa \xed \xfe ' , # arm64
413
- b'\xca \xfe \xba \xbe ' , # universal / fat (same as java class so beware!)
414
- )
415
- elif sys .platform == 'win32' :
416
- return f .read (2 ) == b'MZ'
417
-
418
- # For unknown platforms, check for file extensions.
419
- _ , ext = os .path .splitext (file )
420
- if ext in ('.so' , '.a' , '.out' , '.exe' , '.dll' , '.dylib' , '.pyd' ):
421
- return True
422
- return False
423
-
424
420
def _install_path (self , wheel_file : mesonpy ._wheelfile .WheelFile , origin : Path , destination : pathlib .Path ) -> None :
425
421
"""Add a file to the wheel."""
426
422
427
423
if self ._has_internal_libs :
428
- if self . _is_native (os . fspath ( origin ) ):
424
+ if _is_native (origin ):
429
425
# When an executable, libray, or Python extension module is
430
426
# dynamically linked to a library built as part of the project,
431
427
# Meson adds a library load path to it pointing to the build
@@ -463,7 +459,7 @@ def build(self, directory: Path) -> pathlib.Path:
463
459
464
460
with mesonpy ._util .cli_counter (sum (len (x ) for x in self ._manifest .values ())) as counter :
465
461
466
- root = 'purelib' if self .is_pure else 'platlib'
462
+ root = 'purelib' if self ._pure else 'platlib'
467
463
468
464
for path , entries in self ._manifest .items ():
469
465
for dst , src in entries :
@@ -843,11 +839,6 @@ def version(self) -> str:
843
839
"""Project version."""
844
840
return str (self ._metadata .version )
845
841
846
- @property
847
- def is_pure (self ) -> bool :
848
- """Is the wheel "pure" (architecture independent)?"""
849
- return bool (self ._wheel_builder .is_pure )
850
-
851
842
def sdist (self , directory : Path ) -> pathlib .Path :
852
843
"""Generates a sdist (source distribution) in the specified directory."""
853
844
# generate meson dist file
0 commit comments