From fbaed331af05c6d0c8181471bdf666e27b04c87a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 7 Apr 2026 05:21:26 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Enhance=20CLI=20UX=20?= =?UTF-8?q?with=20execution=20timing=20and=20visual=20hierarchy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces several micro-UX improvements to the demo scripts: - Replaces `random.choices` with `random.sample` to guarantee unique customer IDs. - Tracks and displays total flow execution duration in the final success panel. - Enhances visual hierarchy by adding descriptive titles to `rich.rule.Rule` components. - Simplifies guidance messages to reduce terminal noise. Co-authored-by: ruh-al-tarikh <203426218+ruh-al-tarikh@users.noreply.github.com> --- 01_getting_started.py | 15 +++++++++++---- 02_logging.py | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/01_getting_started.py b/01_getting_started.py index 8f31d36..f9eec6f 100644 --- a/01_getting_started.py +++ b/01_getting_started.py @@ -14,7 +14,8 @@ def get_customer_ids() -> list[str]: """Fetch customer IDs from a database or API.""" # Use sorted and zero-padded IDs for better terminal alignment - ids = [f"customer-{n:02d}" for n in random.choices(range(100), k=5)] + # Use random.sample to ensure unique customer IDs in the demo + ids = [f"customer-{n:02d}" for n in random.sample(range(100), k=5)] return sorted(ids) @@ -34,6 +35,9 @@ def main(): This flow demonstrates how to map a task over a list of inputs. It fetches a list of customer IDs and processes each one individually. """ + # Start timer to measure total execution duration + start_time = time.perf_counter() + # Display the flow's purpose for a guided onboarding experience if main.__doc__: console.print( @@ -60,6 +64,9 @@ def main(): # Explicitly wait for results to avoid AttributeErrors on futures results = [f.result() for f in futures] + # Calculate duration + duration = time.perf_counter() - start_time + # Display results in a clean table for better readability table = Table( title="Processing Summary", @@ -81,15 +88,15 @@ def main(): console.print( Panel.fit( - f"[bold green]✨ Successfully processed {len(results)} customers![/bold green]", + f"[bold green]✨ Successfully processed {len(results)} customers in {duration:.2f}s![/bold green]", title="Result", border_style="green", ) ) - console.print(Rule(style="blue")) + console.print(Rule("Next Step", style="blue")) console.print( - "[bold blue]➡️ Next Step:[/bold blue] Try running [cyan]python 02_logging.py[/cyan] to learn about logging in Prefect!" + "➡️ Try running [cyan]python 02_logging.py[/cyan] to learn about logging in Prefect!" ) return results diff --git a/02_logging.py b/02_logging.py index 3d14d66..95cda3f 100644 --- a/02_logging.py +++ b/02_logging.py @@ -15,7 +15,8 @@ def get_customer_ids() -> list[str]: """Fetch customer IDs from a database or API.""" # Use sorted and zero-padded IDs for better terminal alignment - ids = [f"customer-{n:02d}" for n in random.choices(range(100), k=5)] + # Use random.sample to ensure unique customer IDs in the demo + ids = [f"customer-{n:02d}" for n in random.sample(range(100), k=5)] return sorted(ids) @@ -43,6 +44,9 @@ def main(): - Use the Prefect logger for structured logging in tasks. - Map tasks across a list of inputs. """ + # Start timer to measure total execution duration + start_time = time.perf_counter() + # Display the flow's purpose for a guided onboarding experience if main.__doc__: console.print( @@ -69,6 +73,9 @@ def main(): # Explicitly wait for results to avoid AttributeErrors on futures results = [f.result() for f in futures] + # Calculate duration + duration = time.perf_counter() - start_time + # Display results in a clean table for better readability table = Table( title="Processing Summary", @@ -90,15 +97,15 @@ def main(): console.print( Panel.fit( - f"[bold green]✨ Successfully processed {len(results)} customers with detailed logging![/bold green]", + f"[bold green]✨ Successfully processed {len(results)} customers with detailed logging in {duration:.2f}s![/bold green]", title="Result", border_style="green", ) ) - console.print(Rule(style="blue")) + console.print(Rule("Conclusion", style="blue")) console.print( - "[bold blue]🎉 You've completed the Quickstart! Check out the [cyan]README.md[/cyan] for more features.[/bold blue]" + "🎉 You've completed the Quickstart! Check out the [cyan]README.md[/cyan] for more features." ) return results