Skip to content

Commit

Permalink
Made some changes to additonal path logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersMalmgren committed Sep 8, 2020
1 parent dbee106 commit f30dcfe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion FreePIE.Console/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Start(string[] args)

System.Console.WriteLine("Starting script parser");

scriptEngine.Start(script, activeDocument.FilePath);
scriptEngine.Start(script, args[0]);
waitUntilStopped.WaitOne();
}
catch (Exception e)
Expand Down
5 changes: 5 additions & 0 deletions FreePIE.Core/Common/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public string GetFilename(string path)
return Path.GetFileName(path);
}

public string GetDirectoryName(string path)
{
return Path.GetDirectoryName(path);
}

public void Delete(string path)
{
File.Delete(path);
Expand Down
1 change: 1 addition & 0 deletions FreePIE.Core/Common/IFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public interface IFileSystem
string GetFilename(string path);
void Delete(string path);
void CreateDirectory(string path);
string GetDirectoryName(string path);
}
}
2 changes: 1 addition & 1 deletion FreePIE.Core/ScriptEngine/IScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace FreePIE.Core.ScriptEngine
{
public interface IScriptEngine
{
void Start(string script, string scriptName);
void Start(string script, string scriptPath = null);
void Stop();
}
}
26 changes: 10 additions & 16 deletions FreePIE.Core/ScriptEngine/Python/PythonScriptEngine.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
Expand All @@ -11,20 +10,15 @@
using FreePIE.Core.Common.Extensions;
using FreePIE.Core.Contracts;
using FreePIE.Core.Model.Events;
using FreePIE.Core.Persistence;
using FreePIE.Core.Persistence.Paths;
using FreePIE.Core.ScriptEngine.Globals;
using FreePIE.Core.ScriptEngine.ThreadTiming;
using IronPython;
using IronPython.Compiler;
using IronPython.Hosting;
using IronPython.Modules;
using IronPython.Runtime.Operations;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting.Hosting.Providers;
using Microsoft.Scripting.Runtime;
using IronPython.Runtime.Exceptions;
using Microsoft.Scripting.Utils;

namespace FreePIE.Core.ScriptEngine.Python
{
Expand Down Expand Up @@ -80,6 +74,7 @@ public class PythonScriptEngine : IScriptEngine
private readonly IThreadTimingFactory threadTimingFactory;
private readonly IPaths paths;
private readonly ILog log;
private readonly IFileSystem fileSystem;
private static Microsoft.Scripting.Hosting.ScriptEngine engine;
private IEnumerable<IPlugin> usedPlugins;
private InterlockableBool stopRequested;
Expand All @@ -105,17 +100,19 @@ public PythonScriptEngine(
IEventAggregator eventAggregator,
IThreadTimingFactory threadTimingFactory,
IPaths paths,
ILog log)
ILog log,
IFileSystem fileSystem)
{
this.parser = parser;
this.globalProviders = globalProviders;
this.eventAggregator = eventAggregator;
this.threadTimingFactory = threadTimingFactory;
this.paths = paths;
this.log = log;
this.fileSystem = fileSystem;
}

public void Start(string script, string scriptName)
public void Start(string script, string scriptPath = null)
{
thread = new Thread(obj1 =>
{
Expand Down Expand Up @@ -148,7 +145,7 @@ public void Start(string script, string scriptName)

pluginStarted.Wait();

string[] additionalPaths = new string[] {Path.GetDirectoryName(scriptName)};
var additionalPaths = new [] { scriptPath }.Where(p => !string.IsNullOrEmpty(p)).Select(p => fileSystem.GetDirectoryName(p));
Engine.SetSearchPaths(GetPythonPaths(additionalPaths));

script = PreProcessScript(script, usedGlobalEnums, globals);
Expand Down Expand Up @@ -180,15 +177,12 @@ void RunLoop(string script, ScriptScope scope)
});
}

ICollection<string> GetPythonPaths(string[] additionalPaths)
ICollection<string> GetPythonPaths(IEnumerable<string> additionalPaths)
{
var pythonPaths = new Collection<string> { paths.GetApplicationPath("pylib") };
foreach (string dir in additionalPaths)
{
pythonPaths.Add(dir);
}
pythonPaths.AddRange(additionalPaths);

return pythonPaths;

}

private void CatchThreadAbortedException(Action func)
Expand Down

0 comments on commit f30dcfe

Please sign in to comment.