1.1 --- a/micropython/__init__.py Tue Feb 05 01:11:36 2008 +0100
1.2 +++ b/micropython/__init__.py Tue Feb 05 23:54:52 2008 +0100
1.3 @@ -46,14 +46,18 @@
1.4
1.5 "An import machine, searching for and loading modules."
1.6
1.7 - def __init__(self, path=None):
1.8 + def __init__(self, path=None, verbose=0):
1.9
1.10 """
1.11 Initialise the importer with the given search 'path' - a list of
1.12 directories to search for Python modules.
1.13 +
1.14 + The optional 'verbose' parameter causes output concerning the activities
1.15 + of the object to be produced if set to a true value (not the default).
1.16 """
1.17
1.18 self.path = path or [os.getcwd()]
1.19 + self.verbose = verbose
1.20 self.modules = {}
1.21 self.loading = set()
1.22
1.23 @@ -288,7 +292,8 @@
1.24 if self.modules.has_key(name) and self.modules[name].loaded:
1.25 #print "Cached (%s)" % name
1.26 return self.modules[name]
1.27 - print "Loading", name
1.28 + if self.verbose:
1.29 + print "Loading", name
1.30
1.31 # Split the name into path components, and try to find the uppermost in
1.32 # the search path.
1.33 @@ -296,7 +301,8 @@
1.34 path = name.split(".")
1.35 m = self.find_in_path(path[0])
1.36 if not m:
1.37 - print "Not found (%s)" % path[0]
1.38 + if self.verbose:
1.39 + print "Not found (%s)" % path[0]
1.40 return None # NOTE: Import error.
1.41 d, filename = m
1.42
1.43 @@ -309,7 +315,8 @@
1.44
1.45 if len(path) > 1:
1.46 if not d:
1.47 - print "No package (%s)" % filename
1.48 + if self.verbose:
1.49 + print "No package (%s)" % filename
1.50 return None # NOTE: Import error (package not found).
1.51 else:
1.52 self.add_submodules(d, module)
1.53 @@ -322,7 +329,8 @@
1.54
1.55 m = self.find(d, p)
1.56 if not m:
1.57 - print "Not found (%s)" % p
1.58 + if self.verbose:
1.59 + print "Not found (%s)" % p
1.60 return None # NOTE: Import error.
1.61 d, filename = m
1.62 module_name = ".".join(path_so_far)
2.1 --- a/micropython/inspect.py Tue Feb 05 01:11:36 2008 +0100
2.2 +++ b/micropython/inspect.py Tue Feb 05 23:54:52 2008 +0100
2.3 @@ -744,8 +744,8 @@
2.4
2.5 module = self.importer.load(node.modname, 1)
2.6
2.7 - if module is None:
2.8 - print "Warning:", node.modname, "not imported."
2.9 + #if module is None:
2.10 + # print "Warning:", node.modname, "not imported."
2.11
2.12 for name, alias in node.names:
2.13 if name != "*":
2.14 @@ -871,6 +871,8 @@
2.15 name = node.name
2.16 if name == "self":
2.17 return Self()
2.18 + elif self.namespaces and self.namespaces[-1].has_key(name):
2.19 + return self.namespaces[-1][name]
2.20 elif self.has_key(name):
2.21 return self[name]
2.22 elif builtins.has_key(name):
3.1 --- a/test.py Tue Feb 05 01:11:36 2008 +0100
3.2 +++ b/test.py Tue Feb 05 23:54:52 2008 +0100
3.3 @@ -7,7 +7,7 @@
3.4 for i, x in enumerate(importer.get_image()):
3.5 print i, x
3.6
3.7 -i = micropython.Importer(sys.path)
3.8 +i = micropython.Importer(sys.path, "-v" in sys.argv)
3.9 if len(sys.argv) < 2:
3.10 m = i.load("micropython")
3.11 #m = i.load_from_file("micropython/__init__.py")