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.
This commit is contained in:
Marty Oehme 2024-02-16 18:01:45 +01:00
parent eaaba00755
commit 74a9d201b5
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -27,6 +27,17 @@ import seaborn as sns
from tabulate import tabulate from tabulate import tabulate
import bibtexparser 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") sns.set_style("whitegrid")
DATA_DIR=Path("./02-data") DATA_DIR=Path("./02-data")
@ -39,12 +50,14 @@ bib_string=""
for partial_bib in RAW_DATA.glob("**/*.bib"): for partial_bib in RAW_DATA.glob("**/*.bib"):
with open(partial_bib) as f: with open(partial_bib) as f:
bib_string+="\n".join(f.readlines()) bib_string+="\n".join(f.readlines())
with all_logging_disabled():
bib_sample_raw_db = bibtexparser.parse_string(bib_string) bib_sample_raw_db = bibtexparser.parse_string(bib_string)
bib_string="" bib_string=""
for partial_bib in WORKING_DATA.glob("**/*.bib"): for partial_bib in WORKING_DATA.glob("**/*.bib"):
with open(partial_bib) as f: with open(partial_bib) as f:
bib_string+="\n".join(f.readlines()) bib_string+="\n".join(f.readlines())
with all_logging_disabled():
bib_sample = bibtexparser.parse_string(bib_string) bib_sample = bibtexparser.parse_string(bib_string)
# load relevant studies # load relevant studies