public CPythonInterpreter(PythonInterpreterFactoryWithDatabase factory) { _langVersion = factory.Configuration.Version; _factory = factory; _typeDb = _factory.GetCurrentDatabase(); _factory.NewDatabaseAvailable += OnNewDatabaseAvailable; }
void OnNewDatabaseAvailable(object sender, EventArgs e) { var mod = _modules["__builtin__"] as IBuiltinPythonModule; _typeDb = _factory.GetCurrentDatabase().CloneWithNewBuiltins(mod); RaiseModuleNamesChanged(); }
public IronPythonInterpreter(PythonInterpreterFactoryWithDatabase factory) { #if DEBUG _id = Interlocked.Increment(ref _interpreterCount); Debug.WriteLine(String.Format("IronPython Interpreter Created {0}", _id)); Debug.WriteLine(new StackTrace(true).ToString()); #endif AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolver.Instance.CurrentDomain_AssemblyResolve; InitializeRemoteDomain(); try { LoadAssemblies(); } catch { // IronPython not installed in the GAC... } var mod = Remote.ImportBuiltinModule("__builtin__"); var newMod = new IronPythonBuiltinModule(this, mod, "__builtin__"); _modules[newMod.Name] = newMod; _factory = factory; _typeDb = _factory.GetCurrentDatabase().CloneWithNewBuiltins(newMod); _factory.NewDatabaseAvailable += OnNewDatabaseAvailable; LoadModules(); }
private void OnNewDatabaseAvailable(object sender, EventArgs e) { _typeDb = _factory.GetCurrentDatabase(); if (_references != null) { _typeDb = _typeDb.Clone(); foreach (var reference in _references) { string modName; try { modName = Path.GetFileNameWithoutExtension(reference.Name); } catch (Exception) { continue; } _typeDb.LoadExtensionModuleAsync(modName, reference.Name).Wait(); } } var evt = ModuleNamesChanged; if (evt != null) { evt(this, EventArgs.Empty); } }
// We could override MakeInterpreter() to return a different // implementation of IPythonInterpreter, but we don't need to here, as // the default implementation works well with PythonTypeDatabase. //public override IPythonInterpreter MakeInterpreter(PythonInterpreterFactoryWithDatabase factory) { // return base.MakeInterpreter(factory); //} /// <summary> /// Returns a new database that contains the database from our base /// interpreter. /// </summary> public override PythonTypeDatabase MakeTypeDatabase(string databasePath, bool includeSitePackages = true) { if (_baseDb == null && _base.IsCurrent) { _baseDb = _base.GetCurrentDatabase(ShouldIncludeGlobalSitePackages); } var paths = new List <string> { databasePath }; if (includeSitePackages) { try { paths.AddRange(Directory.EnumerateDirectories(databasePath)); } catch (ArgumentException) { } catch (IOException) { } catch (SecurityException) { } catch (UnauthorizedAccessException) { } } return(new PythonTypeDatabase(this, paths, _baseDb)); }
public CPythonInterpreter(PythonInterpreterFactoryWithDatabase factory) { _langVersion = factory.Configuration.Version; _factory = factory; _typeDb = _factory.GetCurrentDatabase(); _factory.NewDatabaseAvailable += OnNewDatabaseAvailable; }