From 33c09b20cad6dadc7053d36b0ca15aa12bef8493 Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 31 Jul 2017 21:24:35 +0800 Subject: [PATCH] Refine optional support --- CHANGES.rst | 6 ++++ setuptools_rust/build.py | 10 +++++- setuptools_rust/check.py | 74 ++++++++++++++++++++++++---------------- 3 files changed, 60 insertions(+), 30 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 325ddb1e..15a6e44e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,12 @@ CHANGES ======= +0.6.4 +------- + +- `check` command respects `optional` option +- Don't fail when Rust isn't installed while all extensions are optional + 0.6.3 (2017-07-31) ------------------ diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index 83ac0eef..516b325e 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -163,7 +163,15 @@ def run(self): if not self.extensions: return - version = get_rust_version() + all_optional = all(ext.optional for ext in self.extensions) + try: + version = get_rust_version() + except DistutilsPlatformError as e: + if not all_optional: + raise + else: + print(str(e)) + return for ext in self.extensions: try: diff --git a/setuptools_rust/check.py b/setuptools_rust/check.py index 08e52d77..e38350fa 100644 --- a/setuptools_rust/check.py +++ b/setuptools_rust/check.py @@ -4,7 +4,8 @@ import subprocess from distutils.cmd import Command from distutils.errors import ( - CompileError, DistutilsFileError, DistutilsExecError) + CompileError, DistutilsFileError, DistutilsExecError, + DistutilsPlatformError) import semantic_version @@ -30,7 +31,15 @@ def run(self): if not self.extensions: return - version = get_rust_version() + all_optional = all(ext.optional for ext in self.extensions) + try: + version = get_rust_version() + except DistutilsPlatformError as e: + if not all_optional: + raise + else: + print(str(e)) + return if version not in MIN_VERSION: print('Rust version mismatch: required rust%s got rust%s' % ( MIN_VERSION, version)) @@ -50,31 +59,38 @@ def run(self): }) for ext in self.extensions: - if not os.path.exists(ext.path): - raise DistutilsFileError( - "Can not file rust extension project file: %s" % ext.path) - - features = set(ext.features) - features.update(cpython_feature(binding=ext.binding)) - - # check cargo command - feature_args = [ - "--features", " ".join(features)] if features else [] - args = (["cargo", "check", "--lib", "--manifest-path", ext.path] - + feature_args - + list(ext.args or [])) - - # Execute cargo command try: - subprocess.check_output(args) - except subprocess.CalledProcessError as e: - raise CompileError( - "cargo failed with code: %d\n%s" % ( - e.returncode, e.output.decode("utf-8"))) - except OSError: - raise DistutilsExecError( - "Unable to execute 'cargo' - this package " - "requires rust to be installed and " - "cargo to be on the PATH") - else: - print("Extension '%s' checked" % ext.name) + if not os.path.exists(ext.path): + raise DistutilsFileError( + "Can not file rust extension project file: %s" % ext.path) + + features = set(ext.features) + features.update(cpython_feature(binding=ext.binding)) + + # check cargo command + feature_args = [ + "--features", " ".join(features)] if features else [] + args = (["cargo", "check", "--lib", "--manifest-path", ext.path] + + feature_args + + list(ext.args or [])) + + # Execute cargo command + try: + subprocess.check_output(args) + except subprocess.CalledProcessError as e: + raise CompileError( + "cargo failed with code: %d\n%s" % ( + e.returncode, e.output.decode("utf-8"))) + except OSError: + raise DistutilsExecError( + "Unable to execute 'cargo' - this package " + "requires rust to be installed and " + "cargo to be on the PATH") + else: + print("Extension '%s' checked" % ext.name) + except (DistutilsFileError, DistutilsExecError, CompileError) as e: + if not ext.optional: + raise + else: + print('Check optional Rust extension %s failed.' % ext.name) + print(str(e))