mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 17:42:45 +08:00
Refactoring directory path for python plugin
This commit is contained in:
parent
8ee94d75ca
commit
e9ddfa6cf9
@ -1,41 +1,36 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
|
||||||
using Wox.Core.UserSettings;
|
using Wox.Core.UserSettings;
|
||||||
|
using Wox.Infrastructure;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox.Core.Plugin
|
namespace Wox.Core.Plugin
|
||||||
{
|
{
|
||||||
internal class PythonPlugin : JsonRPCPlugin
|
internal class PythonPlugin : JsonRPCPlugin
|
||||||
{
|
{
|
||||||
private static string woxDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
private static readonly string PythonHome = Path.Combine(WoxDirectroy.Executable, "PythonHome");
|
||||||
private ProcessStartInfo startInfo;
|
private readonly ProcessStartInfo _startInfo;
|
||||||
|
|
||||||
public override string SupportedLanguage
|
public override string SupportedLanguage => AllowedLanguage.Python;
|
||||||
{
|
|
||||||
get { return AllowedLanguage.Python; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public PythonPlugin()
|
public PythonPlugin()
|
||||||
{
|
{
|
||||||
startInfo = new ProcessStartInfo
|
_startInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardError = true
|
RedirectStandardError = true
|
||||||
};
|
};
|
||||||
string additionalPythonPath = string.Format("{0};{1}",
|
string additionalPythonPath = $"{Path.Combine(PythonHome, "DLLs")};{Path.Combine(PythonHome, "Lib", "site-packages")}";
|
||||||
Path.Combine(woxDirectory, "PythonHome\\DLLs"),
|
if (!_startInfo.EnvironmentVariables.ContainsKey("PYTHONPATH"))
|
||||||
Path.Combine(woxDirectory, "PythonHome\\Lib\\site-packages"));
|
|
||||||
if (!startInfo.EnvironmentVariables.ContainsKey("PYTHONPATH"))
|
|
||||||
{
|
{
|
||||||
|
|
||||||
startInfo.EnvironmentVariables.Add("PYTHONPATH", additionalPythonPath);
|
_startInfo.EnvironmentVariables.Add("PYTHONPATH", additionalPythonPath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
startInfo.EnvironmentVariables["PYTHONPATH"] = additionalPythonPath;
|
_startInfo.EnvironmentVariables["PYTHONPATH"] = additionalPythonPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,22 +38,22 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
|
JsonRPCServerRequestModel request = new JsonRPCServerRequestModel
|
||||||
{
|
{
|
||||||
Method = "query",
|
Method = "query",
|
||||||
Parameters = new object[] { query.GetAllRemainingParameter() },
|
Parameters = new object[] { query.GetAllRemainingParameter() },
|
||||||
HttpProxy = HttpProxy.Instance
|
HttpProxy = HttpProxy.Instance
|
||||||
};
|
};
|
||||||
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
|
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
|
||||||
startInfo.FileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe");
|
_startInfo.FileName = Path.Combine(PythonHome, "pythonw.exe");
|
||||||
startInfo.Arguments = string.Format("-B \"{0}\" \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath, request);
|
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\"";
|
||||||
|
|
||||||
return Execute(startInfo);
|
return Execute(_startInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
|
protected override string ExecuteCallback(JsonRPCRequestModel rpcRequest)
|
||||||
{
|
{
|
||||||
startInfo.FileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe");
|
_startInfo.FileName = Path.Combine(PythonHome, "pythonw.exe");
|
||||||
startInfo.Arguments = string.Format("-B \"{0}\" \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath, rpcRequest);
|
_startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{rpcRequest}\"";
|
||||||
return Execute(startInfo);
|
return Execute(_startInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user