Exemple #1
0
def diff(name: str) -> ListLike:
    """Get the difference between history yaml and local conda environment"""
    env = Environment.read(name=name)
    env_reader = EnvIO(env_directory=USER_ENVS_DIR / name)
    version_diff_pkges, new_pkges, missing_pkges = History.history_diff(
        env_name=name, env=env, env_reader=env_reader)
    return missing_pkges + version_diff_pkges + new_pkges
Exemple #2
0
def conda_update(
    name: str,
    specs: ListLike = (),
    channels: ListLike = None,
    all=False,
    yes: bool = False,
    strict_channel_priority: bool = True,
) -> Environment:
    """Install conda packages into the environment."""
    env = Environment.read(name=name)
    cleaned = process_specs(specs)
    if all:
        CondaHandler(env=env).update_all(
            packages=cleaned,
            channels=channels,
            yes=yes,
            strict_channel_priority=strict_channel_priority,
        )
    else:
        CondaHandler(env=env).install(
            packages=cleaned,
            channels=channels,
            yes=yes,
            strict_channel_priority=strict_channel_priority,
        )
    _ask_user_to_sync(name=name, yes=yes)
    return env
Exemple #3
0
def pip_remove(name: str, specs: ListLike, yes: bool = False) -> Environment:
    """Remove pip packages including custom packages"""
    env = Environment.read(name=name)
    check_pip(env=env)
    cleaned = process_specs(specs)
    PipHandler(env=env).remove(packages=cleaned, yes=yes)
    _ask_user_to_sync(name=name, yes=yes)
    return env
Exemple #4
0
def r_remove(name: str, specs=ListLike, yes: bool = False) -> Environment:
    """R remove spec"""
    env = Environment.read(name=name)
    check_r_base_package(env=env)
    packages = Packages.from_specs(specs)
    RHandler(env=env).remove(packages=packages)
    _ask_user_to_sync(name=name, yes=yes)
    return env
def test_missing_r_base():
    with pytest.raises(RError) as err:
        env = Environment.read(name="test_env_name_that_does_not_exist")
        check_r_base_package(env=env)
    assert (
        str(err.value)
        == f'"r-base" not installed.\nFound conda packages:\n[]\nMust have "r-base" conda installed to install R packages.'
    )
Exemple #6
0
def conda_remove(
    name: str, specs: ListLike, channels: ListLike = None, yes: bool = False
) -> Environment:
    """Remove conda packages into the environment."""
    env = Environment.read(name=name)
    cleaned = clean_specs(specs)
    CondaHandler(env=env).remove(packages=cleaned, channels=channels, yes=yes)
    _ask_user_to_sync(name=name, yes=yes)
    return env
Exemple #7
0
def r_install(
    name: str, package_names: ListLike, commands: ListLike, yes: bool = False
) -> Environment:
    """Install R packages with corresponding R command."""
    env = Environment.read(name=name)
    check_r_base_package(env=env)
    packages = clean_r_specs(package_names=package_names, commands=commands)
    RHandler(env=env).install(packages=packages)
    _ask_user_to_sync(name=name, yes=yes)
    return env
Exemple #8
0
def pip_custom_install(
    name: str, package: str, url_path: str, yes: bool = False
) -> Environment:
    """Install custom pip package"""
    env = Environment.read(name=name)
    check_pip(env=env)
    cleaned = Package(name=package.lower(), spec=url_path)
    PipHandler(env=env).custom_install(package=cleaned)
    _ask_user_to_sync(name=name, yes=yes)
    return env
Exemple #9
0
def update_packages(name: str, specs: ListLike, remove: ListLike) -> Environment:
    """Update the history with local packages installed without cet cli."""
    # pylint: disable=redefined-outer-name
    env = Environment.read(name=name)
    handler = CondaHandler(env=env)
    if remove:
        cleaned_remove = clean_specs(remove)
        handler.update_history_remove(packages=cleaned_remove)
    if specs:
        cleaned = clean_specs(specs)
        handler.update_history_install(packages=cleaned)
    env.export()
    return env
Exemple #10
0
def pip_install(
    name: str,
    specs: ListLike,
    index_url: Union[str, ListLike] = PIP_DEFAULT_INDEX_URL,
    yes: bool = False,
) -> Environment:
    """Install pip packages into the environment."""
    env = Environment.read(name=name)
    check_pip(env=env)
    cleaned = process_specs(specs, check_custom=True)
    PipHandler(env=env).install(packages=cleaned, index_url=index_url)
    _ask_user_to_sync(name=name, yes=yes)
    return env
Exemple #11
0
def conda_install(
    name: str,
    specs: ListLike,
    channels: ListLike = None,
    yes: bool = False,
    strict_channel_priority: bool = True,
) -> Environment:
    """Install conda packages into the environment."""
    env = Environment.read(name=name)
    cleaned = process_specs(specs)
    CondaHandler(env=env).install(
        packages=cleaned,
        channels=channels,
        yes=yes,
        strict_channel_priority=strict_channel_priority,
    )
    if not yes:
        jupyter_kernel_install_query(name=name, packages=cleaned)
    _ask_user_to_sync(name=name, yes=yes)
    return env
Exemple #12
0
def pull(name: str, yes: bool = False) -> Environment:
    """Pull the remote changes to local"""
    env = Environment.read(name=name)
    return _pull(env=env, yes=yes)
Exemple #13
0
def push(name: str) -> Environment:
    """Push the local changes to remote"""
    env = Environment.read(name=name)
    return _push(env=env)
Exemple #14
0
def remove(name: str, yes=False) -> None:
    """Remove the cet environment. Conda environment and any associated files."""
    env = Environment.read(name=name)
    env.remove(yes=yes)
Exemple #15
0
def rebuild(name: str) -> Environment:
    """Rebuild the conda environment."""
    env = Environment.read(name=name)
    env.rebuild()
    return env
Exemple #16
0
def update_channels(name: str, channels: ListLike) -> Environment:
    """Add channels to the cet for future installs."""
    env = Environment.read(name=name)
    env.append_channels(channels)
    return env
def test_missing_pip_pip_install():
    env = Environment.read(name="test_env_name_that_does_not_exist")
    env.dependencies = {"conda": {"python": "3.7"}}
    with pytest.raises(PipInstallError) as err:
        check_pip(env=env)
    assert str(err.value) == ("Must have pip installed to install pip packages")
Exemple #18
0
def pkg_list(name: str) -> dict:
    """A function to print the list of packages in the environment"""
    env = Environment.read(name=name)
    packages = get_packages(env)
    print_package_list(packages)
    return packages
Exemple #19
0
def sync(name: str, yes: bool = False) -> Environment:
    """Automatically pull and push any changes needed"""
    env = Environment.read(name=name)
    env = _pull(env=env, yes=yes)
    return _push(env=env)