Navigation Menu

Skip to content

Commit

Permalink
Fix .pyc files being included to partially get reproducible PEX builds (
Browse files Browse the repository at this point in the history
#7841)

#7734 partially turned on reproducible PEX builds, but did not properly update every call site to avoid including `.pyc` files.

As decided there, we do not (at the moment) provide an opt-out to still include `.pyc` files at the expense of reproducible PEXes, because we deem this to be a sensible default.

Fixes part of #7808.
  • Loading branch information
Eric-Arellano committed Jun 4, 2019
1 parent e2b18b9 commit 9587e91
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 11 deletions.
Expand Up @@ -157,7 +157,7 @@ def _compile_target(self, vt):
pex_info.entry_point = self._EXEC_NAME
pex_info.pex_path = ':'.join(pex.path() for pex in (reqs_pex, srcs_pex) if pex)
builder = PEXBuilder(safe_path, interpreter, pex_info=pex_info)
builder.freeze()
builder.freeze(bytecode_compile=False)

pex = PEX(exec_pex_path, interpreter)

Expand Down
Expand Up @@ -342,7 +342,7 @@ def freeze(self):
dist = self._distributions.get('setuptools')
if not dist:
self.add_resolved_requirements([self._setuptools_requirement])
self._builder.freeze()
self._builder.freeze(bytecode_compile=False)
self._frozen = True

def set_entry_point(self, entry_point):
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/tasks/pytest_prep.py
Expand Up @@ -51,7 +51,7 @@ def __init__(self, interpreter, pex):
pex_path = pex.path()
pex_info = PexInfo.from_pex(pex_path)
pex_info.merge_pex_path(pex_path) # We're now on the sys.path twice.
PEXBuilder(pex_path, interpreter=interpreter, pex_info=pex_info).freeze()
PEXBuilder(pex_path, interpreter=interpreter, pex_info=pex_info).freeze(bytecode_compile=False)
self._pex = PEX(pex=pex_path, interpreter=interpreter)
self._interpreter = interpreter

Expand Down
Expand Up @@ -165,6 +165,6 @@ def create_pex(self, pex_info=None):
with self.merged_pex(path, pex_info, interpreter, pexes, constraints) as builder:
for extra_file in self.extra_files():
extra_file.add_to(builder)
builder.freeze()
builder.freeze(bytecode_compile=False)

return PEX(path, interpreter)
Expand Up @@ -141,4 +141,4 @@ def merged_pex(cls, path, pex_info, interpreter, pexes, interpeter_constraints=N
def merge_pexes(cls, path, pex_info, interpreter, pexes, interpeter_constraints=None):
"""Generates a merged pex at path."""
with cls.merged_pex(path, pex_info, interpreter, pexes, interpeter_constraints) as builder:
builder.freeze()
builder.freeze(bytecode_compile=False)
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/tasks/setup_py.py
Expand Up @@ -464,7 +464,7 @@ def nsutil_pex(self):
""").strip().format(declares_namespace_package_code=declares_namespace_package_code))
fp.close()
builder.set_executable(filename=fp.name, env_filename='main.py')
builder.freeze()
builder.freeze(bytecode_compile=False)
return PEX(pex=chroot, interpreter=interpreter)

def filter_namespace_packages(self, root_target, inits):
Expand Down
4 changes: 3 additions & 1 deletion testprojects/src/python/unicode/compilation_failure/BUILD
@@ -1 +1,3 @@
python_library()
python_binary(
source = 'main.py'
)
6 changes: 4 additions & 2 deletions testprojects/src/python/unicode/compilation_failure/main.py
@@ -1,4 +1,6 @@
# This file is expected to fail to "compile", and raise a unicode error while doing so.
# This file is expected to fail to "compile" when run via `./pants run` due to a SyntaxError.
# Because the error itself contains unicode, it can exercise that error handling codepaths
# are unicode aware.
import sys¡

if __name__ == '__main__':
import sys¡
3 changes: 1 addition & 2 deletions tests/python/pants_test/base/test_exiter_integration.py
Expand Up @@ -13,8 +13,7 @@ class ExiterIntegrationTest(PantsRunIntegrationTest):
@ensure_daemon
def test_unicode_containing_exception(self):
"""Test whether we can run a single target without special flags."""
pants_run = self.run_pants(['test', 'testprojects/src/python/unicode/compilation_failure'])
pants_run = self.run_pants(['run', 'testprojects/src/python/unicode/compilation_failure'])
self.assert_failure(pants_run)

self.assertIn('during bytecode compilation', pants_run.stderr_data)
self.assertIn('import sys¡', pants_run.stderr_data)

0 comments on commit 9587e91

Please sign in to comment.