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
def install_pip(python_exe, penv_dir): click.echo( "Updating Python package manager (PIP) in a virtual environment") try: log.debug("Creating pip.conf file in %s", penv_dir) with open(os.path.join(penv_dir, "pip.conf"), "w") as fp: fp.write("\n".join(["[global]", "user=no"])) log.debug("Downloading 'get-pip.py' installer...") get_pip_path = os.path.join(os.path.dirname(penv_dir), ".cache", "tmp", os.path.basename(PIP_URL)) util.download_file(PIP_URL, get_pip_path) log.debug("Installing pip") subprocess.check_output([python_exe, get_pip_path], stderr=subprocess.PIPE) click.echo("PIP has been successfully updated!") return True except Exception as e: # pylint:disable=broad-except log.debug( "Could not install pip. Error: %s", str(e), ) return False
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