diff --git a/README.markdown b/README.markdown index 1f86d05..c4e288c 100755 --- a/README.markdown +++ b/README.markdown @@ -42,6 +42,7 @@ Go to `Project > Edit Project` to change project settings. { "Stylus": { + "binDir": "./node_modules/.bin", "compress": false, "compileOnSave": true, "compileDir": "out" diff --git a/Stylus.py b/Stylus.py index f379afa..f23b235 100644 --- a/Stylus.py +++ b/Stylus.py @@ -58,11 +58,20 @@ def _run(cmd, args=[], source="", cwd=None, env=None): okay = proc.returncode == 0 return {"okay": okay, "out": stat[0].decode(locale.getdefaultlocale()[1]), "err": stat[1].decode(locale.getdefaultlocale()[1])} else: + bindir = settings_get('binDir', '/usr/local/bin') + if bindir.startswith("./"): + bindir = current_project_folder() + bindir[1:] + if env is None: - env = {"PATH": settings_get('binDir', '/usr/local/bin')} + env = {"PATH": bindir} # adding custom PATHs from settings customEnv = settings_get('envPATH', "") + + # adding environment path + if len(os.environ.get("PATH")): + env["PATH"] = env["PATH"]+":"+os.environ.get("PATH") + if customEnv: env["PATH"] = env["PATH"]+":"+customEnv if source == "": @@ -75,6 +84,27 @@ def _run(cmd, args=[], source="", cwd=None, env=None): return {"okay": okay, "out": stat[0].decode('utf-8'), "err": stat[1].decode('utf-8')} +# From https://github.com/pderichs/sublime_rubocop/blob/master/rubocop_command.py +# Return the the first path of the project +def current_project_folder(): + if int(sublime.version()) >= 3000: + project = sublime.active_window().project_data() + project_base_path = os.path.dirname(sublime.active_window().project_file_name()) + if not (project is None): + if 'folders' in project: + folders = project['folders'] + if len(folders) > 0: + first_folder = folders[0] + if 'path' in first_folder: + path = first_folder['path'] + return (path if os.path.isabs(path) else os.path.join(project_base_path, path)) or '' + else: + folders = sublime.active_window().folders() + if (not (folders is None)) and (len(folders) > 0): + return folders[0] + return '' + + def isStylus(view=None): if view is None: view = sublime.active_window().active_view() diff --git a/Stylus.sublime-settings b/Stylus.sublime-settings index 26d69c3..e3f618d 100644 --- a/Stylus.sublime-settings +++ b/Stylus.sublime-settings @@ -12,6 +12,8 @@ /* The directory containing your stylus binary. Usually /usr/local/bin or /usr/bin. + If binDir begins with "./", then it is replaced by the first path of the project. + Set bindir to "./node_modules/.bin", and it will use the locally installed coffee. */ "binDir": "/usr/local/bin",