Пример #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