Example #1
0
def install_nvm(host: Driver) -> None:
    """
    Download and install nvm. Add the commands for auto-loading it to the rc
    file for the particular shell (if it's a shell we recognise).
    """
    stdout = host.exec("test -f ~/.nvm/nvm.sh > /dev/null; echo $?").stdout
    if stdout.decode().strip() == "0":
        return

    if host.platform == "ubuntu":
        apt_install(host, ["curl"])
    elif host.platform == "arch":
        pacman_install(host, ["curl"])
    else:
        print("Neither ubuntu nor arch, let's continue and hope we have curl")

    host.exec(
        "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash"
    )

    host.exec_as_script("\n".join(nvm_init_script))

    rc_file = get_shell_rc_file(host)
    if rc_file is not None:
        if host.exec(f"grep NVM_DIR {rc_file}").return_code != 0:
            for i, line in enumerate(nvm_init_script):
                host.exec_as_script("\n".join([
                    f"cat >> {rc_file} <<EOF",
                    *nvm_init_script,
                    "EOF",
                ]))
Example #2
0
def npm_install(host: Driver, node_version: str, cwd: str):
    """
    Run `npm install` in the directory `cwd`, after executing `nvm use
    {node_version}`.
    """
    host.exec_as_script("\n".join([
        *nvm_init_script, f"nvm use {node_version}", f"cd {cwd}", "npm install"
    ]))
Example #3
0
def nvm_install(host: Driver, node_version: str):
    """
    Use nvm to install version `node_version` of node. Eg.
    `nvm_install("v13.7.0")`. Any version that appears in the list output when
    you run `nvm ls` should work.
    """
    install_nvm(host)
    host.exec_as_script("\n".join(
        [*nvm_init_script, f"nvm install {node_version}"]))
Example #4
0
def pip_install(host: Driver,
                python_version: str,
                virtualenv_name: str,
                what_to_install: str,
                editable: bool = False) -> None:
    host.exec_as_script("\n".join([
        'export PATH="$HOME/.pyenv/bin:$PATH"', 'eval "$(pyenv init -)"',
        'eval "$(pyenv virtualenv-init -)"',
        f"pyenv activate {virtualenv_name}",
        f"pip install {'-e' if editable else ''} {what_to_install}"
    ]))
Example #5
0
def pyenv_install_rc(host: Driver):
    lines = [
        'export PATH="$HOME/.pyenv/bin:$PATH"',
        'eval "$(pyenv init -)"',
        'eval "$(pyenv virtualenv-init -)"',
    ]
    rc_file = get_shell_rc_file(host)
    if rc_file is not None:
        if host.exec(f"grep pyenv {rc_file}",
                     assert_ok=False).return_code != 0:
            host.exec_as_script("\n".join([
                f"cat >> {rc_file} <<'EOF'",
                *lines,
                "EOF",
            ]))
Example #6
0
def install_python_app(host: Driver, python_version: str, virtualenv_name: str,
                       install_cmd: str, binaries: List[str]):
    pyenv_virtualenv(host, python_version, virtualenv_name)

    host.exec_as_script(f"""
        export PATH="$HOME/.pyenv/bin:$PATH"
        eval "$(pyenv init -)"
        eval "$(pyenv virtualenv-init -)"
        pyenv activate {python_version}/envs/{virtualenv_name}
        {install_cmd}
    """)

    for b in binaries:
        link(
            host,
            link_name=f"~/bin/{b}",
            target=f"{virtualenv_dir(python_version, virtualenv_name)}/bin/{b}"
        )