我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用pkg_resources.load_entry_point()。
def webServe(): if "--reload" in sys.argv: reload = True else: reload = False wait = 3 while True: try: sys.exit(load_entry_point('pyramid>=1.4.3', 'console_scripts', 'pserve')()) break except IndentationError as e: if reload: print("Failed to (re)start unsonic:", e) print("Restarting in %d seconds..." % wait) else: raise except SyntaxError as e: if reload: print("Failed to (re)start unsonic:", e) print("Restarting in %d seconds..." % wait) else: raise except ImportError as e: if reload: print("Failed to (re)start unsonic:", e) print("Restarting in %d seconds..." % wait) else: raise time.sleep(wait)
def setUp(self): args = sys.argv[1:] self.verbose = '-v' in args self.permanent_tempdir = '-p' in args self.njobs = args[args.index('-n') + 1] if '-n' in args else None if self.permanent_tempdir: tempdir = os.path.join(tempfile.gettempdir(), 'yam_test') if os.path.exists(tempdir) and '-d' in args: shutil.rmtree(tempdir) if not os.path.exists(tempdir): os.mkdir(tempdir) else: tempdir = tempfile.mkdtemp(prefix='yam_test_') self.cwd = os.getcwd() os.chdir(tempdir) self.tempdir = tempdir # for coverage put .coveragerc config file into tempdir # and append correct data_file parameter to config file covfn = os.path.join(self.cwd, '.coverage') if not os.path.exists('.coveragerc') and os.path.exists(covfn + 'rc'): _replace_in_file(covfn + 'rc', '.coveragerc', '[run]', '[run]\ndata_file = ' + covfn) self.plotdir = os.path.join(self.tempdir, 'plots') self.script = load_entry_point('yam', 'console_scripts', 'yam') total = 74 - 2 * self.permanent_tempdir self.pbar = tqdm.tqdm(total=total, desc='CLI tests passed')
def load_class(uri, default="gunicorn.workers.sync.SyncWorker", section="gunicorn.workers"): if inspect.isclass(uri): return uri if uri.startswith("egg:"): # uses entry points entry_str = uri.split("egg:")[1] try: dist, name = entry_str.rsplit("#", 1) except ValueError: dist = entry_str name = default try: return pkg_resources.load_entry_point(dist, section, name) except: exc = traceback.format_exc() msg = "class uri %r invalid or not found: \n\n[%s]" raise RuntimeError(msg % (uri, exc)) else: components = uri.split('.') if len(components) == 1: while True: if uri.startswith("#"): uri = uri[1:] if uri in SUPPORTED_WORKERS: components = SUPPORTED_WORKERS[uri].split(".") break try: return pkg_resources.load_entry_point("gunicorn", section, uri) except: exc = traceback.format_exc() msg = "class uri %r invalid or not found: \n\n[%s]" raise RuntimeError(msg % (uri, exc)) klass = components.pop(-1) try: mod = import_module('.'.join(components)) except: exc = traceback.format_exc() msg = "class uri %r invalid or not found: \n\n[%s]" raise RuntimeError(msg % (uri, exc)) return getattr(mod, klass)