From 74a9d201b511cac6378e669af9136cf3b496da66 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 16 Feb 2024 18:01:45 +0100 Subject: [PATCH] fix(script): Suppress bibtex warning on import When first importing bibtex entries, if there are e.g. double entries, the library gives an 'unsuppressable' warning which will always appear in the manuscript otherwise. This simply ensures no warning is displayed by turning off logging for the duration of their use. --- scoping_review.qmd | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scoping_review.qmd b/scoping_review.qmd index 71dbb3f..1ec5aa6 100644 --- a/scoping_review.qmd +++ b/scoping_review.qmd @@ -27,6 +27,17 @@ import seaborn as sns from tabulate import tabulate import bibtexparser +from contextlib import contextmanager +import logging +@contextmanager +def all_logging_disabled(highest_level=logging.CRITICAL): + previous_level = logging.root.manager.disable + logging.disable(highest_level) + try: + yield + finally: + logging.disable(previous_level) + sns.set_style("whitegrid") DATA_DIR=Path("./02-data") @@ -39,13 +50,15 @@ bib_string="" for partial_bib in RAW_DATA.glob("**/*.bib"): with open(partial_bib) as f: bib_string+="\n".join(f.readlines()) -bib_sample_raw_db = bibtexparser.parse_string(bib_string) +with all_logging_disabled(): + bib_sample_raw_db = bibtexparser.parse_string(bib_string) bib_string="" for partial_bib in WORKING_DATA.glob("**/*.bib"): with open(partial_bib) as f: bib_string+="\n".join(f.readlines()) -bib_sample = bibtexparser.parse_string(bib_string) +with all_logging_disabled(): + bib_sample = bibtexparser.parse_string(bib_string) # load relevant studies from src import load_data