IDEA-CR-61079: PY-41267 Add logging for Plots in SciView

GitOrigin-RevId: 742dbc8bf2a602c4f4eebd30a360348fa8b00d01
This commit is contained in:
Elizaveta Shashkova
2020-03-24 20:20:09 +03:00
committed by intellij-monorepo-bot
parent a2ac5cf8c8
commit da322c3294
6 changed files with 87 additions and 15 deletions

View File

@@ -1,9 +1,20 @@
import os
import sys
import traceback
SHOW_DEBUG_INFO = os.getenv('PYCHARM_DEBUG', 'False').lower() in ['true', '1']
def debug(message):
if SHOW_DEBUG_INFO:
sys.stderr.write(message)
sys.stderr.write("\n")
debug("Executing PyCharm's `sitecustomize`")
modules_list = []
try:
import sys
# We want to import users sitecustomize.py file if any
import os
sitecustomize = "sitecustomize"
parent_dir = os.path.abspath(os.path.join(__file__, os.pardir))
if parent_dir in sys.path:
@@ -15,6 +26,7 @@ try:
try:
import sitecustomize
except ImportError:
debug("User doesn't have a custom `sitecustomize`")
# return our module if we failed to find any other sitecustomize
# to prevent KeyError importing 'site.py'
sys.modules[sitecustomize] = pycharm_sitecustomize_module
@@ -33,13 +45,15 @@ try:
if old_getfilesystemencoding:
sys.getfilesystemencoding = old_getfilesystemencoding
matplotlib.use('module://backend_interagg')
debug("Custom matplotlib backend was set for SciView")
except:
# fallback in case matplotlib is not loaded correctly
import sys
traceback.print_exc()
keys = list(sys.modules.keys())
for key in keys:
if modules_list and key not in modules_list:
sys.modules.pop(key)
if modules_list:
for key in keys:
if key not in modules_list:
sys.modules.pop(key)