Skip to content

Commit

Permalink
Merge pull request #49 from kamangir/conda-refactors-2025-01-10-Q7AoMc
Browse files Browse the repository at this point in the history
conda refactors
  • Loading branch information
kamangir authored Jan 11, 2025
2 parents cfa186c + d9f6d83 commit 0f8f346
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ create a copy of [`sample.env`](./abcli/sample.env) as `.env` and fill in the se

[![pylint](https://github.com/kamangir/awesome-bash-cli/actions/workflows/pylint.yml/badge.svg)](https://github.com/kamangir/awesome-bash-cli/actions/workflows/pylint.yml) [![pytest](https://github.com/kamangir/awesome-bash-cli/actions/workflows/pytest.yml/badge.svg)](https://github.com/kamangir/awesome-bash-cli/actions/workflows/pytest.yml) [![bashtest](https://github.com/kamangir/awesome-bash-cli/actions/workflows/bashtest.yml/badge.svg)](https://github.com/kamangir/awesome-bash-cli/actions/workflows/bashtest.yml) [![PyPI version](https://img.shields.io/pypi/v/abcli.svg)](https://pypi.org/project/abcli/) [![PyPI - Downloads](https://img.shields.io/pypi/dd/abcli)](https://pypistats.org/packages/abcli)

built by 🌀 [`blue_options-4.177.1`](https://github.com/kamangir/awesome-bash-cli), based on 🪄 [`abcli-9.458.1`](https://github.com/kamangir/awesome-bash-cli).
built by 🌀 [`blue_options-4.180.1`](https://github.com/kamangir/awesome-bash-cli), based on 🪄 [`abcli-9.460.1`](https://github.com/kamangir/awesome-bash-cli).
63 changes: 0 additions & 63 deletions abcli/.abcli/plugins/conda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,6 @@
function abcli_conda() {
local task=$(abcli_unpack_keyword $1)

if [ "$task" == "help" ]; then
abcli_conda create "$@"
abcli_conda exists "$@"
abcli_conda list "$@"
abcli_conda remove "$@"
return
fi

if [[ "$2" == "help" ]]; then
local options
case $task in
create)
options="${EOP}clone=<auto|base>,~install_plugin,${EOPE}name=<environment-name>${EOP},repo=<repo-name>,~recreate${EOP}"
abcli_show_usage "@conda create$ABCUL$options" \
"create conda environment."
;;
exists)
abcli_show_usage "@conda exists$ABCUL[<environment-name>]" \
"does conda environment exist? true|false."
;;
list)
abcli_show_usage "@conda list" \
"show list of conda environments."
;;
remove | rm)
abcli_show_usage "@conda remove|rm$ABCUL[<environment-name>]" \
"remove conda environment."
;;
*)
abcli_log_error "@conda: $task: command not found."
return 1
;;
esac

return
fi

if [[ ",remove,rm," == *",$task,"* ]]; then
local environment_name=$(abcli_clarify_input $2 abcli)

conda activate base
conda remove -y --name $environment_name --all

return
fi

if [ "$task" == "exists" ]; then
local environment_name=$(abcli_clarify_input $2 abcli)

if conda info --envs | grep -q "^$environment_name "; then
echo 1
else
echo 0
fi

return
fi

if [ "$task" == "list" ]; then
conda info --envs "${@:2}"
return
fi

local function_name="abcli_conda_$task"
if [[ $(type -t $function_name) == "function" ]]; then
$function_name "${@:2}"
Expand Down
12 changes: 12 additions & 0 deletions abcli/.abcli/plugins/conda/exists.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/env bash

function abcli_conda_exists() {
local options=$1
local environment_name=$(abcli_option "$options" name abcli)

if conda info --envs | grep -q "^$environment_name "; then
echo 1
else
echo 0
fi
}
7 changes: 7 additions & 0 deletions abcli/.abcli/plugins/conda/list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /usr/bin/env bash

function abcli_conda_list() {
abcli_eval ,$1 \
conda info \
--envs "${@:2}"
}
20 changes: 20 additions & 0 deletions abcli/.abcli/plugins/conda/rm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /usr/bin/env bash

function abcli_conda_rm() {
local options=$1
local environment_name=$(abcli_option "$options" name abcli)

local exists=$(abcli_conda_exists $environment_name)
if [[ "$exists" == 0 ]]; then
abcli_log_warning "@conda: $environment_name does not exist."
return 0
fi

conda activate base
[[ $? -ne 0 ]] && return 1

abcli_eval ,$options \
conda remove -y \
--name $environment_name \
--all
}
6 changes: 6 additions & 0 deletions abcli/.abcli/tests/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ function test_abcli_help() {
\
"@cat" \
\
"@conda" \
"@conda create" \
"@conda exists" \
"@conda list" \
"@conda rm" \
\
"@docker browse " \
"@docker build " \
"@docker clear " \
Expand Down
2 changes: 1 addition & 1 deletion abcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

DESCRIPTION = f"{ICON} A language to speak AI."

VERSION = "9.458.1"
VERSION = "9.460.1"

REPO_NAME = "awesome-bash-cli"

Expand Down
90 changes: 90 additions & 0 deletions abcli/help/conda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from typing import List

from blue_options.terminal import show_usage, xtra


def help_create(
tokens: List[str],
mono: bool,
) -> str:
options = "".join(
[
xtra("clone=<auto|base>,~install_plugin,", mono=mono),
"name=<environment-name>",
xtra(",repo=<repo-name>,~recreate", mono=mono),
]
)

return show_usage(
[
"@conda",
"create",
f"[{options}]",
],
"create conda environment.",
mono=mono,
)


def help_exists(
tokens: List[str],
mono: bool,
) -> str:
options = "name=<environment-name>"

return show_usage(
[
"@conda",
"exists",
f"[{options}]",
],
"does conda environment exist?",
mono=mono,
)


def help_list(
tokens: List[str],
mono: bool,
) -> str:
options = xtra("dryrun", mono=mono)

return show_usage(
[
"@conda",
"list",
f"[{options}]",
],
"show list of conda environments.",
mono=mono,
)


def help_rm(
tokens: List[str],
mono: bool,
) -> str:
options = "".join(
[
xtra("dryrun,", mono=mono),
"name=<environment-name>",
]
)

return show_usage(
[
"@conda",
"rm",
f"[{options}]",
],
"rm conda environment.",
mono=mono,
)


help_functions = {
"create": help_create,
"exists": help_exists,
"list": help_list,
"rm": help_rm,
}
2 changes: 2 additions & 0 deletions abcli/help/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from abcli.help.aws_batch import help_functions as help_aws_batch
from abcli.help.blueness import help_blueness
from abcli.help.browse import help_browse
from abcli.help.conda import help_functions as help_conda
from abcli.help.cp import help_cp
from abcli.help.docker import help_functions as help_docker
from abcli.help.download import help_download
Expand Down Expand Up @@ -50,6 +51,7 @@
"blueness": help_blueness,
"browse": help_browse,
"cat": help_cat,
"conda": help_conda,
"cp": help_cp,
"docker": help_docker,
"download": help_download,
Expand Down

0 comments on commit 0f8f346

Please sign in to comment.