diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index 513d85c96..50abd1819 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -127,65 +127,74 @@ namespace Flow.Launcher.Core.Plugin return plugins; } - public static IEnumerable PythonPlugins(List source, string pythonDirecotry) + public static IEnumerable PythonPlugins(List source, string pythonDirectory) { - var metadatas = source.Where(o => o.Language.ToUpper() == AllowedLanguage.Python); - string filename; - - if (string.IsNullOrEmpty(pythonDirecotry)) + // try to set Constant.PythonPath, either from + // PATH or from the given pythonDirectory + if (string.IsNullOrEmpty(pythonDirectory)) { var paths = Environment.GetEnvironmentVariable(PATH); if (paths != null) { - var pythonPaths = paths.Split(';').Where(p => p.ToLower().Contains(Python)); - if (pythonPaths.Any()) + var pythonInPath = paths + .Split(';') + .Where(p => p.ToLower().Contains(Python)) + .Any(); + + if (pythonInPath) { - filename = PythonExecutable; + Constant.PythonPath = PythonExecutable; } else { Log.Error("|PluginsLoader.PythonPlugins|Python can't be found in PATH."); - return new List(); } } else { Log.Error("|PluginsLoader.PythonPlugins|PATH environment variable is not set."); - return new List(); } } else { - var path = Path.Combine(pythonDirecotry, PythonExecutable); + var path = Path.Combine(pythonDirectory, PythonExecutable); if (File.Exists(path)) { - filename = path; + Constant.PythonPath = path; } else { - Log.Error("|PluginsLoader.PythonPlugins|Can't find python executable in (); + Log.Error($"|PluginsLoader.PythonPlugins|Can't find python executable in {path}"); } } - Constant.PythonPath = filename; - var plugins = metadatas.Select(metadata => new PluginPair + + // if we have a path to the python executable, + // load every python plugin pair. + if (String.IsNullOrEmpty(Constant.PythonPath)) { - Plugin = new PythonPlugin(filename), - Metadata = metadata - }); - return plugins; + return new List(); + } + else + { + return source + .Where(o => o.Language.ToUpper() == AllowedLanguage.Python) + .Select(metadata => new PluginPair + { + Plugin = new PythonPlugin(Constant.PythonPath), + Metadata = metadata + }); + } } public static IEnumerable ExecutablePlugins(IEnumerable source) { - var metadatas = source.Where(o => o.Language.ToUpper() == AllowedLanguage.Executable); - - var plugins = metadatas.Select(metadata => new PluginPair - { - Plugin = new ExecutablePlugin(metadata.ExecuteFilePath), - Metadata = metadata - }); - return plugins; + return source + .Where(o => o.Language.ToUpper() == AllowedLanguage.Executable) + .Select(metadata => new PluginPair + { + Plugin = new ExecutablePlugin(metadata.ExecuteFilePath), + Metadata = metadata + }); } }