Skip to content

Commit

Permalink
newline
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer committed Jun 9, 2020
1 parent c8d336a commit d585078
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ venv
.DS_Store
dist
build
geckodriver.log
geckodriver.log

46 changes: 30 additions & 16 deletions webviz_config/testing/_monitor_builtin_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
# 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()

0 comments on commit d585078

Please sign in to comment.