From d585078f28644d53da6bd6e195a76d63bd2254f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Fredrik=20Ki=C3=A6r?= Date: Tue, 9 Jun 2020 10:06:02 +0200 Subject: [PATCH] newline --- .gitignore | 3 +- .../testing/_monitor_builtin_open.py | 46 ++++++++++++------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index b7017911..1d4022e4 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ venv .DS_Store dist build -geckodriver.log \ No newline at end of file +geckodriver.log + diff --git a/webviz_config/testing/_monitor_builtin_open.py b/webviz_config/testing/_monitor_builtin_open.py index 0b90cd1f..cbf656ed 100644 --- a/webviz_config/testing/_monitor_builtin_open.py +++ b/webviz_config/testing/_monitor_builtin_open.py @@ -8,31 +8,45 @@ WHITELISTED_FILENAMES = ["geckodriver.log", ".pytest-sugar.conf"] WHITELISTED_PREFIXES = ["/tmp"] + site.PREFIXES WHITELISTED_POSTFIXES = [str(Path(".plotly" / Path(".config"))), ".py", ".json"] -WHITELISTED_CONTAINS = [".pytest_cache", "__pycache__", ".cache", ".egg-info", "/dev/null"] +WHITELISTED_CONTAINS = [ + ".pytest_cache", + "__pycache__", + ".cache", + ".egg-info", + "/dev/null", +] import builtins -FUNCTIONS = [("builtins", "open", "filepath"), ("pandas", "read_csv", "filepath"), ("xtgeo", "Well", "self")] +FUNCTIONS = [ + ("builtins", "open", "filepath"), + ("pandas", "read_csv", "filepath"), + ("xtgeo", "Well", "self"), +] -class MonitorBuiltinOpen: +class MonitorBuiltinOpen: def __init__(self): - self._original_functions = [getattr(importlib.import_module(module), function) for module, function, _ in FUNCTIONS] + self._original_functions = [ + getattr(importlib.import_module(module), function) + for module, function, _ in FUNCTIONS + ] def stop_monitoring(self): pass - #builtins.open = self._original_open - #io.open = self._original_open + # builtins.open = self._original_open + # io.open = self._original_open def start_monitoring(self): pass - #def wrapped_open(*args, **kwargs): - #path = str(args[0]) - #if Path(path).name not in WHITELISTED_FILENAMES and str(Path(path).parent) != "." and all([part not in path for part in WHITELISTED_CONTAINS]) and all([not path.startswith(prefix) for prefix in WHITELISTED_PREFIXES]) and all([not path.endswith(postfix) for postfix in WHITELISTED_POSTFIXES]): - # raise RuntimeError(f"File {path} opened, which is not white-listed as a 'portable' location.") - #return self._original_open(*args, **kwargs) - - #builtins.open = wrapped_open - #io.open = wrapped_open - -monitor_builtin_open = MonitorBuiltinOpen() \ No newline at end of file + # def wrapped_open(*args, **kwargs): + # path = str(args[0]) + # if Path(path).name not in WHITELISTED_FILENAMES and str(Path(path).parent) != "." and all([part not in path for part in WHITELISTED_CONTAINS]) and all([not path.startswith(prefix) for prefix in WHITELISTED_PREFIXES]) and all([not path.endswith(postfix) for postfix in WHITELISTED_POSTFIXES]): + # raise RuntimeError(f"File {path} opened, which is not white-listed as a 'portable' location.") + # return self._original_open(*args, **kwargs) + + # builtins.open = wrapped_open + # io.open = wrapped_open + + +monitor_builtin_open = MonitorBuiltinOpen()