From cc2b9dc81d22226e2479084ae2cc238551802868 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 17 Jun 2021 22:20:32 +1000 Subject: [PATCH 1/6] use python 3.8.9 embeddable --- Flow.Launcher.Core/Flow.Launcher.Core.csproj | 2 +- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Core/Flow.Launcher.Core.csproj b/Flow.Launcher.Core/Flow.Launcher.Core.csproj index 2b2bef4cf79..ac49b193c24 100644 --- a/Flow.Launcher.Core/Flow.Launcher.Core.csproj +++ b/Flow.Launcher.Core/Flow.Launcher.Core.csproj @@ -53,7 +53,7 @@ - + diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index 3f998fa51b3..fa34db7a4f6 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -209,7 +209,8 @@ public static IEnumerable PythonPlugins(List source, } else { - DroplexPackage.Drop(App.python3_9_1).Wait(); + // Python 3.8.9 is used for Windows 7 compatibility + DroplexPackage.Drop(App.python_3_8_9_embeddable, Path.Combine(DataLocation.DataDirectory(), "Python Embeddable")).Wait(); var installedPythonDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), From 4909f582254c53a6901dc4bf533c4e66abcf07af Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 18 Jun 2021 08:27:23 +1000 Subject: [PATCH 2/6] switch to embedded path --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index fa34db7a4f6..87abc9e36dc 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -209,12 +209,11 @@ public static IEnumerable PythonPlugins(List source, } else { + var installedPythonDirectory = Path.Combine(DataLocation.DataDirectory(), "Python Embeddable"); + // Python 3.8.9 is used for Windows 7 compatibility - DroplexPackage.Drop(App.python_3_8_9_embeddable, Path.Combine(DataLocation.DataDirectory(), "Python Embeddable")).Wait(); + DroplexPackage.Drop(App.python_3_8_9_embeddable, installedPythonDirectory).Wait(); - var installedPythonDirectory = - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), - @"Programs\Python\Python39"); var pythonPath = Path.Combine(installedPythonDirectory, PythonExecutable); if (FilesFolders.FileExists(pythonPath)) { From 64f6c0f60e73c11d9c2af0ee20ae1f94278e7bff Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Fri, 18 Jun 2021 22:48:30 +1000 Subject: [PATCH 3/6] update Droplex --- Flow.Launcher.Core/Flow.Launcher.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Flow.Launcher.Core.csproj b/Flow.Launcher.Core/Flow.Launcher.Core.csproj index ac49b193c24..8d140844936 100644 --- a/Flow.Launcher.Core/Flow.Launcher.Core.csproj +++ b/Flow.Launcher.Core/Flow.Launcher.Core.csproj @@ -53,7 +53,7 @@ - + From c9b232aa265a6854a2d9b16fc064eb336f450234 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Fri, 18 Jun 2021 22:58:14 +1000 Subject: [PATCH 4/6] remove automatic retrieval py path from PATH or via where.exe --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 58 ---------------------- 1 file changed, 58 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index 87abc9e36dc..5d9b987f1f8 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -18,8 +18,6 @@ namespace Flow.Launcher.Core.Plugin { public static class PluginsLoader { - public const string PATH = "PATH"; - public const string Python = "python"; public const string PythonExecutable = "pythonw.exe"; public static List Plugins(List metadatas, PluginsSettings settings) @@ -117,62 +115,6 @@ public static IEnumerable PythonPlugins(List source, if (!source.Any(o => o.Language.ToUpper() == AllowedLanguage.Python)) return new List(); - // Try setting Constant.PythonPath first, either from - // PATH or from the given pythonDirectory - if (string.IsNullOrEmpty(settings.PythonDirectory)) - { - var whereProcess = Process.Start(new ProcessStartInfo - { - FileName = "where.exe", - Arguments = "pythonw", - RedirectStandardOutput = true, - CreateNoWindow = true, - UseShellExecute = false - }); - - var pythonPath = whereProcess?.StandardOutput.ReadToEnd().Trim(); - - if (!string.IsNullOrEmpty(pythonPath)) - { - pythonPath = FilesFolders.GetPreviousExistingDirectory(FilesFolders.LocationExists, pythonPath); - } - - if (string.IsNullOrEmpty(pythonPath)) - { - var paths = Environment.GetEnvironmentVariable(PATH); - - pythonPath = paths? - .Split(';') - .FirstOrDefault(p => p.ToLower().Contains(Python)); - } - - if (!string.IsNullOrEmpty(pythonPath)) - { - Constant.PythonPath = Path.Combine(pythonPath, PythonExecutable); - settings.PythonDirectory = - FilesFolders.GetPreviousExistingDirectory(FilesFolders.LocationExists, Constant.PythonPath); - } - else - { - Log.Error("PluginsLoader", - "Failed to set Python path despite the environment variable PATH is found", - "PythonPlugins"); - } - } - else - { - var path = Path.Combine(settings.PythonDirectory, PythonExecutable); - if (File.Exists(path)) - { - Constant.PythonPath = path; - } - else - { - Log.Error("PluginsLoader", $"Tried to automatically set from Settings.PythonDirectory " + - $"but can't find python executable in {path}", "PythonPlugins"); - } - } - if (string.IsNullOrEmpty(settings.PythonDirectory)) { if (MessageBox.Show("Flow detected you have installed Python plugins, " + From e125d59c6e309b3c099441f764347eb35b6ced1e Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sat, 19 Jun 2021 00:54:04 +1000 Subject: [PATCH 5/6] reorder logic for setting python path --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 102 +++++++++++---------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index 5d9b987f1f8..7c3e50fd4ec 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -115,63 +115,65 @@ public static IEnumerable PythonPlugins(List source, if (!source.Any(o => o.Language.ToUpper() == AllowedLanguage.Python)) return new List(); - if (string.IsNullOrEmpty(settings.PythonDirectory)) + if (!string.IsNullOrEmpty(settings.PythonDirectory)) + return SetPythonPathForPluginPairs(source, Path.Combine(settings.PythonDirectory, PythonExecutable)); + + var pythonPath = string.Empty; + + if (MessageBox.Show("Flow detected you have installed Python plugins, " + + "would you like to install Python to run them? " + + Environment.NewLine + Environment.NewLine + + "Click no if it's already installed, " + + "and you will be prompted to select the folder that contains the Python executable", + string.Empty, MessageBoxButtons.YesNo) == DialogResult.No + && string.IsNullOrEmpty(settings.PythonDirectory)) { - if (MessageBox.Show("Flow detected you have installed Python plugins, " + - "would you like to install Python to run them? " + - Environment.NewLine + Environment.NewLine + - "Click no if it's already installed, " + - "and you will be prompted to select the folder that contains the Python executable", - string.Empty, MessageBoxButtons.YesNo) == DialogResult.No - && string.IsNullOrEmpty(settings.PythonDirectory)) + var dlg = new FolderBrowserDialog { - var dlg = new FolderBrowserDialog - { - SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) - }; + SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + }; - var result = dlg.ShowDialog(); - if (result == DialogResult.OK) + var result = dlg.ShowDialog(); + if (result == DialogResult.OK) + { + string pythonDirectory = dlg.SelectedPath; + if (!string.IsNullOrEmpty(pythonDirectory)) { - string pythonDirectory = dlg.SelectedPath; - if (!string.IsNullOrEmpty(pythonDirectory)) + pythonPath = Path.Combine(pythonDirectory, PythonExecutable); + if (File.Exists(pythonPath)) { - var pythonPath = Path.Combine(pythonDirectory, PythonExecutable); - if (File.Exists(pythonPath)) - { - settings.PythonDirectory = pythonDirectory; - Constant.PythonPath = pythonPath; - } - else - { - MessageBox.Show("Can't find python in given directory"); - } + settings.PythonDirectory = pythonDirectory; + Constant.PythonPath = pythonPath; + } + else + { + MessageBox.Show("Can't find python in given directory"); } } } - else - { - var installedPythonDirectory = Path.Combine(DataLocation.DataDirectory(), "Python Embeddable"); + } + else + { + var installedPythonDirectory = Path.Combine(DataLocation.DataDirectory(), "Python Embeddable"); - // Python 3.8.9 is used for Windows 7 compatibility - DroplexPackage.Drop(App.python_3_8_9_embeddable, installedPythonDirectory).Wait(); + // Python 3.8.9 is used for Windows 7 compatibility + DroplexPackage.Drop(App.python_3_8_9_embeddable, installedPythonDirectory).Wait(); - var pythonPath = Path.Combine(installedPythonDirectory, PythonExecutable); - if (FilesFolders.FileExists(pythonPath)) - { - settings.PythonDirectory = installedPythonDirectory; - Constant.PythonPath = pythonPath; - } - else - { - Log.Error("PluginsLoader", - $"Failed to set Python path after Droplex install, {pythonPath} does not exist", - "PythonPlugins"); - } + pythonPath = Path.Combine(installedPythonDirectory, PythonExecutable); + if (FilesFolders.FileExists(pythonPath)) + { + settings.PythonDirectory = installedPythonDirectory; + Constant.PythonPath = pythonPath; + } + else + { + Log.Error("PluginsLoader", + $"Failed to set Python path after Droplex install, {pythonPath} does not exist", + "PythonPlugins"); } } - if (string.IsNullOrEmpty(settings.PythonDirectory)) + if (string.IsNullOrEmpty(settings.PythonDirectory) || string.IsNullOrEmpty(pythonPath)) { MessageBox.Show( "Unable to set Python executable path, please try from Flow's settings (scroll down to the bottom)."); @@ -182,16 +184,20 @@ public static IEnumerable PythonPlugins(List source, return new List(); } - return source + return SetPythonPathForPluginPairs(source, pythonPath); + } + + private static IEnumerable SetPythonPathForPluginPairs(List source, string pythonPath) + => source .Where(o => o.Language.ToUpper() == AllowedLanguage.Python) .Select(metadata => new PluginPair { - Plugin = new PythonPlugin(Constant.PythonPath), Metadata = metadata + Plugin = new PythonPlugin(pythonPath), + Metadata = metadata }) .ToList(); - } - public static IEnumerable ExecutablePlugins(IEnumerable source) + public static IEnumerable ExecutablePlugins(IEnumerable source) { return source .Where(o => o.Language.ToUpper() == AllowedLanguage.Executable) From 5fbde3779d9d1c235a5c56fee55c00f2eead0e33 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sat, 19 Jun 2021 11:17:00 +1000 Subject: [PATCH 6/6] check location exists if python path is already set --- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index 7c3e50fd4ec..e5f44e4c458 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -115,7 +115,7 @@ public static IEnumerable PythonPlugins(List source, if (!source.Any(o => o.Language.ToUpper() == AllowedLanguage.Python)) return new List(); - if (!string.IsNullOrEmpty(settings.PythonDirectory)) + if (!string.IsNullOrEmpty(settings.PythonDirectory) && FilesFolders.LocationExists(settings.PythonDirectory)) return SetPythonPathForPluginPairs(source, Path.Combine(settings.PythonDirectory, PythonExecutable)); var pythonPath = string.Empty;