def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, symlink=True):
if sys.executable.startswith(bin_dir):<EOL><INDENT>print('<STR_LIT>')<EOL>return<EOL><DEDENT>if clear:<EOL><INDENT>rmtree(lib_dir)<EOL>logger.notify('<STR_LIT>', bin_dir)<EOL><DEDENT>if hasattr(sys, '<STR_LIT>'):<EOL><INDENT>logger.notify('<STR_LIT>' % sys.real_prefix)<EOL>prefix = sys.real_prefix<EOL><DEDENT>elif hasattr(sys, '<STR_LIT>'):<EOL><INDENT>logger.notify('<STR_LIT>' % sys.base_prefix)<EOL>prefix = sys.base_prefix<EOL><DEDENT>else:<EOL><INDENT>prefix = sys.prefix<EOL><DEDENT>mkdir(lib_dir)<EOL>fix_lib64(lib_dir, symlink)<EOL>stdlib_dirs = [os.path.dirname(os.__file__)]<EOL>if is_win:<EOL><INDENT>stdlib_dirs.append(join(os.path.dirname(stdlib_dirs[<NUM_LIT:0>]), '<STR_LIT>'))<EOL><DEDENT>elif is_darwin:<EOL><INDENT>stdlib_dirs.append(join(stdlib_dirs[<NUM_LIT:0>], '<STR_LIT>'))<EOL><DEDENT>if hasattr(os, '<STR_LIT>'):<EOL><INDENT>logger.info('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>logger.info('<STR_LIT>')<EOL><DEDENT>logger.indent += <NUM_LIT:2><EOL>try:<EOL><INDENT>for stdlib_dir in stdlib_dirs:<EOL><INDENT>if not os.path.isdir(stdlib_dir):<EOL><INDENT>continue<EOL><DEDENT>for fn in os.listdir(stdlib_dir):<EOL><INDENT>bn = os.path.splitext(fn)[<NUM_LIT:0>]<EOL>if fn != '<STR_LIT>' and bn in REQUIRED_FILES:<EOL><INDENT>copyfile(join(stdlib_dir, fn), join(lib_dir, fn), symlink)<EOL><DEDENT><DEDENT><DEDENT>copy_required_modules(home_dir, symlink)<EOL><DEDENT>finally:<EOL><INDENT>logger.indent -= <NUM_LIT:2><EOL><DEDENT>mkdir(join(lib_dir, '<STR_LIT>'))<EOL>import site<EOL>site_filename = site.__file__<EOL>if site_filename.endswith('<STR_LIT>'):<EOL><INDENT>site_filename = site_filename[:-<NUM_LIT:1>]<EOL><DEDENT>elif site_filename.endswith('<STR_LIT>'):<EOL><INDENT>site_filename = site_filename.replace('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>site_filename_dst = change_prefix(site_filename, home_dir)<EOL>site_dir = os.path.dirname(site_filename_dst)<EOL>writefile(site_filename_dst, SITE_PY)<EOL>writefile(join(site_dir, '<STR_LIT>'), prefix)<EOL>site_packages_filename = join(site_dir, '<STR_LIT>')<EOL>if not site_packages:<EOL><INDENT>writefile(site_packages_filename, '<STR_LIT>')<EOL><DEDENT>if is_pypy or is_win:<EOL><INDENT>stdinc_dir = join(prefix, '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>stdinc_dir = join(prefix, '<STR_LIT>', py_version + abiflags)<EOL><DEDENT>if os.path.exists(stdinc_dir):<EOL><INDENT>copyfile(stdinc_dir, inc_dir, symlink)<EOL><DEDENT>else:<EOL><INDENT>logger.debug('<STR_LIT>' % stdinc_dir)<EOL><DEDENT>platinc_dir = distutils.sysconfig.get_python_inc(plat_specific=<NUM_LIT:1>)<EOL>if platinc_dir != stdinc_dir:<EOL><INDENT>platinc_dest = distutils.sysconfig.get_python_inc(<EOL>plat_specific=<NUM_LIT:1>, prefix=home_dir)<EOL>if platinc_dir == platinc_dest:<EOL><INDENT>platinc_dest = subst_path(platinc_dir, prefix, home_dir)<EOL><DEDENT>if platinc_dest:<EOL><INDENT>copyfile(platinc_dir, platinc_dest, symlink)<EOL><DEDENT><DEDENT>if sys.exec_prefix != prefix and not is_pypy:<EOL><INDENT>if is_win:<EOL><INDENT>exec_dir = join(sys.exec_prefix, '<STR_LIT>')<EOL><DEDENT>elif is_jython:<EOL><INDENT>exec_dir = join(sys.exec_prefix, '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>exec_dir = join(sys.exec_prefix, '<STR_LIT>', py_version)<EOL><DEDENT>for fn in os.listdir(exec_dir):<EOL><INDENT>copyfile(join(exec_dir, fn), join(lib_dir, fn), symlink)<EOL><DEDENT><DEDENT>if is_jython:<EOL><INDENT>for name in '<STR_LIT>', '<STR_LIT>', '<STR_LIT>':<EOL><INDENT>src = join(prefix, name)<EOL>if os.path.exists(src):<EOL><INDENT>copyfile(src, join(home_dir, name), symlink)<EOL><DEDENT><DEDENT>src = join(prefix, '<STR_LIT>')<EOL>if os.path.exists(src):<EOL><INDENT>copyfile(src, join(home_dir, '<STR_LIT>'), symlink=False)<EOL><DEDENT>copyfile(join(prefix, '<STR_LIT>'), join(home_dir, '<STR_LIT>'),<EOL>symlink=False)<EOL><DEDENT>mkdir(bin_dir)<EOL>py_executable = join(bin_dir, os.path.basename(sys.executable))<EOL>if '<STR_LIT>' in prefix:<EOL><INDENT>if os.environ.get('<STR_LIT>'):<EOL><INDENT>del os.environ["<STR_LIT>"]<EOL><DEDENT>if re.search(r'<STR_LIT>', py_executable):<EOL><INDENT>py_executable = os.path.join(<EOL>os.path.dirname(py_executable), '<STR_LIT>')<EOL><DEDENT><DEDENT>logger.notify('<STR_LIT>', expected_exe, py_executable)<EOL>pcbuild_dir = os.path.dirname(sys.executable)<EOL>pyd_pth = os.path.join(lib_dir, '<STR_LIT>', '<STR_LIT>')<EOL>if is_win and os.path.exists(os.path.join(pcbuild_dir, '<STR_LIT>')):<EOL><INDENT>logger.notify('<STR_LIT>', pcbuild_dir)<EOL>logger.notify('<STR_LIT>')<EOL>writefile(pyd_pth, pcbuild_dir)<EOL><DEDENT>else:<EOL><INDENT>pcbuild_dir = None<EOL>if os.path.exists(pyd_pth):<EOL><INDENT>logger.info('<STR_LIT>' % pyd_pth)<EOL>os.unlink(pyd_pth)<EOL><DEDENT><DEDENT>if sys.executable != py_executable:<EOL><INDENT>executable = sys.executable<EOL>shutil.copyfile(executable, py_executable)<EOL>make_exe(py_executable)<EOL>if is_win or is_cygwin:<EOL><INDENT>pythonw = os.path.join(os.path.dirname(sys.executable), '<STR_LIT>')<EOL>if os.path.exists(pythonw):<EOL><INDENT>logger.info('<STR_LIT>')<EOL>shutil.copyfile(pythonw, os.path.join(os.path.dirname(py_executable), '<STR_LIT>'))<EOL><DEDENT>python_d = os.path.join(os.path.dirname(sys.executable), '<STR_LIT>')<EOL>python_d_dest = os.path.join(os.path.dirname(py_executable), '<STR_LIT>')<EOL>if os.path.exists(python_d):<EOL><INDENT>logger.info('<STR_LIT>')<EOL>shutil.copyfile(python_d, python_d_dest)<EOL><DEDENT>elif os.path.exists(python_d_dest):<EOL><INDENT>logger.info('<STR_LIT>')<EOL>os.unlink(python_d_dest)<EOL><DEDENT>py_executable_dll = '<STR_LIT>' % (<EOL>sys.version_info[<NUM_LIT:0>], sys.version_info[<NUM_LIT:1>])<EOL>py_executable_dll_d = '<STR_LIT>' % (<EOL>sys.version_info[<NUM_LIT:0>], sys.version_info[<NUM_LIT:1>])<EOL>pythondll = os.path.join(os.path.dirname(sys.executable), py_executable_dll)<EOL>pythondll_d = os.path.join(os.path.dirname(sys.executable), py_executable_dll_d)<EOL>pythondll_d_dest = os.path.join(os.path.dirname(py_executable), py_executable_dll_d)<EOL>if os.path.exists(pythondll):<EOL><INDENT>logger.info('<STR_LIT>' % py_executable_dll)<EOL>shutil.copyfile(pythondll, os.path.join(os.path.dirname(py_executable), py_executable_dll))<EOL><DEDENT>if os.path.exists(pythondll_d):<EOL><INDENT>logger.info('<STR_LIT>' % py_executable_dll_d)<EOL>shutil.copyfile(pythondll_d, pythondll_d_dest)<EOL><DEDENT>elif os.path.exists(pythondll_d_dest):<EOL><INDENT>logger.info('<STR_LIT>' % pythondll_d_dest)<EOL>os.unlink(pythondll_d_dest)<EOL><DEDENT><DEDENT>if is_pypy:<EOL><INDENT>python_executable = os.path.join(os.path.dirname(py_executable), '<STR_LIT>')<EOL>if sys.platform in ('<STR_LIT:win32>', '<STR_LIT>'):<EOL><INDENT>python_executable += '<STR_LIT>'<EOL><DEDENT>logger.info('<STR_LIT>' % python_executable)<EOL>copyfile(py_executable, python_executable, symlink)<EOL>if is_win:<EOL><INDENT>for name in '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>':<EOL><INDENT>src = join(prefix, name)<EOL>if os.path.exists(src):<EOL><INDENT>copyfile(src, join(bin_dir, name), symlink)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if os.path.splitext(os.path.basename(py_executable))[<NUM_LIT:0>] != expected_exe:<EOL><INDENT>secondary_exe = os.path.join(os.path.dirname(py_executable),<EOL>expected_exe)<EOL>py_executable_ext = os.path.splitext(py_executable)[<NUM_LIT:1>]<EOL>if py_executable_ext.lower() == '<STR_LIT>':<EOL><INDENT>secondary_exe += py_executable_ext<EOL><DEDENT>if os.path.exists(secondary_exe):<EOL><INDENT>logger.warn('<STR_LIT>'<EOL>% (expected_exe, secondary_exe, py_executable))<EOL><DEDENT>else:<EOL><INDENT>logger.notify('<STR_LIT>' % secondary_exe)<EOL>shutil.copyfile(sys.executable, secondary_exe)<EOL>make_exe(secondary_exe)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in prefix:<EOL><INDENT>if '<STR_LIT>' in prefix:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>original_python = os.path.join(<EOL>prefix, '<STR_LIT>')<EOL><DEDENT>if '<STR_LIT>' in prefix:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>original_python = os.path.join(prefix, '<STR_LIT>')<EOL><DEDENT>shutil.copy(original_python, py_executable)<EOL>virtual_lib = os.path.join(home_dir, '<STR_LIT>')<EOL>if os.path.exists(virtual_lib):<EOL><INDENT>os.unlink(virtual_lib)<EOL><DEDENT>copyfile(<EOL>os.path.join(prefix, '<STR_LIT>'),<EOL>virtual_lib,<EOL>symlink)<EOL>try:<EOL><INDENT>mach_o_change(py_executable,<EOL>os.path.join(prefix, '<STR_LIT>'),<EOL>'<STR_LIT>')<EOL><DEDENT>except:<EOL><INDENT>e = sys.exc_info()[<NUM_LIT:1>]<EOL>logger.warn("<STR_LIT>"<EOL>"<STR_LIT>" % e)<EOL>try:<EOL><INDENT>call_subprocess(<EOL>["<STR_LIT>", "<STR_LIT>",<EOL>os.path.join(prefix, '<STR_LIT>'),<EOL>'<STR_LIT>',<EOL>py_executable])<EOL><DEDENT>except:<EOL><INDENT>logger.fatal("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>raise<EOL><DEDENT><DEDENT><DEDENT>if not is_win:<EOL><INDENT>py_exe_version_major = '<STR_LIT>' % sys.version_info[<NUM_LIT:0>]<EOL>py_exe_version_major_minor = '<STR_LIT>' % (<EOL>sys.version_info[<NUM_LIT:0>], sys.version_info[<NUM_LIT:1>])<EOL>py_exe_no_version = '<STR_LIT>'<EOL>required_symlinks = [ py_exe_no_version, py_exe_version_major,<EOL>py_exe_version_major_minor ]<EOL>py_executable_base = os.path.basename(py_executable)<EOL>if py_executable_base in required_symlinks:<EOL><INDENT>required_symlinks.remove(py_executable_base)<EOL><DEDENT>for pth in required_symlinks:<EOL><INDENT>full_pth = join(bin_dir, pth)<EOL>if os.path.exists(full_pth):<EOL><INDENT>os.unlink(full_pth)<EOL><DEDENT>if symlink:<EOL><INDENT>os.symlink(py_executable_base, full_pth)<EOL><DEDENT>else:<EOL><INDENT>copyfile(py_executable, full_pth, symlink)<EOL><DEDENT><DEDENT><DEDENT>if is_win and '<STR_LIT:U+0020>' in py_executable:<EOL><INDENT>py_executable = '<STR_LIT>' % py_executable<EOL><DEDENT>cmd = [py_executable, '<STR_LIT:-c>', '<STR_LIT>'<EOL>'<STR_LIT>']<EOL>logger.info('<STR_LIT>' % tuple(cmd))<EOL>try:<EOL><INDENT>proc = subprocess.Popen(cmd,<EOL>stdout=subprocess.PIPE)<EOL>proc_stdout, proc_stderr = proc.communicate()<EOL><DEDENT>except OSError:<EOL><INDENT>e = sys.exc_info()[<NUM_LIT:1>]<EOL>if e.errno == errno.EACCES:<EOL><INDENT>logger.fatal('<STR_LIT>' % (py_executable, e))<EOL>sys.exit(<NUM_LIT:100>)<EOL><DEDENT>else:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT>proc_stdout = proc_stdout.strip().decode("<STR_LIT:utf-8>")<EOL>proc_stdout = os.path.normcase(os.path.abspath(proc_stdout))<EOL>norm_home_dir = os.path.normcase(os.path.abspath(home_dir))<EOL>if hasattr(norm_home_dir, '<STR_LIT>'):<EOL><INDENT>norm_home_dir = norm_home_dir.decode(sys.getfilesystemencoding())<EOL><DEDENT>if proc_stdout != norm_home_dir:<EOL><INDENT>logger.fatal(<EOL>'<STR_LIT>' % py_executable)<EOL>logger.fatal(<EOL>'<STR_LIT>'<EOL>% (proc_stdout, norm_home_dir))<EOL>logger.fatal(<EOL>'<STR_LIT>')<EOL>if is_win:<EOL><INDENT>logger.fatal(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>sys.exit(<NUM_LIT:100>)<EOL><DEDENT>else:<EOL><INDENT>logger.info('<STR_LIT>' % proc_stdout)<EOL><DEDENT>pydistutils = os.path.expanduser('<STR_LIT>')<EOL>if os.path.exists(pydistutils):<EOL><INDENT>logger.notify('<STR_LIT>'<EOL>'<STR_LIT>' % pydistutils)<EOL><DEDENT>fix_local_scheme(home_dir, symlink)<EOL>if site_packages:<EOL><INDENT>if os.path.exists(site_packages_filename):<EOL><INDENT>logger.info('<STR_LIT>' % site_packages_filename)<EOL>os.unlink(site_packages_filename)<EOL><DEDENT><DEDENT>return py_executable<EOL>
Install just the base environment, no distutils patches etc