Skip to content

Commit 502141b

Browse files
authored
Merge pull request #16 from messense/feature/optional
Add optional option to RustExtension
2 parents f344fe0 + 0476c50 commit 502141b

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGES
22
=======
33

4+
0.6.2 (2017-07-31)
5+
------------------
6+
7+
- Add `optional` option to `RustExtension` #16
8+
49
0.6.1 (2017-06-30)
510
------------------
611

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ You can define rust extension with `RustExtension` class:
8080
`Binding.RustCPython` uses rust-cpython
8181
`Binding.NoBinding` uses no binding.
8282

83+
:param bool optional: if it is true, a build failure in the extension will not abort the build process,
84+
but instead simply not install the failing extension.
85+
8386
Commands
8487
--------
8588

setuptools_rust/build.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from distutils.cmd import Command
88
from distutils.errors import (
99
CompileError, DistutilsExecError, DistutilsFileError,
10-
DistutilsPlatformError)
10+
DistutilsPlatformError, DistutilsSetupError)
1111

1212
from .extension import RustExtension
1313
from .utils import cpython_feature, get_rust_version
@@ -166,10 +166,18 @@ def run(self):
166166
version = get_rust_version()
167167

168168
for ext in self.extensions:
169-
rust_version = ext.get_rust_version()
170-
if rust_version is not None and version not in rust_version:
171-
raise DistutilsPlatformError(
172-
"Rust %s does not match extension requirement %s" % (
173-
version, ext.rust_version))
174-
175-
self.build_extension(ext)
169+
try:
170+
rust_version = ext.get_rust_version()
171+
if rust_version is not None and version not in rust_version:
172+
raise DistutilsPlatformError(
173+
"Rust %s does not match extension requirement %s" % (
174+
version, ext.rust_version))
175+
176+
self.build_extension(ext)
177+
except (DistutilsSetupError, DistutilsFileError, DistutilsExecError,
178+
DistutilsPlatformError, CompileError) as e:
179+
if not ext.optional:
180+
raise
181+
else:
182+
print('Build optional Rust extension %s failed.' % ext.name)
183+
print(str(e))

setuptools_rust/extension.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,22 @@ class RustExtension:
3535
Binding.PyO3 uses PyO3
3636
Binding.RustCPython uses Rust CPython.
3737
Binding.NoBinding uses no binding.
38+
optional : bool
39+
if it is true, a build failure in the extension will not abort the build process,
40+
but instead simply not install the failing extension.
3841
"""
3942

4043
def __init__(self, name, path,
4144
args=None, features=None, rust_version=None,
42-
quiet=False, debug=None, binding=Binding.PyO3):
45+
quiet=False, debug=None, binding=Binding.PyO3,
46+
optional=False):
4347
self.name = name
4448
self.args = args
4549
self.binding = binding
4650
self.rust_version = rust_version
4751
self.quiet = quiet
4852
self.debug = debug
53+
self.optional = optional
4954

5055
if features is None:
5156
features = []

0 commit comments

Comments
 (0)