Skip to content

Commit

Permalink
Add soap list command
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshanuikabundi committed Feb 7, 2023
1 parent f74d502 commit 4638c17
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
1 change: 0 additions & 1 deletion soap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ user = "devtools/conda-envs/user_env.yml"
docs = "devtools/conda-envs/docs_env.yml"

[aliases]
list = "conda list"
greet = "echo hello world"

[aliases.docs]
Expand Down
73 changes: 73 additions & 0 deletions soap/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import typer
from typer import Argument, Option, Typer, echo
import rich, rich.tree

import soap
from soap.utils import get_git_root
Expand Down Expand Up @@ -134,6 +135,78 @@ def run(
exit(e.returncode)


@app.command()
def list(
verbosity: int = typer.Option(
0,
"--verbose",
"-v",
count=True,
help="Present more information.",
)
):
"""List the available environments."""
cfg = soap.Config()

if verbosity < 3:
captions = [
"📦 Is the root package installed in this environment?",
"🪧 Number of additional channels\n📥 Number of additional dependencies",
]

table = rich.table.Table(
title="Snakes on a Plane environments",
caption="\n" + "\n".join(captions[:verbosity]),
caption_justify="left",
caption_style="dim",
box=rich.box.SIMPLE,
show_edge=False,
)

table.add_column("Name", style="bold")
table.add_column("YML path")
if verbosity > 0:
table.add_column("📦")
if verbosity > 1:
table.add_column("🪧")
table.add_column("📥")

for env in cfg.envs.values():
row = [env.name, str(env.yml_path)]
if verbosity > 0:
row.append("✓" if env.install_current else "")
if verbosity > 1:
row.append(str(len(env.additional_channels)))
row.append(str(len(env.additional_dependencies)))

table.add_row(*row)

rich.print(table)
else:
tree = rich.tree.Tree("[i]Snakes on a Plane environments", guide_style="dim")

for env in cfg.envs.values():
branch = tree.add(f"[cyan bold]{env.name}")
yml_branch = branch.add(f"[b]YAML path:[/b] {env.yml_path}")
branch.add(f"[b]Environment path:[/b] {env.env_path}")
environment_exists = (
"Yes" if (env.env_path / "conda-meta").exists() else "No"
)
branch.add(f"[b]Environment exists?:[/b] {environment_exists}")
branch.add(f"[b]Install root package:[/b] {env.install_current}")
if env.additional_channels or verbosity > 3:
branch.add(f"[b]Additional channels:[/b] {env.additional_channels}")
if env.additional_dependencies or verbosity > 3:
branch.add(
f"[b]Additional dependencies:[/b] {env.additional_dependencies}"
)
if verbosity > 3:
syntax = rich.syntax.Syntax(env.yml_path.read_text(), "yaml")
yml_branch.add(syntax)

rich.print(tree)


_click = typer.main.get_command(app)

if __name__ == "__main__":
Expand Down

0 comments on commit 4638c17

Please sign in to comment.