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)
def __init__(self): """Create import hook.""" assert self._imp ihooks.ModuleLoader.__init__(self) self._lock = self._imp._lock imp = ihooks.ModuleImporter(loader=self) ihooks.install(imp) self._imp.recordModules()
def install(): global _installed if not _installed: hooks = PTLHooks() loader = PTLLoader(hooks) if cimport is not None: importer = cModuleImporter(loader) else: importer = ihooks.ModuleImporter(loader) ihooks.install(importer) _installed = True
def install(): """Main entry point. call this to install the import hook in your for a single Python process. If you want it to be installed whenever you use Python, add it to your sitecustomize (as described above). """ global _installed if not _installed: hooks = PyxHooks() loader = PyxLoader(hooks) if cimport is not None: importer = cModuleImporter(loader) else: importer = ihooks.ModuleImporter(loader) ihooks.install(importer) _installed = 1
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)
def install(v = 0): ihooks.install(PackageImporter(None, v))
stored_time = self.datestamps.get(testpath, 0) if stored_time < stinfo.st_mtime: self.datestamps[testpath] = stinfo.st_mtime if stored_time: warn("---------------------", name, "changed reloading", stored_time, stinfo.st_mtime, os.getcwd()) reload(sys.modules[name]) else: # warn("loading for the first time", testpath) if stinfo: self.datestamps[testpath] = stinfo.st_mtime m = ihooks.ModuleImporter.import_module(self, name, globals, locals, fromlist) try: testpath = m.__file__ stinfo = os.stat(testpath) if os.path.isfile(testpath): self.datestamps[testpath] = stinfo.st_mtime except AttributeError: pass return m warn("**********************8 installing autoreload") ihooks.install(AutoReload())
"""New import scheme with package support.
except AttributeError: pass if stinfo: stored_time = self.datestamps.get(testpath,0) if stored_time < stinfo.st_mtime: self.datestamps[testpath] = stinfo.st_mtime if stored_time: warn("---------------------", name, "changed reloading", stored_time, stinfo.st_mtime, os.getcwd()) reload(sys.modules[name]) else : # warn("loading for the first time", testpath) if stinfo: self.datestamps[testpath] = stinfo.st_mtime m = ihooks.ModuleImporter.import_module(self,name,globals,locals,fromlist) try: testpath = m.__file__ stinfo = os.stat(testpath) if os.path.isfile(testpath): self.datestamps[testpath] = stinfo.st_mtime except AttributeError: pass return m warn("**********************8 installing autoreload") ihooks.install(AutoReload())
def install(): """Install the import hook""" ihooks.install(ihooks.ModuleImporter(ShortcutLoader()))
def install(v=0): ihooks.install(PackageImporter(None, v))
def activate(self): imp = ihooks.ModuleImporter(loader=modloader) ihooks.install(imp) self.recordModules(sys.modules.keys()) self._installed = True
def install(rulesets): ihooks.install(ihooks.ModuleImporter(RulesetModuleLoader(rulesets)))
def install(): """Install the import hook""" ihooks.install(ihooks.ModuleImporter(MFileLoader(MFileHooks())))
--------------------------- class game: name = "uberDog" process = "server" __builtins__["game"] = game() import time import os import sys # Initialize ihooks importer On the production servers, we run genPyCode -n # meaning no squeeze, so nobody else does this. When we squeeze, the # unpacker does this for us and it does not hurt to do in either case. import ihooks ihooks.install() print("Initializing the UberDog (Uber Distributed Object Globals server)...") from otp.uberdog.UberDogGlobal import * from otp.uberdog.UberDog import UberDog from direct.showbase.PythonUtil import * uber.mdip = ConfigVariableString("msg-director-ip", "localhost").getValue() uber.mdport = ConfigVariableInt("msg-director-port", 6666).getValue() uber.esip = ConfigVariableString("event-server-ip", "localhost").getValue() uber.esport = ConfigVariableInt("event-server-port", 4343).getValue() serverId = ConfigVariableInt("district-ssid", 20100000).getValue()
head = name tail = "" if parent: qname = "%s.%s" % (parent.__name__, head) else: qname = head q = self.import_it(head, qname, parent) if q: return q, (tail, name) if parent: qname = head parent = None q = self.import_it(head, qname, parent) if q: return q, (tail, name) raise Utils.LocalizedImportError(name, "No module named " + qname) def load_tail(self, q, (tail, name)): m = q while tail: i = tail.find('.') if i < 0: i = len(tail) head, tail = tail[:i], tail[i+1:] mname = "%s.%s" % (m.__name__, head) m = self.import_it(head, mname, m) if not m: raise Utils.LocalizedImportError(name, "No module named " + mname) return m ihooks.install(ModuleImporter(WwmlLoader(WwmlHooks())))