1111import distutils .sysconfig
1212from distutils .version import LooseVersion
1313
14- from . import escape_path
14+ from . import escape_path , which
1515from .env import (IS_64BIT , IS_DARWIN , IS_WINDOWS ,
1616 DEBUG , REL_WITH_DEB_INFO ,
1717 check_env_flag , check_negative_env_flag )
2222from .numpy_ import USE_NUMPY , NUMPY_INCLUDE_DIR
2323
2424
25- def _which (thefile ):
26- path = os .environ .get ("PATH" , os .defpath ).split (os .pathsep )
27- for d in path :
28- fname = os .path .join (d , thefile )
29- fnames = [fname ]
30- if IS_WINDOWS :
31- exts = os .environ .get ('PATHEXT' , '' ).split (os .pathsep )
32- fnames += [fname + ext for ext in exts ]
33- for name in fnames :
34- if os .access (name , os .F_OK | os .X_OK ) and not os .path .isdir (name ):
35- return name
36- return None
37-
38-
3925def _mkdir_p (d ):
4026 try :
4127 os .makedirs (d )
@@ -47,7 +33,7 @@ def _mkdir_p(d):
4733# Use ninja if it is on the PATH. Previous version of PyTorch required the
4834# ninja python package, but we no longer use it, so we do not have to import it
4935USE_NINJA = (not check_negative_env_flag ('USE_NINJA' ) and
50- _which ('ninja' ) is not None )
36+ which ('ninja' ) is not None )
5137
5238
5339class CMake :
@@ -80,9 +66,9 @@ def _get_cmake_command():
8066 cmake_command = 'cmake'
8167 if IS_WINDOWS :
8268 return cmake_command
83- cmake3 = _which ('cmake3' )
69+ cmake3 = which ('cmake3' )
8470 if cmake3 is not None :
85- cmake = _which ('cmake' )
71+ cmake = which ('cmake' )
8672 if cmake is not None :
8773 bare_version = CMake ._get_version (cmake )
8874 if (bare_version < LooseVersion ("3.5.0" ) and
0 commit comments