Skip to content

Commit 3b06753

Browse files
authored
Merge pull request #17 from messense/feature/optional-check
Refine optional support
2 parents 14864c2 + 33c09b2 commit 3b06753

File tree

3 files changed

+60
-30
lines changed

3 files changed

+60
-30
lines changed

CHANGES.rst

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

4+
0.6.4
5+
-------
6+
7+
- `check` command respects `optional` option
8+
- Don't fail when Rust isn't installed while all extensions are optional
9+
410
0.6.3 (2017-07-31)
511
------------------
612

setuptools_rust/build.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,15 @@ def run(self):
163163
if not self.extensions:
164164
return
165165

166-
version = get_rust_version()
166+
all_optional = all(ext.optional for ext in self.extensions)
167+
try:
168+
version = get_rust_version()
169+
except DistutilsPlatformError as e:
170+
if not all_optional:
171+
raise
172+
else:
173+
print(str(e))
174+
return
167175

168176
for ext in self.extensions:
169177
try:

setuptools_rust/check.py

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import subprocess
55
from distutils.cmd import Command
66
from distutils.errors import (
7-
CompileError, DistutilsFileError, DistutilsExecError)
7+
CompileError, DistutilsFileError, DistutilsExecError,
8+
DistutilsPlatformError)
89

910
import semantic_version
1011

@@ -30,7 +31,15 @@ def run(self):
3031
if not self.extensions:
3132
return
3233

33-
version = get_rust_version()
34+
all_optional = all(ext.optional for ext in self.extensions)
35+
try:
36+
version = get_rust_version()
37+
except DistutilsPlatformError as e:
38+
if not all_optional:
39+
raise
40+
else:
41+
print(str(e))
42+
return
3443
if version not in MIN_VERSION:
3544
print('Rust version mismatch: required rust%s got rust%s' % (
3645
MIN_VERSION, version))
@@ -50,31 +59,38 @@ def run(self):
5059
})
5160

5261
for ext in self.extensions:
53-
if not os.path.exists(ext.path):
54-
raise DistutilsFileError(
55-
"Can not file rust extension project file: %s" % ext.path)
56-
57-
features = set(ext.features)
58-
features.update(cpython_feature(binding=ext.binding))
59-
60-
# check cargo command
61-
feature_args = [
62-
"--features", " ".join(features)] if features else []
63-
args = (["cargo", "check", "--lib", "--manifest-path", ext.path]
64-
+ feature_args
65-
+ list(ext.args or []))
66-
67-
# Execute cargo command
6862
try:
69-
subprocess.check_output(args)
70-
except subprocess.CalledProcessError as e:
71-
raise CompileError(
72-
"cargo failed with code: %d\n%s" % (
73-
e.returncode, e.output.decode("utf-8")))
74-
except OSError:
75-
raise DistutilsExecError(
76-
"Unable to execute 'cargo' - this package "
77-
"requires rust to be installed and "
78-
"cargo to be on the PATH")
79-
else:
80-
print("Extension '%s' checked" % ext.name)
63+
if not os.path.exists(ext.path):
64+
raise DistutilsFileError(
65+
"Can not file rust extension project file: %s" % ext.path)
66+
67+
features = set(ext.features)
68+
features.update(cpython_feature(binding=ext.binding))
69+
70+
# check cargo command
71+
feature_args = [
72+
"--features", " ".join(features)] if features else []
73+
args = (["cargo", "check", "--lib", "--manifest-path", ext.path]
74+
+ feature_args
75+
+ list(ext.args or []))
76+
77+
# Execute cargo command
78+
try:
79+
subprocess.check_output(args)
80+
except subprocess.CalledProcessError as e:
81+
raise CompileError(
82+
"cargo failed with code: %d\n%s" % (
83+
e.returncode, e.output.decode("utf-8")))
84+
except OSError:
85+
raise DistutilsExecError(
86+
"Unable to execute 'cargo' - this package "
87+
"requires rust to be installed and "
88+
"cargo to be on the PATH")
89+
else:
90+
print("Extension '%s' checked" % ext.name)
91+
except (DistutilsFileError, DistutilsExecError, CompileError) as e:
92+
if not ext.optional:
93+
raise
94+
else:
95+
print('Check optional Rust extension %s failed.' % ext.name)
96+
print(str(e))

0 commit comments

Comments
 (0)