def execute_pkg_resources(cls, spec): # type: (str) -> Any entry = EntryPoint.parse("run = {}".format(spec)) cls.demote_bootstrap() runner = entry.resolve() return runner()
def _resolve_as_ep(val): """ Load the indicated attribute value, called, as a as if it were specified as an entry point. """ if val is None: return parsed = EntryPoint.parse("x=" + val) return parsed.resolve()()
def write_entries(cmd, basename, filename): ep = cmd.distribution.entry_points if isinstance(ep, six.string_types) or ep is None: data = ep elif ep is not None: data = [] for section, contents in sorted(ep.items()): if not isinstance(contents, six.string_types): contents = EntryPoint.parse_group(section, contents) contents = '\n'.join(sorted(map(str, contents.values()))) data.append('[%s]\n%s\n\n' % (section, contents)) data = ''.join(data) cmd.write_or_delete_file('entry points', filename, data, True)
def gen_header(self): epm = EntryPoint.parse_map(self.distribution.entry_points or '') ep = epm.get('setuptools.installation', {}).get('eggsecutable') if ep is None: return 'w' # not an eggsecutable, do it the usual way. if not ep.attrs or ep.extras: raise DistutilsSetupError( "eggsecutable entry point (%r) cannot have 'extras' " "or refer to a module" % (ep, )) pyver = sys.version[:3] pkg = ep.module_name full = '.'.join(ep.attrs) base = ep.attrs[0] basename = os.path.basename(self.egg_output) header = ( "#!/bin/sh\n" 'if [ `basename $0` = "%(basename)s" ]\n' 'then exec python%(pyver)s -c "' "import sys, os; sys.path.insert(0, os.path.abspath('$0')); " "from %(pkg)s import %(base)s; sys.exit(%(full)s())" '" "$@"\n' 'else\n' ' echo $0 is not the correct name for this egg file.\n' ' echo Please rename it back to %(basename)s and try again.\n' ' exec false\n' 'fi\n') % locals() if not self.dry_run: mkpath(os.path.dirname(self.egg_output), dry_run=self.dry_run) f = open(self.egg_output, 'w') f.write(header) f.close() return 'a'
sys.path.insert(0, os.path.abspath(os.path.join(__entry_point__, '.bootstrap'))) try: # PEX >= 1.6.0 from pex.third_party.pkg_resources import EntryPoint as __EntryPoint from pex.pex_bootstrapper import bootstrap_pex_env, is_compressed except ImportError: # PEX < 1.6.0 has an install requirement of setuptools which we leverage knowledge of. from pkg_resources import EntryPoint as __EntryPoint from _pex.pex_bootstrapper import bootstrap_pex_env, is_compressed bootstrap_pex_env(__entry_point__) if is_compressed(__entry_point__): import contextlib, zipfile with contextlib.closing(zipfile.ZipFile(__entry_point__)) as zf: __lambdex_info_blob = zf.read('LAMBDEX-INFO') else: with open(os.path.join(__entry_point__, 'LAMBDEX-INFO'), 'rb') as fp: __lambdex_info_blob = fp.read() import json as __json __lambdex_info = __json.loads(__lambdex_info_blob) __RUNNER = __EntryPoint.parse('run = %s' % __lambdex_info['entry_point']).resolve() def handler(event, context): return __RUNNER(event, context)
def execute_pkg_resources(cls, spec): entry = EntryPoint.parse("run = {}".format(spec)) cls.demote_bootstrap() runner = entry.resolve() return runner()