From 4610c15e529225aec540f848f97a20e88afc12c9 Mon Sep 17 00:00:00 2001 From: eecavanna Date: Sat, 13 Jul 2024 18:54:24 -0700 Subject: [PATCH] Add visual padding above/below section headers --- refscan/lib/helpers.py | 13 +++++++++++++ refscan/refscan.py | 9 ++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/refscan/lib/helpers.py b/refscan/lib/helpers.py index 3637c62..40027a3 100644 --- a/refscan/lib/helpers.py +++ b/refscan/lib/helpers.py @@ -3,6 +3,7 @@ from pymongo import MongoClient, timeout from linkml_runtime import SchemaView +from rich.console import Console from rich.progress import ( Progress, TextColumn, @@ -121,3 +122,15 @@ def init_progress_bar() -> Progress: def get_lowercase_key(key_value_pair: tuple) -> str: r"""Returns the key from a `(key, value)` tuple, in lowercase.""" return key_value_pair[0].lower() + + +def print_section_header(console: Console, text: str) -> None: + r""" + Helper function that prints a vertically-padded, + labeled, horizontal rule to the specified console. + + Reference: https://rich.readthedocs.io/en/stable/console.html#rules + """ + console.print("") + console.rule(f"[bold]{text}[/bold]") + console.print("") diff --git a/refscan/refscan.py b/refscan/refscan.py index fa41374..7e1dab0 100644 --- a/refscan/refscan.py +++ b/refscan/refscan.py @@ -4,6 +4,7 @@ import typer import linkml_runtime +from rich import padding from refscan.lib.Finder import Finder from refscan.lib.constants import DATABASE_CLASS_NAME, console @@ -13,6 +14,7 @@ derive_schema_class_name_from_document, init_progress_bar, get_lowercase_key, + print_section_header, ) from refscan.lib.Reference import Reference from refscan.lib.ReferenceList import ReferenceList @@ -108,7 +110,8 @@ def scan( console.print(f"refscan version: {app_version}") console.print(f"Schema version: {schema_view.schema.version}") - console.rule("[bold]Identifying references") + # Show a header on the console, to tell the user which stage of execution we're entering. + print_section_header(console, text="Identifying references") # Make a more self-documenting alias for the CLI option that can be specified multiple times. names_of_source_collections_to_skip: list[str] = [] if skip_source_collection is None else skip_source_collection @@ -184,7 +187,7 @@ def scan( if verbose: console.print(references.as_table()) - console.rule("[bold]Scanning for violations") + print_section_header(console, text="Scanning for violations") # Get a dictionary that maps source class names to the names of their fields that can contain references. reference_field_names_by_source_class_name = references.get_reference_field_names_by_source_class_name() @@ -319,7 +322,7 @@ def scan( # Close the connection to the MongoDB server. mongo_client.close() - console.rule("[bold]Results summary") + print_section_header(console, text="Summarizing results") # Create a violation report in TSV format — for all collections combined. all_violations = ViolationList()