예제 #1
0
def get_shell_command(name: str, r_command: str) -> str:
    """Handle conda env and call R code from command line."""
    commands = []
    if not is_current_conda_env(name=name):
        commands.append(get_conda_activate_command(name=name))
    r_command = _wrap_r_subprocess_command(r_command)
    commands.append(r_command)
    return " && ".join(commands)
예제 #2
0
def get_pip_version(name: str) -> Optional[str]:
    """Check for the version of pip (if installed)."""
    if is_current_conda_env(name):
        import pip

        return pip.__version__
    dependencies = get_dependencies(name=name)
    return dependencies["conda"].get("pip", Package(name="pip")).version
예제 #3
0
def pip_remove(name: str, packages: Packages, yes):
    """Pip uninstall package, can handle custom package removal"""
    commands = []
    if not is_current_conda_env(name):
        commands.append(get_conda_activate_command(name=name))
    commands.append(get_pip_remove_command(packages, yes))
    command = " && ".join(commands)
    logger.debug(f"Pip remove command: {command}")
    run_command(command, error=PipRemoveError)
예제 #4
0
def pip_custom_install(name: str, package: Package):
    """Pip installing packages with custom urls"""
    commands = []
    if not is_current_conda_env(name):
        commands.append(get_conda_activate_command(name=name))
    pip_command = get_pip_custom_install_command(spec=package.spec)
    logger.debug(f"Pip install command: {pip_command}")
    commands.append(pip_command)
    command = " && ".join(commands)
    install = subprocess.run(command,
                             shell=True,
                             stderr=subprocess.PIPE,
                             encoding="UTF-8")
    if install.returncode != 0:
        raise PipInstallError(
            f"Pip install {package.name} with custom url [{package.spec}] failed with message: {install.stderr}"
        )
예제 #5
0
def pip_install(
    name: str,
    packages: Packages,
    index_url: Union[str, ListLike] = PIP_DEFAULT_INDEX_URL,
) -> None:
    """Pip installing packages."""
    commands = []
    if not is_current_conda_env(name):
        commands.append(get_conda_activate_command(name=name))
    commands.append(get_pip_install_command(packages, index_url))
    command = " && ".join(commands)
    logger.debug(f"Pip install command: {command}")
    install = subprocess.run(command,
                             shell=True,
                             stderr=subprocess.PIPE,
                             encoding="UTF-8")
    if install.returncode != 0:
        raise PipInstallError(
            f"Pip install {[package.spec for package in packages]} failed with message: {install.stderr}"
        )
예제 #6
0
def _ensure_correct_conda_env_activated(name: str, command: str):
    """If the current conda environment is not the named conda environment, then activate first."""
    if not is_current_conda_env(name):
        return get_conda_activate_command(name=name) + " && " + command
    return command