Skip to content

Commit a4648e8

Browse files
authored
Merge pull request #203 from davidhewitt/rust-extensions-types
fix: improve handling of invalid rust_extensions values
2 parents 258e198 + 5a81b2d commit a4648e8

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.1.2 (UNRELEASED)
44
### Changed
55
- Removed dependency on `tomli` to simplify installation.
6+
- Improve error messages on invalid inputs to `rust_extensions` keyword. [#203](https://github.com/PyO3/setuptools-rust/pull/203)
67

78
## 1.1.1 (2021-12-01)
89
### Fixed

setuptools_rust/command.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from abc import ABC, abstractmethod
2+
from distutils import log
23
from distutils.cmd import Command
34
from distutils.errors import DistutilsPlatformError
4-
from typing import List
5+
from typing import List, Optional
56

67
from setuptools.dist import Distribution
78

@@ -21,14 +22,34 @@ def initialize_options(self) -> None:
2122
self.extensions: List[RustExtension] = []
2223

2324
def finalize_options(self) -> None:
24-
self.extensions = [
25-
ext
26-
for ext in self.distribution.rust_extensions # type: ignore[attr-defined]
27-
if isinstance(ext, RustExtension)
28-
]
25+
extensions: Optional[List[RustExtension]] = getattr(
26+
self.distribution, "rust_extensions", None
27+
)
28+
if extensions is None:
29+
# extensions is None if the setup.py file did not contain
30+
# rust_extensions keyword; just no-op if this is the case.
31+
return
32+
33+
if not isinstance(extensions, list):
34+
ty = type(extensions)
35+
raise ValueError(
36+
"expected list of RustExtension objects for rust_extensions "
37+
f"argument to setup(), got `{ty}`"
38+
)
39+
for (i, extension) in enumerate(extensions):
40+
41+
if not isinstance(extension, RustExtension):
42+
ty = type(extension)
43+
raise ValueError(
44+
"expected RustExtension object for rust_extensions "
45+
f"argument to setup(), got `{ty}` at position {i}"
46+
)
47+
# Extensions have been verified to be at the correct type
48+
self.extensions = extensions
2949

3050
def run(self) -> None:
3151
if not self.extensions:
52+
log.info("%s: no rust_extensions defined", self.get_command_name())
3253
return
3354

3455
all_optional = all(ext.optional for ext in self.extensions)

0 commit comments

Comments
 (0)