Esempio n. 1
0
def create_core_penv(penv_dir=None, ignore_pythons=None):
    penv_dir = penv_dir or get_penv_dir()

    click.echo("Creating a virtual environment at %s" % penv_dir)

    result_dir = None
    for python_exe in python.find_compatible_pythons(ignore_pythons):
        result_dir = create_virtualenv(python_exe, penv_dir)
        if result_dir:
            break

    if not result_dir and not python.is_portable():
        python_exe = python.fetch_portable_python(os.path.dirname(penv_dir))
        if python_exe:
            result_dir = create_virtualenv(python_exe, penv_dir)

    if not result_dir:
        raise exception.PIOInstallerException(
            "Could not create PIO Core Virtual Environment. Please report to "
            "https://github.com/platformio/platformio-core-installer/issues")

    python_exe = os.path.join(get_penv_bin_dir(penv_dir),
                              "python.exe" if util.IS_WINDOWS else "python")
    add_state_info(python_exe, penv_dir)
    install_pip(python_exe, penv_dir)
    click.echo("Virtual environment has been successfully created!")
    return result_dir
Esempio n. 2
0
def install_platformio_core(shutdown_piohome=True,
                            develop=False,
                            ignore_pythons=None):
    # pylint: disable=bad-option-value, import-outside-toplevel, unused-import, import-error, unused-variable, cyclic-import
    from pioinstaller import penv

    if shutdown_piohome:
        home.shutdown_pio_home_servers()

    penv_dir = penv.create_core_penv(ignore_pythons=ignore_pythons)
    python_exe = os.path.join(penv.get_penv_bin_dir(penv_dir),
                              "python.exe" if util.IS_WINDOWS else "python")
    command = [python_exe, "-m", "pip", "install", "-U"]
    if develop:
        click.echo("Installing a development version of PlatformIO Core")
        command.append(PIO_CORE_DEVELOP_URL)
    else:
        click.echo("Installing PlatformIO Core")
        command.append("platformio")
    try:
        subprocess.check_call(command)
    except Exception as e:  # pylint:disable=broad-except
        error = str(e)
        if util.IS_WINDOWS:
            error = (
                "If you have antivirus/firewall/defender software in a system,"
                " try to disable it for a while.\n %s" % error)
        raise exception.PIOInstallerException(
            "Could not install PlatformIO Core: %s" % error)
    platformio_exe = os.path.join(
        penv.get_penv_bin_dir(penv_dir),
        "platformio.exe" if util.IS_WINDOWS else "platformio",
    )
    try:
        home.install_pio_home(platformio_exe)
    except Exception as e:  # pylint:disable=broad-except
        log.debug(e)

    click.secho(
        "\nPlatformIO Core has been successfully installed into an isolated environment `%s`!\n"
        % penv_dir,
        fg="green",
    )
    click.secho("The full path to `platformio.exe` is `%s`" % platformio_exe,
                fg="cyan")
    # pylint:disable=line-too-long
    click.secho(
        """
If you need an access to `platformio.exe` from other applications, please install Shell Commands
(add PlatformIO Core binary directory `%s` to the system environment PATH variable):

See https://docs.platformio.org/page/installation.html#install-shell-commands
""" % penv.get_penv_bin_dir(penv_dir),
        fg="cyan",
    )
    return True
Esempio n. 3
0
def install_pio_home(platformio_exe):
    try:
        subprocess.check_output(
            [platformio_exe, "home", "--host", "__do_not_start__"],
            stderr=subprocess.PIPE,
        )
        return True
    except Exception as e:  # pylint:disable=broad-except
        raise exception.PIOInstallerException(
            "Could not install PIO Home: %s" % str(e))
Esempio n. 4
0
def upgrade_core(platformio_exe, dev=False):
    command = [platformio_exe, "upgrade"]
    if dev:
        command.append("--dev")
    try:
        subprocess.check_output(
            command,
            stderr=subprocess.PIPE,
        )
        return True
    except Exception as e:  # pylint:disable=broad-except
        raise exception.PIOInstallerException(
            "Could not upgrade PlatformIO Core: %s" % str(e))
Esempio n. 5
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