mirror of
				https://github.com/python/cpython.git
				synced 2025-11-02 14:41:33 +00:00 
			
		
		
		
	distutils was removed in November. However, the c-analyzer relies on it. To solve that here, we vendor the parts the tool needs so it can be run against 3.12+. (Also see gh-92584.) Note that we may end up removing this code later in favor of a solution in common with the peg_generator tool (which also relies on distutils). At the least, the copy here makes sure the c-analyzer tool works on 3.12+ in the meantime.
		
			
				
	
	
		
			48 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
"""distutils.spawn
 | 
						|
 | 
						|
Provides the 'spawn()' function, a front-end to various platform-
 | 
						|
specific functions for launching another program in a sub-process.
 | 
						|
Also provides the 'find_executable()' to search the path for a given
 | 
						|
executable name.
 | 
						|
"""
 | 
						|
 | 
						|
import sys
 | 
						|
import os
 | 
						|
import os.path
 | 
						|
 | 
						|
 | 
						|
def find_executable(executable, path=None):
 | 
						|
    """Tries to find 'executable' in the directories listed in 'path'.
 | 
						|
 | 
						|
    A string listing directories separated by 'os.pathsep'; defaults to
 | 
						|
    os.environ['PATH'].  Returns the complete filename or None if not found.
 | 
						|
    """
 | 
						|
    _, ext = os.path.splitext(executable)
 | 
						|
    if (sys.platform == 'win32') and (ext != '.exe'):
 | 
						|
        executable = executable + '.exe'
 | 
						|
 | 
						|
    if os.path.isfile(executable):
 | 
						|
        return executable
 | 
						|
 | 
						|
    if path is None:
 | 
						|
        path = os.environ.get('PATH', None)
 | 
						|
        if path is None:
 | 
						|
            try:
 | 
						|
                path = os.confstr("CS_PATH")
 | 
						|
            except (AttributeError, ValueError):
 | 
						|
                # os.confstr() or CS_PATH is not available
 | 
						|
                path = os.defpath
 | 
						|
        # bpo-35755: Don't use os.defpath if the PATH environment variable is
 | 
						|
        # set to an empty string
 | 
						|
 | 
						|
    # PATH='' doesn't match, whereas PATH=':' looks in the current directory
 | 
						|
    if not path:
 | 
						|
        return None
 | 
						|
 | 
						|
    paths = path.split(os.pathsep)
 | 
						|
    for p in paths:
 | 
						|
        f = os.path.join(p, executable)
 | 
						|
        if os.path.isfile(f):
 | 
						|
            # the file exists, we have a shot at spawn working
 | 
						|
            return f
 | 
						|
    return None
 |