From db253cdaf8d61747afb32ce9a9e32bca36cd444e Mon Sep 17 00:00:00 2001 From: Alekhya Reddy Date: Mon, 23 Mar 2020 15:23:09 -0700 Subject: [PATCH] Removed python path and python plugin functions --- .../launcher/Wox.Core/Plugin/PluginsLoader.cs | 52 +-------------- .../launcher/Wox.Core/Plugin/PythonPlugin.cs | 64 ------------------- src/modules/launcher/Wox.Core/Wox.Core.csproj | 1 - .../Exception/ExceptionFormatter.cs | 1 - .../launcher/Wox.Infrastructure/Wox.cs | 1 - .../launcher/Wox.Plugin/AllowedLanguage.cs | 8 +-- .../launcher/Wox/Helper/ErrorReporting.cs | 3 +- 7 files changed, 3 insertions(+), 127 deletions(-) delete mode 100644 src/modules/launcher/Wox.Core/Plugin/PythonPlugin.cs diff --git a/src/modules/launcher/Wox.Core/Plugin/PluginsLoader.cs b/src/modules/launcher/Wox.Core/Plugin/PluginsLoader.cs index 3f5f9ad320..bcfe72a843 100644 --- a/src/modules/launcher/Wox.Core/Plugin/PluginsLoader.cs +++ b/src/modules/launcher/Wox.Core/Plugin/PluginsLoader.cs @@ -20,9 +20,8 @@ namespace Wox.Core.Plugin public static List Plugins(List metadatas, PluginsSettings settings) { var csharpPlugins = CSharpPlugins(metadatas).ToList(); - var pythonPlugins = PythonPlugins(metadatas, settings.PythonDirectory); var executablePlugins = ExecutablePlugins(metadatas); - var plugins = csharpPlugins.Concat(pythonPlugins).Concat(executablePlugins).ToList(); + var plugins = csharpPlugins.Concat(executablePlugins).ToList(); return plugins; } @@ -87,55 +86,6 @@ namespace Wox.Core.Plugin return plugins; } - public static IEnumerable PythonPlugins(List source, string pythonDirecotry) - { - var metadatas = source.Where(o => o.Language.ToUpper() == AllowedLanguage.Python); - string filename; - - if (string.IsNullOrEmpty(pythonDirecotry)) - { - var paths = Environment.GetEnvironmentVariable(PATH); - if (paths != null) - { - var pythonPaths = paths.Split(';').Where(p => p.ToLower().Contains(Python)); - if (pythonPaths.Any()) - { - filename = 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); - if (File.Exists(path)) - { - filename = path; - } - else - { - Log.Error("|PluginsLoader.PythonPlugins|Can't find python executable in (); - } - } - Constant.PythonPath = filename; - var plugins = metadatas.Select(metadata => new PluginPair - { - Plugin = new PythonPlugin(filename), - Metadata = metadata - }); - return plugins; - } - public static IEnumerable ExecutablePlugins(IEnumerable source) { var metadatas = source.Where(o => o.Language.ToUpper() == AllowedLanguage.Executable); diff --git a/src/modules/launcher/Wox.Core/Plugin/PythonPlugin.cs b/src/modules/launcher/Wox.Core/Plugin/PythonPlugin.cs deleted file mode 100644 index 95a7d863e6..0000000000 --- a/src/modules/launcher/Wox.Core/Plugin/PythonPlugin.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using Wox.Infrastructure; -using Wox.Plugin; - -namespace Wox.Core.Plugin -{ - internal class PythonPlugin : JsonRPCPlugin - { - private readonly ProcessStartInfo _startInfo; - public override string SupportedLanguage { get; set; } = AllowedLanguage.Python; - - public PythonPlugin(string filename) - { - _startInfo = new ProcessStartInfo - { - FileName = filename, - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardOutput = true, - RedirectStandardError = true, - }; - - // temp fix for issue #667 - var path = Path.Combine(Constant.ProgramDirectory, JsonRPC); - _startInfo.EnvironmentVariables["PYTHONPATH"] = path; - - } - - protected override string ExecuteQuery(Query query) - { - JsonRPCServerRequestModel request = new JsonRPCServerRequestModel - { - Method = "query", - Parameters = new object[] { query.Search }, - }; - //Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable - _startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\""; - // todo happlebao why context can't be used in constructor - _startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory; - - return Execute(_startInfo); - } - - protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest) - { - _startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{rpcRequest}\""; - _startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory; - return Execute(_startInfo); - } - - protected override string ExecuteContextMenu(Result selectedResult) { - JsonRPCServerRequestModel request = new JsonRPCServerRequestModel { - Method = "context_menu", - Parameters = new object[] { selectedResult.ContextData }, - }; - _startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\""; - _startInfo.WorkingDirectory = context.CurrentPluginMetadata.PluginDirectory; - - return Execute(_startInfo); - } - } -} \ No newline at end of file diff --git a/src/modules/launcher/Wox.Core/Wox.Core.csproj b/src/modules/launcher/Wox.Core/Wox.Core.csproj index c7235c9fd5..bb158e7a9f 100644 --- a/src/modules/launcher/Wox.Core/Wox.Core.csproj +++ b/src/modules/launcher/Wox.Core/Wox.Core.csproj @@ -69,7 +69,6 @@ - diff --git a/src/modules/launcher/Wox.Infrastructure/Exception/ExceptionFormatter.cs b/src/modules/launcher/Wox.Infrastructure/Exception/ExceptionFormatter.cs index 91fc5f2f4b..b95cdf1c91 100644 --- a/src/modules/launcher/Wox.Infrastructure/Exception/ExceptionFormatter.cs +++ b/src/modules/launcher/Wox.Infrastructure/Exception/ExceptionFormatter.cs @@ -66,7 +66,6 @@ namespace Wox.Infrastructure.Exception sb.AppendLine($"* OS Version: {Environment.OSVersion.VersionString}"); sb.AppendLine($"* IntPtr Length: {IntPtr.Size}"); sb.AppendLine($"* x64: {Environment.Is64BitOperatingSystem}"); - sb.AppendLine($"* Python Path: {Constant.PythonPath}"); sb.AppendLine($"* Everything SDK Path: {Constant.EverythingSDKPath}"); sb.AppendLine($"* CLR Version: {Environment.Version}"); sb.AppendLine($"* Installed .NET Framework: "); diff --git a/src/modules/launcher/Wox.Infrastructure/Wox.cs b/src/modules/launcher/Wox.Infrastructure/Wox.cs index d09e7b904c..1604c69960 100644 --- a/src/modules/launcher/Wox.Infrastructure/Wox.cs +++ b/src/modules/launcher/Wox.Infrastructure/Wox.cs @@ -40,7 +40,6 @@ namespace Wox.Infrastructure public static readonly string DefaultIcon = Path.Combine(ProgramDirectory, "Images", "app.png"); public static readonly string ErrorIcon = Path.Combine(ProgramDirectory, "Images", "app_error.png"); - public static string PythonPath; public static string EverythingSDKPath; } } diff --git a/src/modules/launcher/Wox.Plugin/AllowedLanguage.cs b/src/modules/launcher/Wox.Plugin/AllowedLanguage.cs index 840792af3a..2db19ab77a 100644 --- a/src/modules/launcher/Wox.Plugin/AllowedLanguage.cs +++ b/src/modules/launcher/Wox.Plugin/AllowedLanguage.cs @@ -2,11 +2,6 @@ { public static class AllowedLanguage { - public static string Python - { - get { return "PYTHON"; } - } - public static string CSharp { get { return "CSHARP"; } @@ -19,8 +14,7 @@ public static bool IsAllowed(string language) { - return language.ToUpper() == Python.ToUpper() - || language.ToUpper() == CSharp.ToUpper() + return language.ToUpper() == CSharp.ToUpper() || language.ToUpper() == Executable.ToUpper(); } } diff --git a/src/modules/launcher/Wox/Helper/ErrorReporting.cs b/src/modules/launcher/Wox/Helper/ErrorReporting.cs index e6bec5a45a..2b3d91c6a0 100644 --- a/src/modules/launcher/Wox/Helper/ErrorReporting.cs +++ b/src/modules/launcher/Wox/Helper/ErrorReporting.cs @@ -41,8 +41,7 @@ namespace Wox.Helper public static string DependenciesInfo() { - var info = $"\nPython Path: {Constant.PythonPath}" + - $"\nEverything SDK Path: {Constant.EverythingSDKPath}"; + var info = $"\nEverything SDK Path: {Constant.EverythingSDKPath}"; return info; } }