Flow.Launcher/Flow.Launcher.Core/ExternalPlugins/Environments/PythonEnvironment.cs

70 lines
2.5 KiB
C#
Raw Normal View History

2025-04-01 01:57:04 +00:00
using System.Collections.Generic;
using System.IO;
using Droplex;
using Flow.Launcher.Core.Plugin;
2022-11-21 22:20:27 +00:00
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedCommands;
2025-04-13 10:04:50 +00:00
using Microsoft.VisualStudio.Threading;
2022-11-21 22:20:27 +00:00
namespace Flow.Launcher.Core.ExternalPlugins.Environments
{
internal class PythonEnvironment : AbstractPluginEnvironment
{
private static readonly string ClassName = nameof(PythonEnvironment);
2022-11-21 22:20:27 +00:00
internal override string Language => AllowedLanguage.Python;
internal override string EnvName => DataLocation.PythonEnvironmentName;
2022-11-21 22:20:27 +00:00
internal override string EnvPath => Path.Combine(DataLocation.PluginEnvironmentsPath, EnvName);
2022-11-21 22:20:27 +00:00
2023-08-03 11:41:35 +00:00
internal override string InstallPath => Path.Combine(EnvPath, "PythonEmbeddable-v3.11.4");
2022-11-21 22:20:27 +00:00
internal override string ExecutablePath => Path.Combine(InstallPath, "pythonw.exe");
internal override string FileDialogFilter => "Python|pythonw.exe";
2025-04-01 01:57:04 +00:00
internal override string PluginsSettingsFilePath
{
get => PluginSettings.PythonExecutablePath;
set => PluginSettings.PythonExecutablePath = value;
}
2022-11-21 22:20:27 +00:00
internal PythonEnvironment(List<PluginMetadata> pluginMetadataList, PluginsSettings pluginSettings) : base(pluginMetadataList, pluginSettings) { }
2025-04-13 10:04:50 +00:00
private JoinableTaskFactory JTF { get; } = new JoinableTaskFactory(new JoinableTaskContext());
2022-11-21 22:20:27 +00:00
internal override void InstallEnvironment()
{
FilesFolders.RemoveFolderIfExists(InstallPath, (s) => API.ShowMsgBox(s));
2022-11-21 22:20:27 +00:00
2023-08-03 11:41:35 +00:00
// Python 3.11.4 is no longer Windows 7 compatible. If user is on Win 7 and
// uses Python plugin they need to custom install and use v3.8.9
JTF.Run(async () =>
{
try
{
await DroplexPackage.Drop(App.python_3_11_4_embeddable, InstallPath);
2022-11-21 22:20:27 +00:00
PluginsSettingsFilePath = ExecutablePath;
}
catch (System.Exception e)
{
API.ShowMsgError(Localize.failToInstallPythonEnv());
API.LogException(ClassName, "Failed to install Python environment", e);
}
});
2022-11-21 22:20:27 +00:00
}
internal override PluginPair CreatePluginPair(string filePath, PluginMetadata metadata)
{
return new PluginPair
{
Plugin = new PythonPlugin(filePath),
Metadata = metadata
};
}
2022-11-21 22:20:27 +00:00
}
}