Skip to content

Commit

Permalink
Merge branch 'topic/default/fix-uninstall' into 'branch/default'
Browse files Browse the repository at this point in the history
Fix get_env_names

See merge request fluiddyn/conda-app!11
  • Loading branch information
paugier committed Nov 6, 2024
2 parents a5603ce + ea1a13e commit 19ef19e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ jobs:
python -m pip install -e .
which conda-app
- name: test install mercurial
- name: test install mercurial and pipx
run: |
conda-app install mercurial
conda-app list
conda-app install pipx python=3.12
conda env list
conda-app list
conda-app uninstall pipx -y
conda-app list
- name: test installed mercurial
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ jobs:
- name: test install mercurial
run: |
conda-app install mercurial
conda-app list
- name: test install pipx
run: |
conda-app install pipx python=3.12
conda env list
conda-app list
pipx --version
conda-app uninstall pipx -y
- name: test installed mercurial
run: |
Expand Down
6 changes: 5 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ test-run:
- conda --version
- pip install .
- conda-app install mercurial
- . ~/.bashrc
- conda-app install pipx python=3.11
- conda env list
- . ~/.bashrc
- which pipx
- pipx --version
- conda-app uninstall pipx -y
- conda env list
- hg debuginstall
- mkdir -p $HOME/tmp
- cd $HOME/tmp
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "pdm.backend"

[project]
name = "conda-app"
version = "0.4.2"
version = "0.4.3"
description = "Install applications with conda"
authors = [
{name = "Pierre Augier"},
Expand Down
48 changes: 31 additions & 17 deletions src/conda_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,11 @@ def get_conda_data():

def get_env_names(conda_data):
envs = conda_data["envs"]
path_root = conda_data["root_prefix"]
env_names = []
for path_env in envs:
if path_env.startswith(path_root):
path_env = path_env[len(path_root) + 1 :]
if path_env.startswith("envs" + os.path.sep):
path_env = path_env[5:]

env_names.append(path_env)
for path_envs_dir in conda_data["envs_dirs"]:
for path_env in envs:
if path_env.startswith(path_envs_dir):
env_names.append(path_env[len(path_envs_dir) + 1 :])
return env_names


Expand All @@ -201,12 +197,22 @@ def load_data():
return data


def _write_data(data):
with _open(path_data, "w") as file:
json.dump(data, file)


def add_to_app_list(app_name):
data = load_data()
if app_name not in data["installed_apps"]:
data["installed_apps"].append(app_name)
with _open(path_data, "w") as file:
json.dump(data, file)
_write_data(data)


def remove_from_app_list(app_name):
data = load_data()
data["installed_apps"].remove(app_name)
_write_data(data)


CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
Expand Down Expand Up @@ -378,24 +384,32 @@ def install(app_name, other_packages=None):

@main.command(context_settings=CONTEXT_SETTINGS)
@click.argument("app_name")
def uninstall(app_name):
@click.option("-y", "--yes", is_flag=True)
def uninstall(app_name, yes):
"""Uninstall an application."""
conda_data = get_conda_data()
env_names = get_env_names(conda_data)

env_name = "_env_" + app_name

if env_name not in env_names:
print("Nothing to do")
print(f"{app_name} not installed with conda-app: nothing to do")
return

if query_yes_no(f"The application {app_name} will be uninstalled.\nProceed"):
if not yes:
yes = query_yes_no(f"The application {app_name} will be uninstalled.\nProceed")

if yes:
import shutil

path_root = conda_data["root_prefix"]
env_path = Path(path_root) / "envs" / env_name
shutil.rmtree(env_path, ignore_errors=True)
print(f"Directory {env_path} removed")
for env_path in conda_data["envs"]:
if env_path.endswith(os.path.sep + env_name):
shutil.rmtree(env_path, ignore_errors=True)
print(f"Directory {env_path} removed")
remove_from_app_list(app_name)
break
else:
assert False, "Environment not found."


@main.command(name="list", context_settings=CONTEXT_SETTINGS)
Expand Down

0 comments on commit 19ef19e

Please sign in to comment.