def load(self): if self.loaded: reloader.reload(self.module) self.loaded = True fn = getattr(self.module, self.fn_name) check.is_callable(fn) obj = fn() # Eventually this class will be generic and not coupled to # Pipeline / Repository types. Tracking this issue here: # https://github.com/dagster-io/dagster/issues/246 if self.coerce_to_repo: if isinstance(obj, RepositoryDefinition): self.object = obj elif isinstance(obj, PipelineDefinition): self.object = RepositoryDefinition( name=EMPHERMAL_NAME, pipeline_dict={obj.name: lambda: obj}) else: raise InvalidPipelineLoadingComboError( 'entry point must return a repository or pipeline') else: self.object = obj return self.object
def on_pubmsg(self,c,e): if e.target in self.channels: ch = self.channels[e.target] if self.boss in e.source and e.arguments[0] == '.reload': reloader.reload(trpbot_commands) self.build_commands() self.add_mqueue(c,e.target,'reload complete')
def reload_grammars(): unload() global grammar grammar = Grammar("to rule them all") now = datetime.datetime.now() print "begun reloading at %s:%s" % (now.hour, now.minute) # reload module and re-add the rules imported from that module global GRAMMAR_IMPORTS for import_name in GRAMMAR_IMPORTS: try: reloader.reload(sys.modules[import_name]) import_rule = getattr(__import__(import_name, fromlist=["rules"]), "rules") grammar.add_rule(import_rule) print "Loaded module %s successfully" % import_name except RuntimeError as runtime_error: "There was an error in file %s" % import_name print runtime_error, '\n', '\n' except NameError as nameerror: "Forgot something in file %s?" % import_name print nameerror, '\n', '\n' grammar.add_rule(get_reloader_rules()) # for the "reload grammar module" code in get_reloader_rules grammar.load() print "reloaded all modules"
def _reload(self, filenames): modules = [ m for m in sys.modules.values() if _normalize_filename(getattr(m, '__file__', None)) in filenames] for mod in modules: reloader.reload(mod)
def execute(self, parameters, messages): """The source code of the tool.""" reloader.reload( GNDB_executes ) # Only relevant while debugging the GNDB_executes.py source result = GNDB_executes.GNDBruninTOC_execute(parameters, messages) arcEC.SetMsg("Execute() returned: " + str(result), 0) return result
def on_pubmsg(self, c, e): if e.target in self.channels: ch = self.channels[e.target] if self.boss in e.source and e.arguments[0] == '.reload': reloader.reload(trpbot_commands) self.build_commands() self.add_mqueue(c, e.target, 'Reload complete.') elif self.boss in e.source and e.arguments[0] == '.die': raise KeyboardInterrupt('Die Command Received.') msg = e.arguments[0].strip() nick = e.source.nick mcmsg = ' '.join(e.arguments).encode('ascii', 'ignore') #uprint(mcmsg) if reply == '1': if c.get_nickname() in mcmsg: #time.sleep(0.2) #to prevent flooding #mcmsg = re.compile(c.get_nickname() + '[:,]* ?', re.I).sub('', mcmsg) prefix = '%s: ' % (nick, ) else: prefix = '' add_to_brain(mcmsg, chain_length, write_to_file=True) #uprint(mcmsg) #prints to stdout what sadface added to brain if prefix or random.random() <= chattiness: sentence = generate_sentence(mcmsg, chain_length, max_words) if sentence: self.add_mqueue(c, e.target, prefix + sentence) #uprint(prefix + sentence) # ">" + "\t" + sentence #prints to stdout what sadface said # Replies to messages starting with the bot's name. elif reply == '2': if mcmsg.startswith( c.get_nickname): #matches nickname, mecause of Noxz #time.sleep(0.2) #to prevent flooding #mcmsg = re.compile(c.get_nickname + "[:,]* ?", re.I).sub('', mcmsg) prefix = "%s: " % (nick, ) else: #mcmsg = re.compile(c.get_nickname + "[:,]* ?", re.I).sub('', mcmsg) prefix = '' add_to_brain(mcmsg, chain_length, write_to_file=True) #print "\t" + msg #prints to stdout what sadface added to brain if prefix or random.random() <= chattiness: sentence = generate_sentence(mcmsg, chain_length, max_words) if sentence: self.add_mqueue(c, e.target, prefix + sentence) #uprint(prefix + sentence) #prints to stdout what sadface said else: #for when you don't want it talking back #print mcmsg prefix = '' add_to_brain(mcmsg, chain_length, write_to_file=True) if prefix or random.random() <= chattiness: # sentence = generate_sentence(mcmsg, chain_length, max_words) pass
def on_pubmsg(self,c,e): if e.target in self.channels: ch = self.channels[e.target] if self.boss in e.source and e.arguments[0] == '.reload': reloader.reload(trpbot_commands) self.build_commands() self.add_mqueue(c,e.target,'Reload complete.') elif self.boss in e.source and e.arguments[0] =='.die': raise KeyboardInterrupt('Die Command Received.') msg = e.arguments[0].strip() nick = e.source.nick mcmsg = ' '.join(e.arguments).encode('ascii','ignore') #uprint(mcmsg) if reply == '1': if c.get_nickname() in mcmsg: #time.sleep(0.2) #to prevent flooding #mcmsg = re.compile(c.get_nickname() + '[:,]* ?', re.I).sub('', mcmsg) prefix = '%s: ' % (nick, ) else: prefix = '' add_to_brain(mcmsg, chain_length, write_to_file=True) #uprint(mcmsg) #prints to stdout what sadface added to brain if prefix or random.random() <= chattiness: sentence = generate_sentence(mcmsg, chain_length, max_words) if sentence: self.add_mqueue(c,e.target,prefix + sentence) #uprint(prefix + sentence) # ">" + "\t" + sentence #prints to stdout what sadface said # Replies to messages starting with the bot's name. elif reply == '2': if mcmsg.startswith(c.get_nickname): #matches nickname, mecause of Noxz #time.sleep(0.2) #to prevent flooding #mcmsg = re.compile(c.get_nickname + "[:,]* ?", re.I).sub('', mcmsg) prefix = "%s: " % (nick, ) else: #mcmsg = re.compile(c.get_nickname + "[:,]* ?", re.I).sub('', mcmsg) prefix = '' add_to_brain(mcmsg, chain_length, write_to_file=True) #print "\t" + msg #prints to stdout what sadface added to brain if prefix or random.random() <= chattiness: sentence = generate_sentence(mcmsg, chain_length, max_words) if sentence: self.add_mqueue(c,e.target,prefix + sentence) #uprint(prefix + sentence) #prints to stdout what sadface said else: #for when you don't want it talking back #print mcmsg prefix = '' add_to_brain(mcmsg, chain_length, write_to_file=True) if prefix or random.random() <= chattiness: # sentence = generate_sentence(mcmsg, chain_length, max_words) pass
def reload_module(): try: reloader.reload(detect) except Exception as e: traceback.print_tb(e.__traceback__) texts += '\n'.join(traceback.format_tb( e.__traceback__)).split('\n') texts.append(str(e)) game_render = np.copy(b.frame()) writeOverlayText(game_render, texts) screen.blit(cvimage_to_pygame(game_render), (0, 0)) # Load new image on screen render(reloaded=True)
def test_reload(self): import reloader reloader.enable() self.write_module('testmodule', "def func(): return 'Some code.'\n") from tests import testmodule self.assertEqual('Some code.', testmodule.func()) self.write_module('testmodule', "def func(): return 'New code.'\n") reloader.reload(testmodule) self.assertEqual('New code.', testmodule.func()) self.write_module('testmodule', "def func(): return 'More code.'\n") reloader.reload(testmodule) self.assertEqual('More code.', testmodule.func())
async def respondImpersonate(self, prefix, suffix, message, timer=NoTimer()): reloaded = reloader.reload(markov, "markov.py") sid = message.channel.server.id if reloaded or not sid in self.markovs: self.log("Loading corpus") corpus = self.markovs[sid] self.log("Loaded corpus") corpus = self.markovs[sid] names = re.split(",", suffix.strip()) names = [name.strip() for name in names] try: ids = [self.userNameCache[name] for name in names] except KeyError as key: return "Data for {0} not found {1}".format(key, g_Lann) try: lines = corpus.impersonate(ids, 1) if lines: reply = lines[0] if message.channel.type != discord.ChannelType.private: reply = await self.stripMentions(reply, message.channel.server) return reply return "Hmm... I couldn't think of anything to say {0}".format( g_Lann) except Exception as e: self.log(e) return g_Lann
def test_reload(self): import reloader reloader.enable() self.write_module("testmodule", "def func(): return 'Some code.'\n") import tests.testmodule self.assertEqual("Some code.", tests.testmodule.func()) self.write_module("testmodule", "def func(): return 'New code.'\n") reloader.reload(tests.testmodule) self.assertEqual("New code.", tests.testmodule.func()) self.write_module("testmodule", "def func(): return 'More code.'\n") reloader.reload(tests.testmodule) self.assertEqual("More code.", tests.testmodule.func()) reloader.disable()
def import_apps(): """import or reimport modules and exposed static files""" reloader.enable() folder = os.environ['WEB3PY_APPLICATIONS_FOLDER'] app = bottle.default_app() app.routes.clear() # app.routes = app.routes[:] new_apps = [] for app_name in os.listdir(folder): path = os.path.join(folder, app_name) if os.path.isdir(path) and not path.endswith('__'): try: module = Reloader.MODULES.get(app_name) if not module: module = importlib.import_module(app_name) Reloader.MODULES[app_name] = module new_apps.append(path) else: reloader.reload(module) Reloader.ERRORS[app_name] = None except: print(traceback.format_exc()) Reloader.ERRORS[app_name] = traceback.format_exc() reloader.disable() # expose static files for path in new_apps: @bottle.route('/%s/static/<filename:path>' % path.split(os.path.sep)[-1]) def server_static(filename, path=path): return bottle.static_file(filename, root=os.path.join(path, 'static')) # register routes routes = [] def to_filename(module): filename = module.replace('.', os.path.sep) filename = os.path.join(filename, '__init__.py') if not module.count('.') else filename + '.py' return filename for route in app.routes: func = route.callback routes.append({'rule': route.rule, 'method': route.method, 'filename': to_filename(func.__module__), 'action': func.__name__}) Reloader.ROUTES = sorted(routes, key=lambda item: item['rule'])
async def on_message(message): try: global my_soph if reloader.reload(soph, "soph.py"): my_soph = soph.Soph(my_soph.corpus, client = client) response = await my_soph.consume(message) if response: await client.send_message(message.channel, response[0:1000]) except Exception as e: print (e) print (traceback.format_exc())
def reloadallmodules(): from config import es_constants from database import connectdb from database import querydb from apps.productmanagement import datasets from apps.productmanagement import products import reloader reloader.enable() # print reloader.get_dependencies(es_constants) reloader.reload(es_constants) reloader.reload(connectdb) reloader.reload(querydb) reloader.reload(datasets) reloader.reload(products) reloader.disable() # reloader.reload(sys.modules['config']) # from config import es_constants as constantsreloaded # for setting in constantsreloaded.es2globals: # logger.info(setting + ': ' + str(es_constants.es2globals[setting]))
import reloader reloader.enable(blacklist=['zope.interface', 'numpy', 'twisted', 'labrad']) #import scripts.PulseSequences.subsequences.OpticalPumpingContinuous #m = scripts.PulseSequences.subsequences.OpticalPumpingContinuous import scripts.PulseSequences.delete_later m = scripts.PulseSequences.delete_later reloader.reload(m) #print reloader.get_dependencies(scripts.PulseSequences.subsequences.OpticalPumpingContinuous)
def import_apps(): """import or reimport modules and exposed static files""" reloader.enable() folder = os.environ['WEB3PY_APPS_FOLDER'] app = bottle.default_app() app.routes.clear() new_apps = [] for app_name in os.listdir(folder): path = os.path.join(folder, app_name) init = os.path.join(path, '__init__.py') if os.path.isdir( path) and not path.endswith('__') and os.path.exists(init): module_name = 'apps.%s' % app_name try: module = Reloader.MODULES.get(app_name) if not module: print('[ ] loading %s ...' % app_name) module = importlib.machinery.SourceFileLoader( module_name, init).load_module() Reloader.MODULES[app_name] = module new_apps.append(path) print('\x1b[A[OK] loaded %s ' % app_name) else: print('[ ] reloading %s ...' % app_name) reloader.reload(module) print('\x1b[A[OK] loaded %s ' % app_name) Reloader.ERRORS[app_name] = None except: print('\x1b[A[FAILED] loading %s ' % app_name) print('\n'.join( ' ' + line for line in traceback.format_exc().split('\n'))) Reloader.ERRORS[app_name] = traceback.format_exc() reloader.disable() # expose static files for path in new_apps: @bottle.route('/%s/static/<filename:path>' % path.split(os.path.sep)[-1]) def server_static(filename, path=path): return bottle.static_file(filename, root=os.path.join(path, 'static')) # register routes routes = [] def to_filename(module): filename = os.path.join(*module.split('.')[1:]) filename = os.path.join(filename, '__init__.py') if not filename.count( os.sep) else filename + '.py' return filename for route in app.routes: func = route.callback routes.append({ 'rule': route.rule, 'method': route.method, 'filename': to_filename(func.__module__), 'action': func.__name__ }) Reloader.ROUTES = sorted(routes, key=lambda item: item['rule'])
import reloader reloader.enable(blacklist = ['zope.interface', 'numpy','twisted','labrad']) #import scripts.PulseSequences.subsequences.OpticalPumpingContinuous #m = scripts.PulseSequences.subsequences.OpticalPumpingContinuous import scripts.PulseSequences.delete_later m = scripts.PulseSequences.delete_later reloader.reload(m) #print reloader.get_dependencies(scripts.PulseSequences.subsequences.OpticalPumpingContinuous)
def _reload(self, filenames): for mod in self._matching_modules(filenames): reloader.reload(mod)
def reload(): reloader.reload(handler) reloader.reload(script_handler) return "重载方法"
b.prev() render() if event.key == pygame.K_COMMA: for i in range(20): b.prev() render() if event.key == pygame.K_PERIOD: for i in range(20): b.next() render() if event.key == pygame.K_r: try: reloader.reload(detect) except Exception as e: print(e) render(reloaded=True) if event.key == pygame.K_d: disabled = not disabled render() end = time.time() pygame.display.update() # Update pygame display clock.tick(30) fps = 1.0 / (end - start) observer.stop() observer.join()
def rescan_runner(number, frame): reloader.enable() reloader.reload(objshrunner) factories[0].runner.scan()
def scan(self,runner_folder): base_dir = os.path.abspath(os.path.dirname(__file__)) loaded_module_names = sys.modules.keys() module_to_reload = [] # pat to recognize a runner script has_runner_pat = re.compile('^@(after_|before_)?runner') for root,folders,files in os.walk(runner_folder): runner_folder_root = os.path.normpath(os.path.join(runner_folder,root)) relpath = os.path.relpath(runner_folder_root,base_dir) paths = runner_folder_root.split('/') if (not relpath.startswith('..')) and len(relpath.split('/'))<2: sub_foldername = None if relpath=='.': foldername = None lib_folder = base_dir else: foldername = paths[-1] lib_folder = os.path.join(base_dir,paths[-1]) else: foldername = paths[-2] sub_foldername = paths[-1] lib_folder = '/'+os.path.join(*paths[:-2]) lib_folder_inserted = False if not lib_folder in sys.path: lib_folder_inserted = True sys.path.insert(0,lib_folder) for file in files: if file.startswith('.') or file.startswith('_'): continue elif file[-3:]=='.py': # avoid to load twice if execution is from the runner subfolder for unit testing file_path = os.path.join(runner_folder_root,file) # only load file which wants to register runner is_runner_script = False fd = open(file_path,'r') for line in fd: if not has_runner_pat.search(line): continue is_runner_script = True break fd.close() if not is_runner_script: continue name = os.path.splitext(file)[0] if sub_foldername is None: module_name = '%s.%s' % (foldername,name) else: module_name = '%s.%s.%s' % (foldername,sub_foldername, name) if module_name in loaded_module_names: log.msg('reload runner %s' % (module_name)) module_to_reload.append(module_name) else: log.msg('load runner %s' % (module_name)) log.msg('lib ',lib_folder) __import__(module_name, globals(), locals(), [], 0) # remove added path if lib_folder_inserted: sys.path.remove(lib_folder) if len(module_to_reload): reloader.enable() for module_name in module_to_reload: reloader.reload(sys.modules[module_name]) reloader.disable()