Skip to content

Commit

Permalink
Add visual padding above/below section headers
Browse files Browse the repository at this point in the history
  • Loading branch information
eecavanna committed Jul 14, 2024
1 parent 4a47072 commit 4610c15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 13 additions & 0 deletions refscan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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("")
9 changes: 6 additions & 3 deletions refscan/refscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 4610c15

Please sign in to comment.