コード例 #1
0
def fetch_portable_python(dst):
    url = get_portable_python_url()
    if not url:
        log.debug("Could not find portable Python for %s", util.get_systype())
        return None
    try:
        log.debug("Downloading portable python...")

        archive_path = util.download_file(
            url,
            os.path.join(os.path.join(dst, ".cache", "tmp"),
                         os.path.basename(url)))

        python_dir = os.path.join(dst, "python3")
        util.safe_remove_dir(python_dir)
        util.safe_create_dir(python_dir, raise_exception=True)

        log.debug("Unpacking portable python...")
        util.unpack_archive(archive_path, python_dir)
        if util.IS_WINDOWS:
            return os.path.join(python_dir, "python.exe")
        return os.path.join(python_dir, "bin", "python3")
    except:  # pylint:disable=bare-except
        log.debug("Could not download portable python")
    return None
コード例 #2
0
def create_with_remote_venv(python_exe, penv_dir):
    util.safe_remove_dir(penv_dir)

    log.debug("Downloading virtualenv package archive")
    venv_script_path = util.download_file(
        VIRTUALENV_URL,
        os.path.join(os.path.dirname(penv_dir), ".cache", "tmp",
                     os.path.basename(VIRTUALENV_URL)),
    )
    if not venv_script_path:
        raise exception.PIOInstallerException(
            "Could not find virtualenv script")
    command = [python_exe, venv_script_path, penv_dir]
    log.debug("Creating virtual environment: %s", " ".join(command))
    subprocess.check_output(command, stderr=subprocess.PIPE)
    return penv_dir
コード例 #3
0
def create_with_local_venv(python_exe, penv_dir):
    venv_cmd_options = [
        [python_exe, "-m", "venv", penv_dir],
        [python_exe, "-m", "virtualenv", "-p", python_exe, penv_dir],
        ["virtualenv", "-p", python_exe, penv_dir],
        [python_exe, "-m", "virtualenv", penv_dir],
        ["virtualenv", penv_dir],
    ]
    last_error = None
    for command in venv_cmd_options:
        util.safe_remove_dir(penv_dir)
        log.debug("Creating virtual environment: %s", " ".join(command))
        try:
            subprocess.check_output(command, stderr=subprocess.PIPE)
            return penv_dir
        except Exception as e:  # pylint:disable=broad-except
            last_error = e
    raise last_error  # pylint:disable=raising-bad-type