44import subprocess
55from distutils .cmd import Command
66from distutils .errors import (
7- CompileError , DistutilsFileError , DistutilsExecError )
7+ CompileError , DistutilsFileError , DistutilsExecError ,
8+ DistutilsPlatformError )
89
910import 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