From 9bdc984e751000818e96b55e7dcf0825ad146529 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Fri, 8 Jan 2016 16:10:45 -0800 Subject: [PATCH] Fix ST3 plugin directory detection --- git/__init__.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/git/__init__.py b/git/__init__.py index 210deb29..f92803f4 100644 --- a/git/__init__.py +++ b/git/__init__.py @@ -14,15 +14,19 @@ # Goal is to get: "Packages/Git", allowing for people who rename things -def find_plugin_directory(f): - dirname = os.path.split(os.path.dirname(f))[-1] +def find_plugin_directory(): + if __file__.startswith('./'): + # ST2, we get "./git/__init__.py" which is pretty useless since we want the part above that + # However, os.getcwd() is the plugin directory! + full = os.getcwd() + else: + # In a complete inversion, in ST3 when a plugin is loaded we + # actually can trust __file__. It'll be something like: + # /Users/dlynch/Library/Application Support/Sublime Text 3/Packages/Git/git/__init__.py + full = os.path.normpath(os.path.join(os.path.dirname(__file__), '..')) + dirname = os.path.split(full)[-1] return "Packages/" + dirname.replace(".sublime-package", "") -if __file__.startswith('./'): - PLUGIN_DIRECTORY = os.getcwd().replace(os.path.normpath(os.path.join(os.getcwd(), '..', '..')) + os.path.sep, '').replace(os.path.sep, '/') -else: - # In a complete inversion from ST2, in ST3 when a plugin is loaded we - # actually can trust __file__. - PLUGIN_DIRECTORY = find_plugin_directory(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) +PLUGIN_DIRECTORY = find_plugin_directory() def main_thread(callback, *args, **kwargs):