@@ -127,65 +127,74 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
127
127
return plugins ;
128
128
}
129
129
130
- public static IEnumerable < PluginPair > PythonPlugins ( List < PluginMetadata > source , string pythonDirecotry )
130
+ public static IEnumerable < PluginPair > PythonPlugins ( List < PluginMetadata > source , string pythonDirectory )
131
131
{
132
- var metadatas = source . Where ( o => o . Language . ToUpper ( ) == AllowedLanguage . Python ) ;
133
- string filename ;
134
-
135
- if ( string . IsNullOrEmpty ( pythonDirecotry ) )
132
+ // try to set Constant.PythonPath, either from
133
+ // PATH or from the given pythonDirectory
134
+ if ( string . IsNullOrEmpty ( pythonDirectory ) )
136
135
{
137
136
var paths = Environment . GetEnvironmentVariable ( PATH ) ;
138
137
if ( paths != null )
139
138
{
140
- var pythonPaths = paths . Split ( ';' ) . Where ( p => p . ToLower ( ) . Contains ( Python ) ) ;
141
- if ( pythonPaths . Any ( ) )
139
+ var pythonInPath = paths
140
+ . Split ( ';' )
141
+ . Where ( p => p . ToLower ( ) . Contains ( Python ) )
142
+ . Any ( ) ;
143
+
144
+ if ( pythonInPath )
142
145
{
143
- filename = PythonExecutable ;
146
+ Constant . PythonPath = PythonExecutable ;
144
147
}
145
148
else
146
149
{
147
150
Log . Error ( "|PluginsLoader.PythonPlugins|Python can't be found in PATH." ) ;
148
- return new List < PluginPair > ( ) ;
149
151
}
150
152
}
151
153
else
152
154
{
153
155
Log . Error ( "|PluginsLoader.PythonPlugins|PATH environment variable is not set." ) ;
154
- return new List < PluginPair > ( ) ;
155
156
}
156
157
}
157
158
else
158
159
{
159
- var path = Path . Combine ( pythonDirecotry , PythonExecutable ) ;
160
+ var path = Path . Combine ( pythonDirectory , PythonExecutable ) ;
160
161
if ( File . Exists ( path ) )
161
162
{
162
- filename = path ;
163
+ Constant . PythonPath = path ;
163
164
}
164
165
else
165
166
{
166
- Log . Error ( "|PluginsLoader.PythonPlugins|Can't find python executable in <b " ) ;
167
- return new List < PluginPair > ( ) ;
167
+ Log . Error ( $ "|PluginsLoader.PythonPlugins|Can't find python executable in { path } ") ;
168
168
}
169
169
}
170
- Constant . PythonPath = filename ;
171
- var plugins = metadatas . Select ( metadata => new PluginPair
170
+
171
+ // if we have a path to the python executable,
172
+ // load every python plugin pair.
173
+ if ( String . IsNullOrEmpty ( Constant . PythonPath ) )
172
174
{
173
- Plugin = new PythonPlugin ( filename ) ,
174
- Metadata = metadata
175
- } ) ;
176
- return plugins ;
175
+ return new List < PluginPair > ( ) ;
176
+ }
177
+ else
178
+ {
179
+ return source
180
+ . Where ( o => o . Language . ToUpper ( ) == AllowedLanguage . Python )
181
+ . Select ( metadata => new PluginPair
182
+ {
183
+ Plugin = new PythonPlugin ( Constant . PythonPath ) ,
184
+ Metadata = metadata
185
+ } ) ;
186
+ }
177
187
}
178
188
179
189
public static IEnumerable < PluginPair > ExecutablePlugins ( IEnumerable < PluginMetadata > source )
180
190
{
181
- var metadatas = source . Where ( o => o . Language . ToUpper ( ) == AllowedLanguage . Executable ) ;
182
-
183
- var plugins = metadatas . Select ( metadata => new PluginPair
184
- {
185
- Plugin = new ExecutablePlugin ( metadata . ExecuteFilePath ) ,
186
- Metadata = metadata
187
- } ) ;
188
- return plugins ;
191
+ return source
192
+ . Where ( o => o . Language . ToUpper ( ) == AllowedLanguage . Executable )
193
+ . Select ( metadata => new PluginPair
194
+ {
195
+ Plugin = new ExecutablePlugin ( metadata . ExecuteFilePath ) ,
196
+ Metadata = metadata
197
+ } ) ;
189
198
}
190
199
191
200
}
0 commit comments