From 5c34a3cd1447fd37523a539d152dc94f513c79ea Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Thu, 4 Oct 2018 14:34:48 -0600 Subject: [PATCH] move warning filtering into compatibility module --- dbt/compat.py | 9 +++++++++ dbt/logger.py | 5 +---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dbt/compat.py b/dbt/compat.py index 0e450552326..7e8b5982a32 100644 --- a/dbt/compat.py +++ b/dbt/compat.py @@ -1,5 +1,6 @@ import codecs import json +import warnings WHICH_PYTHON = None @@ -51,3 +52,11 @@ def write_file(path, s): else: with open(path, 'w') as f: return f.write(to_string(s)) + +def suppress_warnings(): + # in python 2, ResourceWarnings don't exist. + # in python 3, suppress ResourceWarnings about unclosed sockets, as the + # bigquery library never closes them. + if WHICH_PYTHON == 3: + warnings.filterwarnings("ignore", category=ResourceWarning, + message="unclosed.*") diff --git a/dbt/logger.py b/dbt/logger.py index ced08ff2a9a..11f19ec0b07 100644 --- a/dbt/logger.py +++ b/dbt/logger.py @@ -50,10 +50,7 @@ # Redirect warnings through our logging setup # They will be logged to a file below logging.captureWarnings(True) -# suppress ResourceWarnings about unclosed sockets, as the bigquery library -# never closes them -warnings.filterwarnings("ignore", category=ResourceWarning, - message="unclosed.*") +dbt.compat.suppress_warnings() initialized = False