From 43c336071f11c17a49f237c63ddcefe18a8ef6a2 Mon Sep 17 00:00:00 2001 From: Oscar Campos Date: Fri, 31 Oct 2014 19:30:53 +0000 Subject: [PATCH 1/2] Fixes #231 * Fix #231 When an environment hook file (.anaconda) was present but it could not being parsed as valid JSON, anaconda loops forever. Added gracefully fail and show an error message to inform the user about the problem in the hook file. --- anaconda_lib/helpers.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/anaconda_lib/helpers.py b/anaconda_lib/helpers.py index 774f44c2..071cb1f3 100644 --- a/anaconda_lib/helpers.py +++ b/anaconda_lib/helpers.py @@ -29,6 +29,8 @@ NOT_SCRATCH = 0x02 LINTING_ENABLED = 0x04 +ENVIRON_HOOK_INVALID = False + def is_code(view, lang='python', ignore_comments=False, ignore_repl=False): """Determine if the given view location is `lang` code @@ -132,12 +134,15 @@ def get_settings(view, name, default=None): """Get settings """ + global ENVIRON_HOOK_INVALID + if view is None: return default plugin_settings = sublime.load_settings('Anaconda.sublime-settings') - if name in ('python_interpreter', 'extra_paths'): + if (name in ('python_interpreter', 'extra_paths') + and not ENVIRON_HOOK_INVALID): if view.window() is not None and view.window().folders(): dirname = view.window().folders()[0] while True: @@ -148,7 +153,18 @@ def get_settings(view, name, default=None): try: data = json.loads(jsonfile.read()) except Exception as error: - print(error) + sublime.error_message( + "Anaconda Message:\n" + "I found an .anaconda environemnt file in {} " + "path but it doesn't seems to be a valid JSON " + "file.\n\nThat means that your .anaconda " + "hook file is being ignored.".format( + environfile + ) + ) + logging.error(error) + ENVIRON_HOOK_INVALID = True + break # stop loop else: return data.get( name, From 1caf9344fda46dd5cc45fef502382d9625bfc4c1 Mon Sep 17 00:00:00 2001 From: Oscar Campos Date: Fri, 31 Oct 2014 19:44:12 +0000 Subject: [PATCH 2/2] Fixed typos and improved fix for #231 * Fixed misspelled word environment in error message * Improved condition to show try to get the python_environment in the hook file depending on the view identification --- anaconda_lib/helpers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/anaconda_lib/helpers.py b/anaconda_lib/helpers.py index 071cb1f3..6741f78b 100644 --- a/anaconda_lib/helpers.py +++ b/anaconda_lib/helpers.py @@ -13,6 +13,7 @@ import functools import traceback import subprocess +from collections import defaultdict import sublime @@ -29,7 +30,7 @@ NOT_SCRATCH = 0x02 LINTING_ENABLED = 0x04 -ENVIRON_HOOK_INVALID = False +ENVIRON_HOOK_INVALID = defaultdict(lambda: False) def is_code(view, lang='python', ignore_comments=False, ignore_repl=False): @@ -142,7 +143,7 @@ def get_settings(view, name, default=None): plugin_settings = sublime.load_settings('Anaconda.sublime-settings') if (name in ('python_interpreter', 'extra_paths') - and not ENVIRON_HOOK_INVALID): + and not ENVIRON_HOOK_INVALID[view.id()]): if view.window() is not None and view.window().folders(): dirname = view.window().folders()[0] while True: @@ -155,7 +156,7 @@ def get_settings(view, name, default=None): except Exception as error: sublime.error_message( "Anaconda Message:\n" - "I found an .anaconda environemnt file in {} " + "I found an .anaconda environment file in {} " "path but it doesn't seems to be a valid JSON " "file.\n\nThat means that your .anaconda " "hook file is being ignored.".format( @@ -163,7 +164,7 @@ def get_settings(view, name, default=None): ) ) logging.error(error) - ENVIRON_HOOK_INVALID = True + ENVIRON_HOOK_INVALID[view.id()] = True break # stop loop else: return data.get(