|
21 | 21 |
|
22 | 22 | import pkg_resources |
23 | 23 | from semantic_version import Version |
| 24 | +from setuptools import Distribution |
24 | 25 | from setuptools.command.build import build as CommandBuild |
25 | 26 | from setuptools.command.build_ext import build_ext as CommandBuildExt |
26 | 27 | from setuptools.command.build_ext import get_abi3_suffix |
|
39 | 40 | logger = logging.getLogger(__name__) |
40 | 41 |
|
41 | 42 |
|
| 43 | +try: |
| 44 | + from wheel.bdist_wheel import bdist_wheel as CommandBdistWheel |
| 45 | +except ImportError: # wheel installation might be deferred in PEP 517 |
| 46 | + from setuptools import Command as CommandBdistWheel |
| 47 | + |
| 48 | + |
42 | 49 | def _check_cargo_supports_crate_type_option() -> bool: |
43 | 50 | version = get_rust_version() |
44 | 51 |
|
@@ -447,17 +454,13 @@ def get_dylib_ext_path(self, ext: RustExtension, target_fname: str) -> str: |
447 | 454 | return ext_path |
448 | 455 |
|
449 | 456 | def _py_limited_api(self) -> _PyLimitedApi: |
450 | | - bdist_wheel = self.distribution.get_command_obj("bdist_wheel", create=False) |
| 457 | + bdist_wheel = _get_bdist_wheel_cmd(self.distribution, create=False) |
451 | 458 |
|
452 | 459 | if bdist_wheel is None: |
453 | 460 | # wheel package is not installed, not building a limited-api wheel |
454 | 461 | return False |
455 | 462 | else: |
456 | | - from wheel.bdist_wheel import bdist_wheel as CommandBdistWheel |
457 | | - |
458 | | - bdist_wheel_command = cast(CommandBdistWheel, bdist_wheel) # type: ignore[no-any-unimported] |
459 | | - bdist_wheel_command.ensure_finalized() |
460 | | - return cast(_PyLimitedApi, bdist_wheel_command.py_limited_api) |
| 463 | + return cast(_PyLimitedApi, bdist_wheel.py_limited_api) |
461 | 464 |
|
462 | 465 | def _detect_rust_target( |
463 | 466 | self, forced_target_triple: Optional[str] = None |
@@ -752,3 +755,15 @@ def _replace_cross_target_dir(path: str, ext: RustExtension, *, quiet: bool) -> |
752 | 755 | cross_target_dir = ext._metadata(cargo="cross", quiet=quiet)["target_directory"] |
753 | 756 | local_target_dir = ext._metadata(cargo="cargo", quiet=quiet)["target_directory"] |
754 | 757 | return path.replace(cross_target_dir, local_target_dir) |
| 758 | + |
| 759 | + |
| 760 | +def _get_bdist_wheel_cmd( # type: ignore[no-any-unimported] |
| 761 | + dist: Distribution, |
| 762 | + create: bool = True |
| 763 | +) -> Optional[CommandBdistWheel]: |
| 764 | + try: |
| 765 | + cmd_obj = dist.get_command_obj("bdist_wheel", create=create) |
| 766 | + cmd_obj.ensure_finalized() |
| 767 | + return cast(CommandBdistWheel, cmd_obj) # type: ignore [no-any-unimported] |
| 768 | + except Exception: |
| 769 | + return None |
0 commit comments