From de1cf2cd10676a818f7d0171dc83560b00ba0b7d Mon Sep 17 00:00:00 2001 From: Stefan du Fresne Date: Thu, 2 Feb 2017 13:02:35 +0000 Subject: [PATCH] Only re-set path when preference changes Because preferences change when you do lots of things like change font size, and because working out the path is quite costly, only do it the first time the plugin is loaded, or if the additional_path_items preference changes. --- FixPath.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/FixPath.py b/FixPath.py index e338598..cf285b5 100644 --- a/FixPath.py +++ b/FixPath.py @@ -14,6 +14,7 @@ def isMac(): if isMac(): fixPathSettings = None + lastAdditionalPathItems = None originalEnv = {} def getSysPath(): @@ -34,17 +35,24 @@ def getSysPath(): def fixPath(): - currSysPath = getSysPath() - # Basic sanity check to make sure our new path is not empty - if len(currSysPath) < 1: - return False + additionalPathItems = fixPathSettings.get("additional_path_items", []); - environ['PATH'] = currSysPath + # Only do work if path items changes + global lastAdditionalPathItems + if additionalPathItems != lastAdditionalPathItems: + lastAdditionalPathItems = additionalPathItems - for pathItem in fixPathSettings.get("additional_path_items", []): - environ['PATH'] = pathItem + ':' + environ['PATH'] + currSysPath = getSysPath() + # Basic sanity check to make sure our new path is not empty + if len(currSysPath) < 1: + return False - return True + environ['PATH'] = currSysPath + + for pathItem in additionalPathItems: + environ['PATH'] = pathItem + ':' + environ['PATH'] + + return True def plugin_loaded():