Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate entry point at build time (#521)
Resolves #508 ### Problem Current behavior allows building a pex that cannot execute: ``` [omerta ~]$ pex requests -e qqqqqqqqqqqq -o test.pex [omerta ~]$ ./test.pex Traceback (most recent call last): File ".bootstrap/_pex/pex.py", line 367, in execute File ".bootstrap/_pex/pex.py", line 293, in _wrap_coverage File ".bootstrap/_pex/pex.py", line 325, in _wrap_profiling File ".bootstrap/_pex/pex.py", line 410, in _execute File ".bootstrap/_pex/pex.py", line 468, in execute_entry File ".bootstrap/_pex/pex.py", line 473, in execute_module File "/Users/kwilson/Python/CPython-2.7.13/lib/python2.7/runpy.py", line 182, in run_module mod_name, loader, code, fname = _get_module_details(mod_name) File "/Users/kwilson/Python/CPython-2.7.13/lib/python2.7/runpy.py", line 107, in _get_module_details raise error(format(e)) ImportError: No module named qqqqqqqqqqqq ``` ### Solution Verify entry point at build time. E.g. `a.b.c:m` means we will try to do `from a.b.c import m` in a separate process. ### Result ``` $ find hello hello hello/test.py hello/tree.py # Invalid module $ python bin.py -D hello -e invalid.module -o x.pex --validate-entry-point Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named invalid.module Traceback (most recent call last): File "bin.py", line 758, in <module> main() File "bin.py", line 743, in main pex_builder.build(tmp_name, verify_entry_point=options.validate_ep) File "/Users/yic/workspace/pex/pex/pex_builder.py", line 529, in build self.freeze(bytecode_compile=bytecode_compile, verify_entry_point=verify_entry_point) File "/Users/yic/workspace/pex/pex/pex_builder.py", line 514, in freeze self._verify_entry_point() File "/Users/yic/workspace/pex/pex/pex_builder.py", line 263, in _verify_entry_point raise self.InvalidEntryPoint('Failed to:`{}`'.format(import_statement)) pex.pex_builder.InvalidEntryPoint: Failed to:`import invalid.module` # invalid method $ python bin.py -D hello -e test:invalid_method -o x.pex --validate-entry-point Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: cannot import name invalid_method Traceback (most recent call last): File "bin.py", line 758, in <module> main() File "bin.py", line 743, in main pex_builder.build(tmp_name, verify_entry_point=options.validate_ep) File "/Users/yic/workspace/pex/pex/pex_builder.py", line 529, in build self.freeze(bytecode_compile=bytecode_compile, verify_entry_point=verify_entry_point) File "/Users/yic/workspace/pex/pex/pex_builder.py", line 514, in freeze self._verify_entry_point() File "/Users/yic/workspace/pex/pex/pex_builder.py", line 263, in _verify_entry_point raise self.InvalidEntryPoint('Failed to:`{}`'.format(import_statement)) pex.pex_builder.InvalidEntryPoint: Failed to:`from test import invalid_method` # without the flag, invalid method still works $ python bin.py -D hello -e test:invalid_method -o x.pex ```
- Loading branch information