/// <summary> /// Reloads the modules when the interpreter says they've changed. /// Modules that are already in the table as builtins are replaced or /// removed, but no new modules are added. /// </summary> public void ReInit() { var newNames = new HashSet <string>(_interpreter.GetModuleNames(), StringComparer.Ordinal); foreach (var keyValue in _modules) { var name = keyValue.Key; var moduleRef = keyValue.Value; var builtinModule = moduleRef.Module as BuiltinModule; if (builtinModule != null) { IPythonModule newModule = null; if (newNames.Contains(name)) { newModule = _interpreter.ImportModule(name); } if (newModule == null) { // this module was unloaded ModuleReference dummy; _modules.TryRemove(name, out dummy); BuiltinModule removedModule; _builtinModuleTable.TryRemove(builtinModule.InterpreterModule, out removedModule); foreach (var child in builtinModule.InterpreterModule.GetChildrenModules()) { _modules.TryRemove(builtinModule.Name + "." + child, out dummy); } } else if (builtinModule.InterpreterModule != newModule) { // this module was replaced with a new module BuiltinModule removedModule; _builtinModuleTable.TryRemove(builtinModule.InterpreterModule, out removedModule); moduleRef.Module = GetBuiltinModule(newModule); ImportChildren(newModule); } } } }
private void InitializeBuiltinModules() { var names = _interpreter.GetModuleNames(); foreach (string modName in names) { var mod = _interpreter.ImportModule(modName); if (mod != null) { ModuleReference modRef; if (Modules.TryGetValue(modName, out modRef)) { var existingBuiltin = modRef.Module as BuiltinModule; if (existingBuiltin != null && existingBuiltin._type == mod) { // don't replace existing module which is the same continue; } } Modules[modName] = new ModuleReference(new BuiltinModule(mod, this)); } } }
public AnalysisView( string dbDir, Version version = null, bool withContention = false, bool withRecursion = false ) { var paths = new List <string>(); paths.Add(dbDir); while (!File.Exists(IOPath.Combine(paths[0], "__builtin__.idb")) && !File.Exists(IOPath.Combine(paths[0], "builtins.idb"))) { var upOne = IOPath.GetDirectoryName(paths[0]); if (string.IsNullOrEmpty(upOne) || upOne == paths[0]) { break; } paths.Insert(0, upOne); } if (withRecursion) { paths.AddRange(Directory.EnumerateDirectories(dbDir, "*", SearchOption.AllDirectories)); } if (version == null) { if (File.Exists(IOPath.Combine(paths[0], "builtins.idb"))) { version = new Version(3, 3); } else { version = new Version(2, 7); } } _factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory( version, dbDir, paths.ToArray() ); Path = dbDir; _interpreter = _factory.CreateInterpreter(); _context = _interpreter.CreateModuleContext(); var modNames = _interpreter.GetModuleNames(); IEnumerable <Tuple <string, string> > modItems; if (!withRecursion) { modItems = modNames .Select(n => Tuple.Create(n, IOPath.Combine(dbDir, n + ".idb"))) .Where(t => File.Exists(t.Item2)); } else { modItems = modNames .Select(n => Tuple.Create( n, Directory.EnumerateFiles(dbDir, n + ".idb", SearchOption.AllDirectories).FirstOrDefault() )) .Where(t => File.Exists(t.Item2)); } var stopwatch = new Stopwatch(); stopwatch.Start(); if (withContention) { modItems = modItems .AsParallel() .WithExecutionMode(ParallelExecutionMode.ForceParallelism); } _modules = modItems .Select(t => new ModuleView(_interpreter, _context, t.Item1, t.Item2)) .OrderBy(m => m.SortKey) .ThenBy(m => m.Name) .ToList <IAnalysisItemView>(); stopwatch.Stop(); _modules.Insert(0, new KnownTypesView(_interpreter, version)); LoadMilliseconds = stopwatch.ElapsedMilliseconds; TopLevelModuleCount = _modules.Count - 1; }
public AnalysisView( string dbDir, Version version = null, bool withContention = false, bool withRecursion = false ) { var paths = new List<string>(); paths.Add(dbDir); while (!File.Exists(IOPath.Combine(paths[0], "__builtin__.idb")) && !File.Exists(IOPath.Combine(paths[0], "builtins.idb"))) { var upOne = IOPath.GetDirectoryName(paths[0]); if (string.IsNullOrEmpty(upOne) || upOne == paths[0]) { break; } paths.Insert(0, upOne); } if (withRecursion) { paths.AddRange(Directory.EnumerateDirectories(dbDir, "*", SearchOption.AllDirectories)); } if (version == null) { if (File.Exists(IOPath.Combine(paths[0], "builtins.idb"))) { version = new Version(3, 3); } else { version = new Version(2, 7); } } _factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory( version, dbDir, paths.ToArray() ); Path = dbDir; _interpreter = _factory.CreateInterpreter(); _context = _interpreter.CreateModuleContext(); var modNames = _interpreter.GetModuleNames(); IEnumerable<Tuple<string, string>> modItems; if (!withRecursion) { modItems = modNames .Select(n => Tuple.Create(n, IOPath.Combine(dbDir, n + ".idb"))) .Where(t => File.Exists(t.Item2)); } else { modItems = modNames .Select(n => Tuple.Create( n, Directory.EnumerateFiles(dbDir, n + ".idb", SearchOption.AllDirectories).FirstOrDefault() )) .Where(t => File.Exists(t.Item2)); } var stopwatch = new Stopwatch(); stopwatch.Start(); if (withContention) { modItems = modItems .AsParallel() .WithExecutionMode(ParallelExecutionMode.ForceParallelism); } _modules = modItems .Select(t => new ModuleView(_interpreter, _context, t.Item1, t.Item2)) .OrderBy(m => m.SortKey) .ThenBy(m => m.Name) .ToList<IAnalysisItemView>(); stopwatch.Stop(); _modules.Insert(0, new KnownTypesView(_interpreter, version)); LoadMilliseconds = stopwatch.ElapsedMilliseconds; TopLevelModuleCount = _modules.Count - 1; }