|
19 | 19 | from typing import Dict, List, NamedTuple, Optional, Set, Tuple, cast
|
20 | 20 |
|
21 | 21 | import pkg_resources
|
| 22 | +from semantic_version import Version |
| 23 | +from setuptools import Distribution |
22 | 24 | from setuptools.command.build import build as CommandBuild
|
23 | 25 | from setuptools.command.build_ext import build_ext as CommandBuildExt
|
24 | 26 | from setuptools.command.build_ext import get_abi3_suffix
|
|
36 | 38 | logger = logging.getLogger(__name__)
|
37 | 39 |
|
38 | 40 |
|
| 41 | +try: |
| 42 | + from wheel.bdist_wheel import bdist_wheel as CommandBdistWheel |
| 43 | +except ImportError: # wheel installation might be deferred in PEP 517 |
| 44 | + from setuptools import Command as CommandBdistWheel |
| 45 | + |
| 46 | + |
39 | 47 | def _check_cargo_supports_crate_type_option() -> bool:
|
40 | 48 | version = get_rust_version()
|
41 | 49 |
|
@@ -468,17 +476,13 @@ def get_dylib_ext_path(self, ext: RustExtension, target_fname: str) -> str:
|
468 | 476 | return ext_path
|
469 | 477 |
|
470 | 478 | def _py_limited_api(self) -> _PyLimitedApi:
|
471 |
| - bdist_wheel = self.distribution.get_command_obj("bdist_wheel", create=False) |
| 479 | + bdist_wheel = _get_bdist_wheel_cmd(self.distribution, create=False) |
472 | 480 |
|
473 | 481 | if bdist_wheel is None:
|
474 | 482 | # wheel package is not installed, not building a limited-api wheel
|
475 | 483 | return False
|
476 | 484 | else:
|
477 |
| - from wheel.bdist_wheel import bdist_wheel as CommandBdistWheel |
478 |
| - |
479 |
| - bdist_wheel_command = cast(CommandBdistWheel, bdist_wheel) # type: ignore[no-any-unimported] |
480 |
| - bdist_wheel_command.ensure_finalized() |
481 |
| - return cast(_PyLimitedApi, bdist_wheel_command.py_limited_api) |
| 485 | + return cast(_PyLimitedApi, bdist_wheel.py_limited_api) |
482 | 486 |
|
483 | 487 | def _detect_rust_target(
|
484 | 488 | self, forced_target_triple: Optional[str] = None
|
@@ -773,3 +777,15 @@ def _replace_cross_target_dir(path: str, ext: RustExtension, *, quiet: bool) ->
|
773 | 777 | cross_target_dir = ext._metadata(cargo="cross", quiet=quiet)["target_directory"]
|
774 | 778 | local_target_dir = ext._metadata(cargo="cargo", quiet=quiet)["target_directory"]
|
775 | 779 | return path.replace(cross_target_dir, local_target_dir)
|
| 780 | + |
| 781 | + |
| 782 | +def _get_bdist_wheel_cmd( # type: ignore[no-any-unimported] |
| 783 | + dist: Distribution, |
| 784 | + create: bool = True |
| 785 | +) -> Optional[CommandBdistWheel]: |
| 786 | + try: |
| 787 | + cmd_obj = dist.get_command_obj("bdist_wheel", create=create) |
| 788 | + cmd_obj.ensure_finalized() |
| 789 | + return cast(CommandBdistWheel, cmd_obj) # type: ignore [no-any-unimported] |
| 790 | + except Exception: |
| 791 | + return None |
0 commit comments