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

Better CLI output #388

Closed
pringshia opened this issue Feb 3, 2021 · 4 comments · Fixed by #869
Closed

Better CLI output #388

pringshia opened this issue Feb 3, 2021 · 4 comments · Fixed by #869
Assignees
Labels
help wanted Extra attention is needed proposal

Comments

@pringshia
Copy link
Contributor

pringshia commented Feb 3, 2021

It would be great to think of Mephisto's output from a user-first perspective. Here's a mockup of what a more friendly output stream could look like. In this case, I move away from just using logging as output as mentioned in #386 and focus on a more first-class support for CLI output.

GIF:

rich_print

Still image:

Screen Shot 2021-02-03 at 4 32 52 PM


Mockup source:

Requires the rich package, pip install rich:

from time import sleep
from rich.console import Console
from rich.prompt import Confirm

console = Console()
DELAY_OFF = 0

def print_summary(task):
    from rich.table import Table, Column
    from rich import box
    import locale
    locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') 

    table = Table("property", Column("value", style="magenta bold"), "description", title="Task Launch Preview", box=box.ROUNDED, expand=True, show_lines=True)
    # table = Table("task_name", "blueprint", "architect", "crowd provider", "requester", title="Task Launch Preview")
    # table.add_row("my_custom_task", "simple_static_task", "local", "mturk_sanbox", "demo")
    table.add_row("task_name", "my_custom_task", "ID used to later query all HITs launched in this run.\nConfigure via: task.task_name.")
    table.add_row("blueprint", "simple_static_task", "The base template for your task. Can be found in the folder: mephisto/abstractions/blueprints.")
    table.add_row("architect", "local", "Where this task will be hosted/launched from. Configure via: mephisto/architect=...")
    table.add_row("crowd provider", "mturk_sandbox", "The underlying platform that supplies the crowdworkers (e.g. mturk, mturk_sandbox).")
    table.add_row("requester", "demo", "The account/budget to run the task through. Configure via: mephisto.provider.requester_name=... Or use the mephisto CLI for more info: 'mephisto requesters'")


    console.print(table)

    billing_table = Table("num HITs", "price", "estimated total", title="Estimated Costs")
    billing_table.add_row(str(task['hits']), locale.currency(0.02), f"[bold green]{locale.currency(task['hits'] * 0.02)}[/bold green]")
    console.print(billing_table)

def log(category, message):
    return f"[dim]{category}[/dim] - {message}"

def prepare_router():
    console.log(log("router/install", "npm install (hidden, show with 'build.show_npm_output: true')"))
    sleep(1 * DELAY_OFF)
    console.log(log("router/install", "npm build (hidden, show with 'build.show_npm_output: true')"))
    sleep(2 * DELAY_OFF)
    console.log(log("router/install", "completed npm build"))
    console.log(log("operator/launch", "created a task run under name: 'react-static-task-example'"))

def prepare_architect():
    console.log(log("architect/deploy", "building payload"))
    sleep(1 * DELAY_OFF)
    console.log(log("architect/deploy", "sending payload to final destination"))
    sleep(2 * DELAY_OFF)
    console.log(log("architect/deploy", "deployed successfully"))





def launch_tasks(console):
    from rich.emoji import Emoji
    preview_url = "http://localhost:3000"
    assignment_url = "http://localhost:3000/?worker_id=x&assignment_id="
    for job in range(3):
        # console.log(f":rocket: Launched Assignment {job+1}. Preview: '{preview_url}' | Assignment: '{assignment_url}{job+1}'")
        console.log(log(f":rocket: assignment/launch", f"assignment ID: {job+1}\nPreview: '{preview_url}'\nAssignment: '{assignment_url}{job+1}'"))
        sleep(0.1)
    sleep(2 * DELAY_OFF)


def start():
    task = { "hits": 500}
    print_summary(task)
    confirm = Confirm.ask(f"[bold]Are you sure you would like to proceed launching {task['hits']} HITs?[/bold]")
    if not confirm:
        return

    with console.status("[bold green]Setting up router...") as status:
        prepare_router()
    with console.status("[bold green]Invoking architect...") as status:
        prepare_architect()


    from rich.progress import Progress
    with Progress(transient=True) as progress:
        task = progress.add_task("[bold green]Launching tasks...", total=3)
        sleep(1)

        launch_tasks(progress.console)
        # simulate completion:
        for job in range(3):
            sleep(1.5)
            if job == 1:
                progress.console.log(log(f"[yellow]:hourglass: assignment/update", f"Assignment {job+1} timed-out."))
            else:
                progress.console.log(log(f"[green]:inbox_tray: assignment/update", f"Assignment {job+1} received."))
            progress.advance(task)

        sleep(1)



    console.log("Finished launching 3 tasks.")

    # with console.status("[bold green]Launching tasks...", spinner="earth") as status:
    #     launch_tasks()


start()
@JackUrb
Copy link
Contributor

JackUrb commented Jul 25, 2022

Adding this to a milestone, as considering we already have rich as part of elsewhere in our CLI it shouldn't be a large stretch to get it running for task launches as well.

@Etesam913
Copy link
Contributor

Etesam913 commented Jul 28, 2022

Are you referring to any specific commands or are you just talking about the logging messages in general?

Edit:
Are you referring to the logging messages when python run_task.py is ran?

@mjkanji
Copy link
Contributor

mjkanji commented Nov 8, 2022

@JackUrb @pringshia I don't think #869 really covers everything suggested in this issue (as that PR only covers logging and this is more about the output when running the task itself).

I'd suggest re-opening this issue.

@JackUrb
Copy link
Contributor

JackUrb commented Nov 9, 2022

Logging was a pretty serious concern for this experience, but I do see that there's more to it. I'd suggest having a different issue for the Mephisto Operator TUI instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed proposal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants