# HG changeset patch # User Paul Boddie # Date 1202252092 -3600 # Node ID dc9b0b8fa3af2068c1c9166fbfe5f8be83274e0b # Parent 20651857e5b845545bc596362221b147cd22b208 Added verbose mode. Fixed InspectedModule.visitName to look up locals correctly. diff -r 20651857e5b8 -r dc9b0b8fa3af micropython/__init__.py --- a/micropython/__init__.py Tue Feb 05 01:11:36 2008 +0100 +++ b/micropython/__init__.py Tue Feb 05 23:54:52 2008 +0100 @@ -46,14 +46,18 @@ "An import machine, searching for and loading modules." - def __init__(self, path=None): + def __init__(self, path=None, verbose=0): """ Initialise the importer with the given search 'path' - a list of directories to search for Python modules. + + The optional 'verbose' parameter causes output concerning the activities + of the object to be produced if set to a true value (not the default). """ self.path = path or [os.getcwd()] + self.verbose = verbose self.modules = {} self.loading = set() @@ -288,7 +292,8 @@ if self.modules.has_key(name) and self.modules[name].loaded: #print "Cached (%s)" % name return self.modules[name] - print "Loading", name + if self.verbose: + print "Loading", name # Split the name into path components, and try to find the uppermost in # the search path. @@ -296,7 +301,8 @@ path = name.split(".") m = self.find_in_path(path[0]) if not m: - print "Not found (%s)" % path[0] + if self.verbose: + print "Not found (%s)" % path[0] return None # NOTE: Import error. d, filename = m @@ -309,7 +315,8 @@ if len(path) > 1: if not d: - print "No package (%s)" % filename + if self.verbose: + print "No package (%s)" % filename return None # NOTE: Import error (package not found). else: self.add_submodules(d, module) @@ -322,7 +329,8 @@ m = self.find(d, p) if not m: - print "Not found (%s)" % p + if self.verbose: + print "Not found (%s)" % p return None # NOTE: Import error. d, filename = m module_name = ".".join(path_so_far) diff -r 20651857e5b8 -r dc9b0b8fa3af micropython/inspect.py --- a/micropython/inspect.py Tue Feb 05 01:11:36 2008 +0100 +++ b/micropython/inspect.py Tue Feb 05 23:54:52 2008 +0100 @@ -744,8 +744,8 @@ module = self.importer.load(node.modname, 1) - if module is None: - print "Warning:", node.modname, "not imported." + #if module is None: + # print "Warning:", node.modname, "not imported." for name, alias in node.names: if name != "*": @@ -871,6 +871,8 @@ name = node.name if name == "self": return Self() + elif self.namespaces and self.namespaces[-1].has_key(name): + return self.namespaces[-1][name] elif self.has_key(name): return self[name] elif builtins.has_key(name): diff -r 20651857e5b8 -r dc9b0b8fa3af test.py --- a/test.py Tue Feb 05 01:11:36 2008 +0100 +++ b/test.py Tue Feb 05 23:54:52 2008 +0100 @@ -7,7 +7,7 @@ for i, x in enumerate(importer.get_image()): print i, x -i = micropython.Importer(sys.path) +i = micropython.Importer(sys.path, "-v" in sys.argv) if len(sys.argv) < 2: m = i.load("micropython") #m = i.load_from_file("micropython/__init__.py")