private static object ImportNested(PythonModule mod, string name) { object ret; if (mod.TryGetAttr(mod, SymbolTable.StringToId(name), out ret)) { return(ret); } string baseName; List path = ResolveSearchPath(mod, out baseName); string fullName = CreateFullName(baseName, name); if (TryGetExistingModule(mod.SystemState, fullName, out ret)) { return(ret); } if (path != null) { ret = ImportFromPath(mod.SystemState, name, fullName, path); if (ret != null) { mod.SetAttr(mod, SymbolTable.StringToId(name), ret); return(ret); } } throw Ops.ImportError("cannot import {0} from {1}", name, mod.ModuleName); }
private static object LoadPackageFromSource(SystemState state, string fullName, string dirname) { string fullPath = Path.GetFullPath(dirname); List __path__ = Ops.MakeList(fullPath); PythonModule mod = LoadFromSource(state, fullName, Path.Combine(dirname, "__init__.py")); mod.SetAttr(DefaultContext.Default, SymbolTable.Path, __path__); return(InitializeModule(fullName, mod)); }
private static object ImportTopFrom(PythonModule mod, string name) { string baseName; List path = ResolveSearchPath(mod, out baseName); if (path == null) { return(null); } object ret = ImportFromPath(mod.SystemState, name, CreateFullName(baseName, name), path); if (ret != null) { mod.SetAttr(mod, SymbolTable.StringToId(name), ret); return(ret); } return(null); }