5050import os
5151import platform
5252import re
53- import sys
5453import site
54+ import sys
5555
5656# Import this before distutils so that setuptools can intercept the distuils
5757# imports.
@@ -372,12 +372,13 @@ def dst_path(self, installer: "InstallerBuildExt") -> Path:
372372
373373class InstallerBuildExt (build_ext ):
374374 """Installs files that were built by cmake."""
375+
375376 def __init__ (self , * args , ** kwargs ):
376377 self ._ran_build = False
377378 super ().__init__ (* args , ** kwargs )
378379
379380 def run (self ):
380- # Run the build command first in editable mode. Since `build` command
381+ # Run the build command first in editable mode. Since `build` command
381382 # will also trigger `build_ext` command, only run this once.
382383 if self ._ran_build :
383384 return
@@ -387,10 +388,9 @@ def run(self):
387388 self .run_command ("build" )
388389 super ().run ()
389390
390-
391391 def copy_extensions_to_source (self ) -> None :
392- """For each extension in `ext_modules`, we need to copy the extension
393- file from the build directory to the correct location in the local
392+ """For each extension in `ext_modules`, we need to copy the extension
393+ file from the build directory to the correct location in the local
394394 directory.
395395
396396 This should only be triggered when inplace mode (editable mode) is enabled.
@@ -399,11 +399,11 @@ def copy_extensions_to_source(self) -> None:
399399
400400 Returns:
401401 """
402- build_py = self .get_finalized_command (' build_py' )
402+ build_py = self .get_finalized_command (" build_py" )
403403 for ext in self .extensions :
404404 if isinstance (ext , BuiltExtension ):
405- modpath = ext .name .split ('.' )
406- package = '.' .join (modpath [:- 1 ])
405+ modpath = ext .name .split ("." )
406+ package = "." .join (modpath [:- 1 ])
407407 package_dir = os .path .abspath (build_py .get_package_dir (package ))
408408 else :
409409 # HACK: get rid of the leading "executorch" in ext.dst.
@@ -412,9 +412,11 @@ def copy_extensions_to_source(self) -> None:
412412
413413 # Ensure that the destination directory exists.
414414 self .mkpath (os .fspath (package_dir ))
415-
415+
416416 regular_file = ext .src_path (self )
417- inplace_file = os .path .join (package_dir , os .path .basename (ext .src_path (self )))
417+ inplace_file = os .path .join (
418+ package_dir , os .path .basename (ext .src_path (self ))
419+ )
418420
419421 # Always copy, even if source is older than destination, to ensure
420422 # that the right extensions for the current Python/platform are
@@ -428,7 +430,6 @@ def copy_extensions_to_source(self) -> None:
428430 # Always compile stub and remove the original (leave the cache behind)
429431 # (this behaviour was observed in previous iterations of the code)
430432
431-
432433 # TODO(dbort): Depend on the "build" command to ensure it runs first
433434
434435 def build_extension (self , ext : _BaseExtension ) -> None :
@@ -688,7 +689,9 @@ def run(self):
688689 # Dry run should log the command but not actually run it.
689690 (Path (cmake_cache_dir ) / "CMakeCache.txt" ).unlink (missing_ok = True )
690691 # Set PYTHONPATH to the location of the pip package.
691- os .environ ["PYTHONPATH" ] = site .getsitepackages ()[0 ] + ";" + os .environ ["PYTHONPATH" ]
692+ os .environ ["PYTHONPATH" ] = (
693+ site .getsitepackages ()[0 ] + ";" + os .environ .get ("PYTHONPATH" , "" )
694+ )
692695 with Buck2EnvironmentFixer ():
693696 # The context manager may patch the environment while running this
694697 # cmake command, which happens to run buck2 to get some source
0 commit comments