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

Add a way to specify script attribute for pex #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions pex/pex_rules.bzl
Original file line number Diff line number Diff line change
@@ -168,9 +168,15 @@ def _pex_binary_impl(ctx):

if ctx.attr.entrypoint and ctx.file.main:
fail("Please specify either entrypoint or main, not both.")
if ctx.attr.entrypoint and ctx.attr.script:
fail("Please specify either entrypoint or script, not both.")

if ctx.attr.entrypoint:
main_file = None
main_pkg = ctx.attr.entrypoint
elif ctx.attr.script:
main_file = None
main_pkg = None
elif ctx.file.main:
main_file = ctx.file.main
else:
@@ -218,9 +224,12 @@ def _pex_binary_impl(ctx):
arguments += ["--repo", repo]
for egg in py.transitive_eggs:
arguments += ["--find-links", egg.dirname]
if ctx.attr.script:
arguments += ["--script", ctx.attr.script]
else:
arguments += ["--entry-point", main_pkg]
arguments += [
"--pex-root", ".pex", # May be redundant since we also set PEX_ROOT
"--entry-point", main_pkg,
"--output-file", deploy_pex.path,
"--cache-dir", ".pex/build",
manifest_file.path,
@@ -349,6 +358,7 @@ pex_bin_attrs = _dmerge(pex_attrs, {
"main": attr.label(allow_files = True,
single_file = True),
"entrypoint": attr.string(),
"script": attr.string(),
"interpreter": attr.string(),
"pex_use_wheels": attr.bool(default=True),
"pex_verbosity": attr.int(default=0),
@@ -470,7 +480,7 @@ def pex_pytest(name, srcs, deps=[], eggs=[], data=[],

Almost all of the attributes that can be used with pex_test work identically
here, including those not specifically mentioned in this docstring.
Exceptions are `main` and `entrypoint`, which cannot be used with this macro.
Exceptions are `main` and `entrypoint` and `script`, which cannot be used with this macro.

Args:

@@ -480,6 +490,8 @@ def pex_pytest(name, srcs, deps=[], eggs=[], data=[],
fail("Specifying a `main` file makes no sense for pex_pytest.")
if "entrypoint" in kwargs:
fail("Do not specify `entrypoint` for pex_pytest.")
if "script" in kwargs:
fail("Do not specify `script` for pex_pytest.")

pex_binary(
name = "%s_runner" % name,