Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pex_binary: Support PEXes with no entry points (interpreters) #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ pex_pytest(
deps = [":libfoo"],
size = "small",
)

# Tests that building a pex without entry points is supported
pex_binary(
name = "interpreter_only",
)
sh_test(
name = "interpreter_only_test",
srcs = ["interpreter_only_test.py"],
data = [":interpreter_only"],
args = ["$(location :interpreter_only)"],
)
17 changes: 17 additions & 0 deletions examples/interpreter_only_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python2.7

import sys
import subprocess

def main():
if len(sys.argv) != 2:
sys.stderr.write('Error: Pass path to an interpreter pex\n')
sys.exit(1)
interpreter_pex_path = sys.argv[1]

output = subprocess.check_output([interpreter_pex_path], stderr=subprocess.STDOUT)
assert 'InteractiveConsole' in output
print 'PASS'

if __name__ == '__main__':
main()
7 changes: 5 additions & 2 deletions pex/pex_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,16 @@ def _pex_binary_impl(ctx):

if ctx.attr.entrypoint and ctx.file.main:
fail("Please specify either entrypoint or main, not both.")
main_file = None
main_pkg = ''
if ctx.attr.entrypoint:
main_file = None
main_pkg = ctx.attr.entrypoint
elif ctx.file.main:
main_file = ctx.file.main
else:
main_file = pex_file_types.filter(ctx.files.srcs)[0]
filtered_srcs = pex_file_types.filter(ctx.files.srcs)
if filtered_srcs:
main_file = filtered_srcs[0]
if main_file:
# Translate main_file's short path into a python module name
main_pkg = main_file.short_path.replace('/', '.')[:-3]
Expand Down