From 883d13a7fdd26f11d29c574391b2e0a577f4b8bc Mon Sep 17 00:00:00 2001 From: wisechengyi Date: Tue, 17 Jul 2018 18:03:34 -0700 Subject: [PATCH] flag works --- bin.py | 4 ++-- pex/pex_builder.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bin.py b/bin.py index 4e87f37e7..7471df0b8 100755 --- a/bin.py +++ b/bin.py @@ -740,14 +740,14 @@ def main(args=None): log('Saving PEX file to %s' % options.pex_name, v=options.verbosity) tmp_name = options.pex_name + '~' safe_delete(tmp_name) - pex_builder.build(tmp_name) + pex_builder.build(tmp_name, verify_entry_point=options.validate_ep) os.rename(tmp_name, options.pex_name) return 0 if not _compatible_with_current_platform(options.platforms): log('WARNING: attempting to run PEX with incompatible platforms!') - pex_builder.freeze() + pex_builder.freeze(verify_entry_point=options.validate_ep) log('Running PEX file at %s with args %s' % (pex_builder.path(), cmdline), v=options.verbosity) pex = PEX(pex_builder.path(), interpreter=pex_builder.interpreter) diff --git a/pex/pex_builder.py b/pex/pex_builder.py index a30604bb7..2fe58268c 100644 --- a/pex/pex_builder.py +++ b/pex/pex_builder.py @@ -226,7 +226,7 @@ def set_script(self, script): 'Could not find script %r in any distribution %s within PEX!' % ( script, ', '.join(str(d) for d in self._distributions))) - def _verify_entry_point(self, entry_point): + def _verify_entry_point(self): """ Given entry_point `a.b.c:m`, make sure 1. a/b/c.py exists @@ -236,6 +236,7 @@ def _verify_entry_point(self, entry_point): :return: """ + entry_point = self._pex_info.entry_point ep_split = entry_point.split(':') # Only module is specified @@ -290,7 +291,6 @@ def set_entry_point(self, entry_point): The entry point may also be specified via ``PEXBuilder.set_executable``. """ self._ensure_unfrozen('Setting an entry point') - self._verify_entry_point(entry_point) self._pex_info.entry_point = entry_point def set_shebang(self, shebang): @@ -494,7 +494,7 @@ def _prepare_bootstrap(self): self._chroot.write(provider.get_resource_string(source_name, fn), os.path.join(self.BOOTSTRAP_DIR, target_location, fn), 'bootstrap') - def freeze(self, bytecode_compile=True): + def freeze(self, verify_entry_point, bytecode_compile=True): """Freeze the PEX. :param bytecode_compile: If True, precompile .py files into .pyc files when freezing code. @@ -508,11 +508,13 @@ def freeze(self, bytecode_compile=True): self._prepare_manifest() self._prepare_bootstrap() self._prepare_main() + if verify_entry_point: + self._verify_entry_point() if bytecode_compile: self._precompile_source() self._frozen = True - def build(self, filename, bytecode_compile=True): + def build(self, filename, bytecode_compile=True, verify_entry_point=False): """Package the PEX into a zipfile. :param filename: The filename where the PEX should be stored. @@ -522,7 +524,7 @@ def build(self, filename, bytecode_compile=True): PEXBuilder immutable. """ if not self._frozen: - self.freeze(bytecode_compile=bytecode_compile) + self.freeze(verify_entry_point=verify_entry_point, bytecode_compile=bytecode_compile) try: os.unlink(filename + '~') self._logger.warn('Previous binary unexpectedly exists, cleaning: %s' % (filename + '~'))