Cleanup logging (#379)

clean up logging
This commit is contained in:
Matthew Tancik authored and GitHub committed 2022-09-09 10:26:45 -07:00
1 parent 12958ce1c3
commit 6b2485d166
5 files changed
+60 -44

No files matched your search

+8 -5
View File
@@ -5,6 +5,9 @@ from glob import glob
import dcargs
import nbformat as nbf
from rich.console import Console
console = Console(width=120)
def main(check: bool = False):
@@ -28,8 +31,6 @@ def main(check: bool = False):
"# COLLAPSED": "hide-input", # Hide the input w/ a button to show
}
print_yellow = lambda x: print(f"\033[33m{x}\033[0m") # print in yellow
# Search through each notebook and look for the text, add a tag if necessary
any_missing = False
for ipath in notebooks:
@@ -46,7 +47,7 @@ def main(check: bool = False):
found_tags.append(val)
if len(found_keys) > 1:
print_yellow(f"Found multiple tags {found_keys} for {ipath}")
console.print(f"[bold yellow]Found multiple tags {found_keys} for {ipath}")
sys.exit(1)
if len(cell_tags) != len(found_tags):
@@ -58,14 +59,16 @@ def main(check: bool = False):
cell["metadata"]["tags"] = found_tags
if incorrect_metadata:
if check:
print_yellow(f"{ipath} has incorrect metadata. Call `python scripts.docs.add_nb_tags.py` to add it.")
console.print(
f"[bold yellow]{ipath} has incorrect metadata. Call `python scripts.docs.add_nb_tags.py` to add it."
)
any_missing = True
else:
print(f"Adding metadata to {ipath}")
nbf.write(ntbk, ipath)
if not any_missing:
print("All notebooks have correct metadata.")
console.print("[green]All notebooks have correct metadata.")
if check and any_missing:
sys.exit(1)
+11 -9
View File
@@ -3,6 +3,10 @@ import subprocess
import sys
import dcargs
from rich.console import Console
from rich.style import Style
console = Console(width=120)
LOCAL_TESTS = ["Run license checks", "Run Black", "Python Pylint", "Test with pytest"]
@@ -15,7 +19,7 @@ def run_command(command: str) -> None:
"""
ret_code = subprocess.call(command, shell=True)
if ret_code != 0:
print(f"\033[31mError: `{command}` failed. Exiting...\033[0m")
console.print(f"[bold red]Error: `{command}` failed. Exiting...")
sys.exit(1)
@@ -26,22 +30,20 @@ def main(clean_cache: bool = False):
clean_cache: whether to clean the cache before building docs.
"""
print_green = lambda x: print(f"\033[32m{x}\033[0m")
print_green("Adding notebook documentation metadata")
console.print("[green]Adding notebook documentation metadata")
run_command("python scripts/docs/add_nb_tags.py")
# Add checks for building documentation
print_green("Building Documentation")
console.print("[green]Building Documentation")
if clean_cache:
run_command("cd docs/; make clean; make html SPHINXOPTS='-W;'")
else:
run_command("cd docs/; make html SPHINXOPTS='-W;'")
print("\n")
print_green("=" * 100)
print_green("Done")
print_green("=" * 100)
console.line()
console.rule(characters="=", style=Style(color="green"))
console.print("[bold green]Done")
console.rule(characters="=", style=Style(color="green"))
if __name__ == "__main__":