Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workspace selection to register flow #435

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions latch_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ def execute(
type=bool,
help="Skip the confirmation dialog.",
)
@click.option(
"-w",
"--skip-workspace-selection",
is_flag=True,
default=False,
type=bool,
help="Skip workspace selection.",
)
@click.option(
"--open",
"-o",
Expand Down Expand Up @@ -419,6 +427,7 @@ def register(
remote: bool,
docker_progress: str,
yes: bool,
skip_workspace_selection: bool,
open: bool,
snakefile: Optional[Path],
cache_tasks: bool,
Expand All @@ -440,6 +449,7 @@ def register(
disable_auto_version=disable_auto_version,
remote=remote,
skip_confirmation=yes,
skip_workspace_selection=skip_workspace_selection,
open=open,
snakefile=snakefile,
progress_plain=(docker_progress == "auto" and not sys.stdout.isatty())
Expand Down
37 changes: 27 additions & 10 deletions latch_cli/services/register/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import click
import gql
import latch_sdk_gql.execute as l_gql
from latch_sdk_config.user import user_config
from scp import SCPClient

from latch.utils import current_workspace, get_workspaces
from latch_cli.click_utils import bold, color
from latch_cli.services.workspace import workspace_tui

from ...centromere.ctx import _CentromereCtx
from ...centromere.utils import MaybeRemoteDir
Expand Down Expand Up @@ -273,6 +276,7 @@ def register(
remote: bool = False,
open: bool = False,
skip_confirmation: bool = False,
skip_workspace_selection: bool = False,
snakefile: Optional[Path] = None,
progress_plain: bool = False,
cache_tasks: bool = False,
Expand Down Expand Up @@ -330,6 +334,29 @@ def register(
click.secho("\n`snakemake` package is not installed.", fg="red", bold=True)
sys.exit(1)

workspaces = get_workspaces()
ws_name = next(
(
x[1]
for x in workspaces.items()
if x[0] == current_workspace()
or (current_workspace() == "" and x[1] == "Personal Workspace")
),
"N/A",
)

if not skip_workspace_selection:
if click.confirm(
f"Workflow will be registered to {ws_name} ({current_workspace()})."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it makes sense to have both ws_name and account_id
ik its unlikely but possible for ws names to be the same lol

" Use a different workspace?"
):
updated = workspace_tui()
if updated is None:
click.secho("Cancelled", bold=True)
return

user_config.update_workspace(**updated)

with _CentromereCtx(
Path(pkg_root),
disable_auto_version=disable_auto_version,
Expand All @@ -348,16 +375,6 @@ def register(
)
click.echo(" ".join([click.style("Version:", fg="bright_blue"), ctx.version]))

workspaces = get_workspaces()
ws_name = next(
(
x[1]
for x in workspaces.items()
if x[0] == current_workspace()
or (current_workspace() == "" and x[1] == "Personal Workspace")
),
"N/A",
)
click.echo(
" ".join([
click.style("Target workspace:", fg="bright_blue"),
Expand Down
37 changes: 20 additions & 17 deletions latch_cli/services/workspace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, TypedDict
from typing import List, Optional, TypedDict

import click
from latch_sdk_config.user import user_config
Expand All @@ -12,12 +12,7 @@ class WSInfo(TypedDict):
name: str


def workspace():
"""Opens a terminal user interface in which a user can select the workspace
the want to switch to.

Like `get_executions`, this function should only be called from the CLI.
"""
def workspace_tui() -> Optional[WSInfo]:
data = get_workspaces()

old_id = current_workspace()
Expand All @@ -32,22 +27,30 @@ def workspace():
if id == old_id:
display_name = f"{name}{selected_marker}"

options.append(
{
"display_name": display_name,
"value": {
"workspace_id": id,
"name": name,
},
}
)
options.append({
"display_name": display_name,
"value": {
"workspace_id": id,
"name": name,
},
})

selected_option = select_tui(
return select_tui(
title="Select Workspace",
options=options,
clear_terminal=False,
)


def workspace():
"""Opens a terminal user interface in which a user can select the workspace
the want to switch to.

Like `get_executions`, this function should only be called from the CLI.
"""
old_id = current_workspace()

selected_option = workspace_tui()
if selected_option is None:
return

Expand Down
Loading