|
1 | 1 | using Microsoft.Scripting.Hosting; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
2 | 4 | using System.IO; |
3 | 5 | using System.Reflection; |
4 | 6 |
|
5 | 7 | namespace Bonsai.Scripting.IronPython |
6 | 8 | { |
7 | 9 | static class PythonEngine |
8 | 10 | { |
| 11 | + const string ExtensionsPath = "Extensions"; |
| 12 | + const string RepositoryPath = "Packages"; |
| 13 | + |
9 | 14 | internal static ScriptEngine Create() |
10 | 15 | { |
11 | | - var engine = global::IronPython.Hosting.Python.CreateEngine(); |
12 | | - var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); |
13 | | - var libPath = Directory.GetDirectories(Path.Combine(basePath, "../../../"), "IronPython.StdLib.*"); |
| 16 | + var searchPaths = new List<string>(); |
| 17 | + var editorPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); |
| 18 | + var editorExtensionsPath = Path.Combine(editorPath, ExtensionsPath); |
| 19 | + var editorRepositoryPath = Path.Combine(editorPath, RepositoryPath); |
| 20 | + var customExtensionsPath = Path.Combine(Environment.CurrentDirectory, ExtensionsPath); |
| 21 | + searchPaths.Add(customExtensionsPath); |
| 22 | + searchPaths.Add(editorExtensionsPath); |
| 23 | + |
| 24 | + var libPath = Directory.GetDirectories(editorRepositoryPath, "IronPython.StdLib.*"); |
14 | 25 | if (libPath.Length == 1) |
15 | 26 | { |
16 | | - var lib = Path.Combine(libPath[0], $"content/Lib"); |
| 27 | + var lib = Path.Combine(libPath[0], "content", "Lib"); |
17 | 28 | var sitePackages = Path.Combine(lib, "site-packages"); |
18 | | - engine.SetSearchPaths(new[] { lib, sitePackages }); |
| 29 | + searchPaths.Add(lib); |
| 30 | + searchPaths.Add(sitePackages); |
19 | 31 | } |
| 32 | + |
| 33 | + var engine = global::IronPython.Hosting.Python.CreateEngine(); |
| 34 | + engine.SetSearchPaths(searchPaths); |
20 | 35 | return engine; |
21 | 36 | } |
22 | 37 | } |
|
0 commit comments