public void Initialize() { //TODO CHANGE HOME AND PATH //string py_home = @"C:\Users\markd\AppData\Local\Programs\Python\Python35"; /*string codeBase = System.Reflection.Assembly.GetAssembly(typeof(ExecutionEngine)).CodeBase; * string path = new FileInfo(Uri.UnescapeDataString(new UriBuilder(codeBase).Path)).Directory.FullName; * string solution = Path.GetFullPath(path + @"\..\..\..\..\..\..\..\"); * * * string py_home = solution + @"Dependencies\Python35\"; * string py_path = py_home + @"Scripts;" + py_home + @"DLLs;" + py_home + @"lib;" + py_home + @"lib\site-packages"; * * Environment.SetEnvironmentVariable("PATH", py_home, EnvironmentVariableTarget.Process); * Environment.SetEnvironmentVariable("PYTHONHOME", py_home, EnvironmentVariableTarget.Process); * Environment.SetEnvironmentVariable("PYTHONPATH", py_path, EnvironmentVariableTarget.Process); * * PythonEngine.PythonHome = py_home; * PythonEngine.PythonPath = py_path;*/ PythonEngine.Initialize(); ThreadPtr = PythonEngine.BeginAllowThreads(); m_ScopeValues = new Dictionary <string, object>(); m_Assemblies = new HashSet <AssemblyDeclaration>(); m_Sessions = new HashSet <ExecutionSession>(); m_IOManager = null; SetValue("RUNTIME", new PyString(Runtime)); }
internal ExecutionSession(IExecutionEngineIO manager, Dictionary <string, object> Values, HashSet <AssemblyDeclaration> Assemblies) { CanExecute = true; Dictionary <string, object> args = new Dictionary <string, object>(); args["Debug"] = true; //IOManager IOManager = manager; // Create Engine Engine = IronPython.Hosting.Python.CreateEngine(args); // Create Scope Scope = InitializeScope(Values, Assemblies); // Redirect IO Engine.Runtime.IO.RedirectToConsole(); if (IOManager?.GetOutput() != null) { Console.SetOut(IOManager.GetOutput()); } if (IOManager?.GetError() != null) { Console.SetError(IOManager.GetError()); } if (IOManager?.GetInput() != null) { Console.SetIn(IOManager.GetInput()); } }
public void Initialize() { m_ScopeValues = new Dictionary <string, object>(); m_Assemblies = new HashSet <AssemblyDeclaration>(); m_Sessions = new HashSet <ExecutionSession>(); m_IOManager = null; SetValue("RUNTIME", Runtime); }
internal ExecutionSession(IExecutionEngineIO manager, Dictionary <string, object> Values, HashSet <AssemblyDeclaration> Assemblies) { CanExecute = true; //IOManager IOManager = manager; // Create Scope Scope = InitializeScope(Values, Assemblies); if (Scope == null) { CanExecute = false; return; } // Redirect IO using (Py.GIL()) { dynamic SYS = Scope.Import("sys"); SYS.stdout = new PythonOutput(); SYS.stderr = new PythonError(); SYS.stdin = new PythonInput(); } if (IOManager?.GetOutput() != null) { Console.SetOut(IOManager.GetOutput()); } if (IOManager?.GetError() != null) { Console.SetError(IOManager.GetError()); } if (IOManager?.GetInput() != null) { Console.SetIn(IOManager.GetInput()); } }
public void SetIO(IExecutionEngineIO manager) { m_IOManager = manager; }