Skip to content

Commit be95b67

Browse files
committed
Account for possibility bdist_wheel is not installed
1 parent 94f6781 commit be95b67

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

setuptools_rust/setuptools_ext.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sysconfig
55
import logging
66

7-
from typing import List, Set, Tuple, Type, TypeVar, cast
7+
from typing import List, Optional, Set, Tuple, Type, TypeVar, cast
88
from functools import partial
99

1010
from setuptools.command.build_ext import build_ext
@@ -163,14 +163,20 @@ def run(self) -> None:
163163
build_rust.inplace = self.inplace
164164
build_rust.target = self.target
165165
build_rust.verbose = self.verbose
166-
167-
bdist_wheel = self.distribution.get_command_obj("bdist_wheel")
168-
plat_name = bdist_wheel.plat_name or self.plat_name
169-
build_rust.plat_name = plat_name
166+
build_rust.plat_name = self._get_wheel_plat_name() or self.plat_name
170167
build_rust.run()
171168

172169
build_ext_base_class.run(self)
173170

171+
def _get_wheel_plat_name(self) -> Optional[str]:
172+
try:
173+
bdist_wheel = self.distribution.get_command_obj("bdist_wheel")
174+
return cast(Optional[str], bdist_wheel.plat_name)
175+
except Exception:
176+
# `wheel` is not installed.
177+
options = self.distribution.get_cmdline_options().get("bdist_wheel", {})
178+
return cast(Optional[str], options.get("plat-name"))
179+
174180
dist.cmdclass["build_ext"] = build_ext_rust_extension
175181

176182
clean_base_class = dist.cmdclass.get("clean")

0 commit comments

Comments
 (0)