@@ -34,8 +34,9 @@ def __init__(self, triple=None, cross_lib=None, linker=None, link_args=None):
3434 self .linker = linker
3535 self .link_args = link_args
3636
37+
3738class build_rust (RustCommand ):
38- """ Command for building Rust crates via cargo. """
39+ """Command for building Rust crates via cargo."""
3940
4041 description = "build Rust extensions (compile/link to build directory)"
4142
@@ -72,7 +73,7 @@ def finalize_options(self):
7273 super ().finalize_options ()
7374
7475 if self .plat_name is None :
75- self .plat_name = self .get_finalized_command (' build' ).plat_name
76+ self .plat_name = self .get_finalized_command (" build" ).plat_name
7677
7778 # Inherit settings from the `build_ext` command
7879 self .set_undefined_options (
@@ -105,17 +106,17 @@ def get_nix_target_info(self):
105106 # necessarily the same as the system we are running on. *NIX systems
106107 # have more detailed information available in sysconfig. We need that
107108 # because plat_name doesn't give us information on e.g., glibc vs musl.
108- host_type = sysconfig .get_config_var (' HOST_GNU_TYPE' )
109- build_type = sysconfig .get_config_var (' BUILD_GNU_TYPE' )
109+ host_type = sysconfig .get_config_var (" HOST_GNU_TYPE" )
110+ build_type = sysconfig .get_config_var (" BUILD_GNU_TYPE" )
110111
111112 if not host_type or host_type == build_type :
112113 # not *NIX, or not cross compiling
113114 return _TargetInfo ()
114115
115- stdlib = sysconfig .get_path (' stdlib' )
116+ stdlib = sysconfig .get_path (" stdlib" )
116117 cross_lib = os .path .dirname (stdlib )
117118
118- bldshared = sysconfig .get_config_var (' BLDSHARED' )
119+ bldshared = sysconfig .get_config_var (" BLDSHARED" )
119120 if not bldshared :
120121 linker = None
121122 linker_args = None
@@ -131,16 +132,17 @@ def get_nix_target_info(self):
131132
132133 # the vendor field can be ignored, so x86_64-pc-linux-gnu is compatible
133134 # with x86_64-unknown-linux-gnu
134- components = host_type .split ('-' )
135+ components = host_type .split ("-" )
135136 if len (components ) == 4 :
136- components [1 ] = ' unknown'
137- host_type2 = '-' .join (components )
137+ components [1 ] = " unknown"
138+ host_type2 = "-" .join (components )
138139 if host_type2 in targets :
139140 return _TargetInfo (host_type2 , cross_lib , linker , linker_args )
140141
141142 raise DistutilsPlatformError (
142- "Don't know the correct rust target for system type %s. Please "
143- "set the CARGO_BUILD_TARGET environment variable." % host_type )
143+ "Don't know the correct rust target for system type %s. Please "
144+ "set the CARGO_BUILD_TARGET environment variable." % host_type
145+ )
144146
145147 def run_for_extension (self , ext : RustExtension ):
146148 arch_flags = os .getenv ("ARCHFLAGS" )
@@ -151,9 +153,13 @@ def run_for_extension(self, ext: RustExtension):
151153 arm64_dylib_paths = self .build_extension (ext , "aarch64-apple-darwin" )
152154 x86_64_dylib_paths = self .build_extension (ext , "x86_64-apple-darwin" )
153155 dylib_paths = []
154- for (target_fname , arm64_dylib ), (_ , x86_64_dylib ) in zip (arm64_dylib_paths , x86_64_dylib_paths ):
156+ for (target_fname , arm64_dylib ), (_ , x86_64_dylib ) in zip (
157+ arm64_dylib_paths , x86_64_dylib_paths
158+ ):
155159 fat_dylib_path = arm64_dylib .replace ("aarch64-apple-darwin/" , "" )
156- self .create_universal2_binary (fat_dylib_path , [arm64_dylib , x86_64_dylib ])
160+ self .create_universal2_binary (
161+ fat_dylib_path , [arm64_dylib , x86_64_dylib ]
162+ )
157163 dylib_paths .append ((target_fname , fat_dylib_path ))
158164 else :
159165 dylib_paths = self .build_extension (ext )
@@ -179,7 +185,9 @@ def build_extension(self, ext: RustExtension, target_triple=None):
179185 # which causes pythonXX-sys to fall back to detecting the
180186 # interpreter from the path.
181187 "PATH" : os .path .join (bindir , os .environ .get ("PATH" , "" )),
182- "PYTHON_SYS_EXECUTABLE" : os .environ .get ("PYTHON_SYS_EXECUTABLE" , sys .executable ),
188+ "PYTHON_SYS_EXECUTABLE" : os .environ .get (
189+ "PYTHON_SYS_EXECUTABLE" , sys .executable
190+ ),
183191 "PYO3_PYTHON" : os .environ .get ("PYO3_PYTHON" , sys .executable ),
184192 }
185193 )
@@ -212,7 +220,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
212220
213221 features = {
214222 * ext .features ,
215- * binding_features (ext , py_limited_api = self ._py_limited_api ())
223+ * binding_features (ext , py_limited_api = self ._py_limited_api ()),
216224 }
217225
218226 debug_build = ext .debug if ext .debug is not None else self .inplace
@@ -238,7 +246,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
238246 args .append ("-q" )
239247 elif self .verbose :
240248 # cargo only have -vv
241- verbose_level = 'v' * min (self .verbose , 2 )
249+ verbose_level = "v" * min (self .verbose , 2 )
242250 args .append (f"-{ verbose_level } " )
243251
244252 else :
@@ -254,7 +262,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
254262 args .append ("-q" )
255263 elif self .verbose :
256264 # cargo only have -vv
257- verbose_level = 'v' * min (self .verbose , 2 )
265+ verbose_level = "v" * min (self .verbose , 2 )
258266 args .append (f"-{ verbose_level } " )
259267
260268 args .extend (["--" , "--crate-type" , "cdylib" ])
@@ -293,9 +301,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
293301 try :
294302 output = subprocess .check_output (args , env = env , encoding = "latin-1" )
295303 except subprocess .CalledProcessError as e :
296- raise CompileError (
297- f"cargo failed with code: { e .returncode } \n { e .output } "
298- )
304+ raise CompileError (f"cargo failed with code: { e .returncode } \n { e .output } " )
299305
300306 except OSError :
301307 raise DistutilsExecError (
@@ -421,23 +427,18 @@ def install_extension(self, ext: RustExtension, dylib_paths):
421427 mode |= (mode & 0o444 ) >> 2 # copy R bits to X
422428 os .chmod (ext_path , mode )
423429
424- def get_dylib_ext_path (
425- self ,
426- ext : RustExtension ,
427- target_fname : str
428- ) -> str :
430+ def get_dylib_ext_path (self , ext : RustExtension , target_fname : str ) -> str :
429431 build_ext = self .get_finalized_command ("build_ext" )
430432
431433 filename = build_ext .get_ext_fullpath (target_fname )
432434
433- if (
434- (ext .py_limited_api == "auto" and self ._py_limited_api ())
435- or (ext .py_limited_api )
435+ if (ext .py_limited_api == "auto" and self ._py_limited_api ()) or (
436+ ext .py_limited_api
436437 ):
437438 abi3_suffix = get_abi3_suffix ()
438439 if abi3_suffix is not None :
439- so_ext = get_config_var (' EXT_SUFFIX' )
440- filename = filename [:- len (so_ext )] + get_abi3_suffix ()
440+ so_ext = get_config_var (" EXT_SUFFIX" )
441+ filename = filename [: - len (so_ext )] + get_abi3_suffix ()
441442
442443 return filename
443444
@@ -451,9 +452,7 @@ def create_universal2_binary(output_path, input_paths):
451452 output = e .output
452453 if isinstance (output , bytes ):
453454 output = e .output .decode ("latin-1" ).strip ()
454- raise CompileError (
455- "lipo failed with code: %d\n %s" % (e .returncode , output )
456- )
455+ raise CompileError ("lipo failed with code: %d\n %s" % (e .returncode , output ))
457456 except OSError :
458457 # lipo not found, try using the fat-macho library
459458 try :
0 commit comments