@@ -115,63 +115,65 @@ public static IEnumerable<PluginPair> PythonPlugins(List<PluginMetadata> source,
115
115
if ( ! source . Any ( o => o . Language . ToUpper ( ) == AllowedLanguage . Python ) )
116
116
return new List < PluginPair > ( ) ;
117
117
118
- if ( string . IsNullOrEmpty ( settings . PythonDirectory ) )
118
+ if ( ! string . IsNullOrEmpty ( settings . PythonDirectory ) )
119
+ return SetPythonPathForPluginPairs ( source , Path . Combine ( settings . PythonDirectory , PythonExecutable ) ) ;
120
+
121
+ var pythonPath = string . Empty ;
122
+
123
+ if ( MessageBox . Show ( "Flow detected you have installed Python plugins, " +
124
+ "would you like to install Python to run them? " +
125
+ Environment . NewLine + Environment . NewLine +
126
+ "Click no if it's already installed, " +
127
+ "and you will be prompted to select the folder that contains the Python executable" ,
128
+ string . Empty , MessageBoxButtons . YesNo ) == DialogResult . No
129
+ && string . IsNullOrEmpty ( settings . PythonDirectory ) )
119
130
{
120
- if ( MessageBox . Show ( "Flow detected you have installed Python plugins, " +
121
- "would you like to install Python to run them? " +
122
- Environment . NewLine + Environment . NewLine +
123
- "Click no if it's already installed, " +
124
- "and you will be prompted to select the folder that contains the Python executable" ,
125
- string . Empty , MessageBoxButtons . YesNo ) == DialogResult . No
126
- && string . IsNullOrEmpty ( settings . PythonDirectory ) )
131
+ var dlg = new FolderBrowserDialog
127
132
{
128
- var dlg = new FolderBrowserDialog
129
- {
130
- SelectedPath = Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles )
131
- } ;
133
+ SelectedPath = Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles )
134
+ } ;
132
135
133
- var result = dlg . ShowDialog ( ) ;
134
- if ( result == DialogResult . OK )
136
+ var result = dlg . ShowDialog ( ) ;
137
+ if ( result == DialogResult . OK )
138
+ {
139
+ string pythonDirectory = dlg . SelectedPath ;
140
+ if ( ! string . IsNullOrEmpty ( pythonDirectory ) )
135
141
{
136
- string pythonDirectory = dlg . SelectedPath ;
137
- if ( ! string . IsNullOrEmpty ( pythonDirectory ) )
142
+ pythonPath = Path . Combine ( pythonDirectory , PythonExecutable ) ;
143
+ if ( File . Exists ( pythonPath ) )
138
144
{
139
- var pythonPath = Path . Combine ( pythonDirectory , PythonExecutable ) ;
140
- if ( File . Exists ( pythonPath ) )
141
- {
142
- settings . PythonDirectory = pythonDirectory ;
143
- Constant . PythonPath = pythonPath ;
144
- }
145
- else
146
- {
147
- MessageBox . Show ( "Can't find python in given directory" ) ;
148
- }
145
+ settings . PythonDirectory = pythonDirectory ;
146
+ Constant . PythonPath = pythonPath ;
147
+ }
148
+ else
149
+ {
150
+ MessageBox . Show ( "Can't find python in given directory" ) ;
149
151
}
150
152
}
151
153
}
152
- else
153
- {
154
- var installedPythonDirectory = Path . Combine ( DataLocation . DataDirectory ( ) , "Python Embeddable" ) ;
154
+ }
155
+ else
156
+ {
157
+ var installedPythonDirectory = Path . Combine ( DataLocation . DataDirectory ( ) , "Python Embeddable" ) ;
155
158
156
- // Python 3.8.9 is used for Windows 7 compatibility
157
- DroplexPackage . Drop ( App . python_3_8_9_embeddable , installedPythonDirectory ) . Wait ( ) ;
159
+ // Python 3.8.9 is used for Windows 7 compatibility
160
+ DroplexPackage . Drop ( App . python_3_8_9_embeddable , installedPythonDirectory ) . Wait ( ) ;
158
161
159
- var pythonPath = Path . Combine ( installedPythonDirectory , PythonExecutable ) ;
160
- if ( FilesFolders . FileExists ( pythonPath ) )
161
- {
162
- settings . PythonDirectory = installedPythonDirectory ;
163
- Constant . PythonPath = pythonPath ;
164
- }
165
- else
166
- {
167
- Log . Error ( "PluginsLoader" ,
168
- $ "Failed to set Python path after Droplex install, { pythonPath } does not exist",
169
- "PythonPlugins" ) ;
170
- }
162
+ pythonPath = Path . Combine ( installedPythonDirectory , PythonExecutable ) ;
163
+ if ( FilesFolders . FileExists ( pythonPath ) )
164
+ {
165
+ settings . PythonDirectory = installedPythonDirectory ;
166
+ Constant . PythonPath = pythonPath ;
167
+ }
168
+ else
169
+ {
170
+ Log . Error ( "PluginsLoader" ,
171
+ $ "Failed to set Python path after Droplex install, { pythonPath } does not exist",
172
+ "PythonPlugins" ) ;
171
173
}
172
174
}
173
175
174
- if ( string . IsNullOrEmpty ( settings . PythonDirectory ) )
176
+ if ( string . IsNullOrEmpty ( settings . PythonDirectory ) || string . IsNullOrEmpty ( pythonPath ) )
175
177
{
176
178
MessageBox . Show (
177
179
"Unable to set Python executable path, please try from Flow's settings (scroll down to the bottom)." ) ;
@@ -182,16 +184,20 @@ public static IEnumerable<PluginPair> PythonPlugins(List<PluginMetadata> source,
182
184
return new List < PluginPair > ( ) ;
183
185
}
184
186
185
- return source
187
+ return SetPythonPathForPluginPairs ( source , pythonPath ) ;
188
+ }
189
+
190
+ private static IEnumerable < PluginPair > SetPythonPathForPluginPairs ( List < PluginMetadata > source , string pythonPath )
191
+ => source
186
192
. Where ( o => o . Language . ToUpper ( ) == AllowedLanguage . Python )
187
193
. Select ( metadata => new PluginPair
188
194
{
189
- Plugin = new PythonPlugin ( Constant . PythonPath ) , Metadata = metadata
195
+ Plugin = new PythonPlugin ( pythonPath ) ,
196
+ Metadata = metadata
190
197
} )
191
198
. ToList ( ) ;
192
- }
193
199
194
- public static IEnumerable < PluginPair > ExecutablePlugins ( IEnumerable < PluginMetadata > source )
200
+ public static IEnumerable < PluginPair > ExecutablePlugins ( IEnumerable < PluginMetadata > source )
195
201
{
196
202
return source
197
203
. Where ( o => o . Language . ToUpper ( ) == AllowedLanguage . Executable )
0 commit comments