def setUp(self): """ Perturb the normal import behavior subtly by installing an import hook. No custom behavior is provided, but this adds some extra frames to the call stack, which L{namedAny} must be able to account for. """ self.importer = ModuleImporter() self.importer.install()
def installImporter(): "This lets us import prep files directly" # the python import mechanics are only invoked if you call this, # since preppy has very few dependencies and I don't want to #add to them. from ihooks import ModuleLoader, ModuleImporter, install class PreppyLoader(ModuleLoader): "This allows prep files to be imported." def find_module_in_dir(self, name, dir, allow_packages=1): ModuleLoader = self.__class__.__bases__[0] stuff = ModuleLoader.find_module_in_dir(self, name, dir, allow_packages) if stuff: #print 'standard module loader worked' return stuff else: if dir: prepFileName = dir + os.sep + name + '.prep' else: prepFileName = name + '.prep' if os.path.isfile(prepFileName): #compile WITHOUT IMPORTING to avoid triggering recursion mod = compileModule(prepFileName, verbose=0, importModule=0) #now use the default... return ModuleLoader.find_module_in_dir( self, name, dir, allow_packages) else: return None loader = PreppyLoader() importer = ModuleImporter(loader=loader) install(importer)