Skip to content

Commit

Permalink
Merge pull request #17 from messense/feature/optional-check
Browse files Browse the repository at this point in the history
Refine optional support
  • Loading branch information
messense authored Jul 31, 2017
2 parents 14864c2 + 33c09b2 commit 3b06753
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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)
------------------

Expand Down
10 changes: 9 additions & 1 deletion setuptools_rust/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
74 changes: 45 additions & 29 deletions setuptools_rust/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
Expand All @@ -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))

0 comments on commit 3b06753

Please sign in to comment.