def main(prefix, name): # Set prefix conda.set_root_prefix(prefix=prefix) # Remove environment conda.remove_environment(name=name)
def test_envs(self): self.assertIsInstance(conda_api.get_envs(), list) try: path = os.path.join(tempfile.mkdtemp(), 'conda_api_test') clone = os.path.join(tempfile.mkdtemp(), 'conda_api_test_clone') conda_api.create(path=path, pkgs=['python']) conda_api.clone_environment(path, path=clone) self.assertEqual(conda_api.linked(path), conda_api.linked(clone)) conda_api.remove_environment(path=path) conda_api.remove_environment(path=clone) except Exception as e: self.fail('create/remove fails: %s' % e)
def remove_package_with_dependencies(environment, package): # Before we do anything, set the ROOT_PREFIX # variable so conda_api knows where to work from. conda_api.set_root_prefix(get_root_prefix()) # Set the name of the temporary conda environment # we'll work in. temp_env = 'temp_env' # Create the temporary environment in which to do our install test. conda_api.create(temp_env, pkgs=['python']) # Do a fake install of the package we want to remove, # in order to get its "dependencies". install_cmd = shlex.split('{0} install -n {1} {2} --json --dry-run' .format(os.path.join(conda_api.ROOT_PREFIX, 'bin/conda'), temp_env, package)) p = subprocess.Popen(install_cmd, stdout=subprocess.PIPE) stdout, _ = p.communicate() install_response = json.loads(stdout) # Get the dependencies from the JSON that was written # by the conda install command above. regex = re.compile('\S*(?=-[0-9]+)') packages_to_remove = [regex.match(item.split(' ')[0]).group() for item in install_response['actions']['LINK']] # Remove these packages from the actual target environment. remove_response = conda_api.remove(*packages_to_remove, name=environment) print(remove_response) # The below condition should always evaluate to True. # We can expect the above call to conda_api.remove() to throw # a CondaError error if something goes wrong. if remove_response['success']: print('\nThe following packages were successfully removed from {0}:\n\n{1}\n' .format(conda_api.get_prefix_envname(environment), '\n'.join(packages_to_remove))) # Cleanup - delete the temporary conda env. conda_api.remove_environment(temp_env)
def tearDownClass(self): os.remove(self.config) conda_api.remove_environment(path=self.prefix)