Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGES
=======

0.6.2 (2017-07-31)
------------------

- Add `optional` option to `RustExtension` #16

0.6.1 (2017-06-30)
------------------

Expand Down
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ You can define rust extension with `RustExtension` class:
`Binding.RustCPython` uses rust-cpython
`Binding.NoBinding` uses no binding.

:param bool optional: if it is true, a build failure in the extension will not abort the build process,
but instead simply not install the failing extension.

Commands
--------

Expand Down
24 changes: 16 additions & 8 deletions setuptools_rust/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from distutils.cmd import Command
from distutils.errors import (
CompileError, DistutilsExecError, DistutilsFileError,
DistutilsPlatformError)
DistutilsPlatformError, DistutilsSetupError)

from .extension import RustExtension
from .utils import cpython_feature, get_rust_version
Expand Down Expand Up @@ -166,10 +166,18 @@ def run(self):
version = get_rust_version()

for ext in self.extensions:
rust_version = ext.get_rust_version()
if rust_version is not None and version not in rust_version:
raise DistutilsPlatformError(
"Rust %s does not match extension requirement %s" % (
version, ext.rust_version))

self.build_extension(ext)
try:
rust_version = ext.get_rust_version()
if rust_version is not None and version not in rust_version:
raise DistutilsPlatformError(
"Rust %s does not match extension requirement %s" % (
version, ext.rust_version))

self.build_extension(ext)
except (DistutilsSetupError, DistutilsFileError, DistutilsExecError,
DistutilsPlatformError, CompileError) as e:
if not ext.optional:
raise
else:
print('Build optional Rust extension %s failed.' % ext.name)
print(str(e))
7 changes: 6 additions & 1 deletion setuptools_rust/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,22 @@ class RustExtension:
Binding.PyO3 uses PyO3
Binding.RustCPython uses Rust CPython.
Binding.NoBinding uses no binding.
optional : bool
if it is true, a build failure in the extension will not abort the build process,
but instead simply not install the failing extension.
"""

def __init__(self, name, path,
args=None, features=None, rust_version=None,
quiet=False, debug=None, binding=Binding.PyO3):
quiet=False, debug=None, binding=Binding.PyO3,
optional=False):
self.name = name
self.args = args
self.binding = binding
self.rust_version = rust_version
self.quiet = quiet
self.debug = debug
self.optional = optional

if features is None:
features = []
Expand Down