Ejemplo n.º 1
0
 def teardown():
     conda.delete_conda_environment(name=CET_ENV_NAME)
     conda.delete_conda_environment(name=UNSEEN_ENV_NAME)
     if env_dir.is_dir():
         shutil.rmtree(env_dir)
     if cet_dir.is_dir():
         shutil.rmtree(cet_dir)
     if unseen_cet_dir.is_dir():
         shutil.rmtree(unseen_cet_dir)
     if identical_history_dir.is_dir():
         shutil.rmtree(identical_history_dir)
     if empty_dir.is_dir():
         shutil.rmtree(empty_dir)
     if unseen_local_dir.is_dir():
         shutil.rmtree(unseen_local_dir)
Ejemplo n.º 2
0
 def remove(self, yes=False) -> None:
     """Remove the environment and history."""
     delete_conda_environment(name=self.name)
     try:
         remote_io = EnvIO(self.local_io.get_remote_dir())
     except CondaEnvTrackerRemoteError:
         remote_io = None
     self.local_io.delete_all()
     if remote_io and (
         yes
         or prompt_yes_no(
             prompt_msg=f"Do you want to remove remote files in dir: {remote_io.env_dir}?"
         )
     ):
         remote_io.delete_all()
Ejemplo n.º 3
0
 def teardown():
     delete_conda_environment(name=name)
     if env_dir.is_dir():
         shutil.rmtree(env_dir)
     if remote_path.is_dir():
         shutil.rmtree(remote_path)
Ejemplo n.º 4
0
    def create(
        cls,
        name: str,
        packages: Packages,
        channels: ListLike = None,
        yes: bool = False,
        strict_channel_priority: bool = True,
    ):
        """Creating a conda environment from a list of packages."""
        if name == "base":
            raise CondaEnvTrackerCondaError(
                "Environment can not be created using default name base"
            )

        if name in get_all_existing_environment():
            message = (
                f"This environment {name} already exists. Would you like to replace it"
            )
            if prompt_yes_no(prompt_msg=message, default=False):
                delete_conda_environment(name=name)
                local_io = EnvIO(env_directory=USER_ENVS_DIR / name)
                if local_io.env_dir.exists():
                    local_io.delete_all()
            else:
                raise CondaEnvTrackerCondaError(f"Environment {name} already exists")
        logger.debug(f"creating conda env {name}")

        conda_create(
            name=name,
            packages=packages,
            channels=channels,
            yes=yes,
            strict_channel_priority=strict_channel_priority,
        )
        create_cmd = get_conda_create_command(
            name=name,
            packages=packages,
            channels=channels,
            strict_channel_priority=strict_channel_priority,
        )
        specs = Actions.get_package_specs(
            packages=packages, dependencies=get_dependencies(name=name)["conda"]
        )

        if not channels:
            channels = get_conda_channels()

        dependencies = get_dependencies(name=name)

        history = History.create(
            name=name,
            channels=Channels(channels),
            packages=PackageRevision.create(packages, dependencies=dependencies),
            logs=Logs(create_cmd),
            actions=Actions.create(
                name=name,
                specs=specs,
                channels=Channels(channels),
                strict_channel_priority=strict_channel_priority,
            ),
            diff=Diff.create(packages=packages, dependencies=dependencies),
            debug=Debug.create(name=name),
        )
        env = cls(name=name, history=history, dependencies=dependencies)
        env.export()

        return env
Ejemplo n.º 5
0
 def rebuild(self) -> None:
     """Rebuild the conda environment."""
     logger.debug('If struggling to use an environment try "conda clean --all".')
     delete_conda_environment(name=self.name)
     update_conda_environment(env_dir=self.local_io.env_dir)
     self.update_dependencies()