Skip to content

Commit

Permalink
Add extension folders to IronPython search path
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Nov 14, 2022
1 parent 259e716 commit b146977
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageTags>Bonsai Rx Scripting Iron Python Design</PackageTags>
<UseWindowsForms>true</UseWindowsForms>
<TargetFramework>net462</TargetFramework>
<VersionPrefix>2.7.0</VersionPrefix>
<VersionPrefix>2.7.1</VersionPrefix>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="jacobslusser.ScintillaNET" Version="3.6.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description>Bonsai Scripting Library containing IronPython scripting infrastructure for Bonsai.</Description>
<PackageTags>Bonsai Rx Scripting Iron Python</PackageTags>
<TargetFramework>net462</TargetFramework>
<VersionPrefix>2.7.0</VersionPrefix>
<VersionPrefix>2.7.1</VersionPrefix>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IronPython" Version="2.7.5" />
Expand Down
25 changes: 20 additions & 5 deletions Bonsai.Scripting.IronPython/PythonEngine.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
using Microsoft.Scripting.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace Bonsai.Scripting.IronPython
{
static class PythonEngine
{
const string ExtensionsPath = "Extensions";
const string RepositoryPath = "Packages";

internal static ScriptEngine Create()
{
var engine = global::IronPython.Hosting.Python.CreateEngine();
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var libPath = Directory.GetDirectories(Path.Combine(basePath, "../../../"), "IronPython.StdLib.*");
var searchPaths = new List<string>();
var editorPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var editorExtensionsPath = Path.Combine(editorPath, ExtensionsPath);
var editorRepositoryPath = Path.Combine(editorPath, RepositoryPath);
var customExtensionsPath = Path.Combine(Environment.CurrentDirectory, ExtensionsPath);
searchPaths.Add(customExtensionsPath);
searchPaths.Add(editorExtensionsPath);

var libPath = Directory.GetDirectories(editorRepositoryPath, "IronPython.StdLib.*");
if (libPath.Length == 1)
{
var lib = Path.Combine(libPath[0], $"content/Lib");
var lib = Path.Combine(libPath[0], "content", "Lib");
var sitePackages = Path.Combine(lib, "site-packages");
engine.SetSearchPaths(new[] { lib, sitePackages });
searchPaths.Add(lib);
searchPaths.Add(sitePackages);
}

var engine = global::IronPython.Hosting.Python.CreateEngine();
engine.SetSearchPaths(searchPaths);
return engine;
}
}
Expand Down

0 comments on commit b146977

Please sign in to comment.