Skip to content

Commit

Permalink
Support PEX_SCRIPT=pex3 ./pex ... for scie.
Browse files Browse the repository at this point in the history
Add a `--scie-busybox-pex-entrypoint-env-passthrough` option to trade a
small amount of perf for a Pex scie busybox accepting
PEX_{INTERPRETER,MODULE,SCRIPT} entry point control like its Pex PEX
sibling.
  • Loading branch information
jsirois committed Sep 10, 2024
1 parent 70c0c9d commit 1d2dbb2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
16 changes: 16 additions & 0 deletions pex/scie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ def register_options(parser):
"review the `install` command help."
),
)
parser.add_argument(
"--scie-busybox-pex-entrypoint-env-passthrough",
"--no-scie-busybox-pex-entrypoint-env-passthrough",
dest="scie_busybox_pex_entrypoint_env_passthrough",
default=False,
type=bool,
action=HandleBoolAction,
help=(
"When creating a busybox, allow entrypoint control via PEX_INTERPRETER, PEX_SCRIPT and "
"PEX_MODULE. Note that when using --venv this adds modest startup overhead on the "
"order of 10ms."
),
)
parser.add_argument(
"--scie-platform",
dest="scie_platforms",
Expand Down Expand Up @@ -269,6 +282,8 @@ def render_options(options):
entrypoints = list(options.busybox_entrypoints.console_scripts_manifest.iter_specs())
entrypoints.extend(map(str, options.busybox_entrypoints.ad_hoc_entry_points))
args.append(",".join(entrypoints))
if options.busybox_pex_entrypoint_env_passthrough:
args.append("--scie-busybox-pex-entrypoint-env-passthrough")
for platform in options.platforms:
args.append("--scie-platform")
args.append(str(platform))
Expand Down Expand Up @@ -368,6 +383,7 @@ def extract_options(options):
naming_style=options.naming_style,
scie_only=options.scie_only,
busybox_entrypoints=entry_points,
busybox_pex_entrypoint_env_passthrough=options.scie_busybox_pex_entrypoint_env_passthrough,
platforms=tuple(OrderedSet(options.scie_platforms)),
pbs_release=options.scie_pbs_release,
pypy_release=options.scie_pypy_release,
Expand Down
1 change: 1 addition & 0 deletions pex/scie/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class ScieOptions(object):
naming_style = attr.ib(default=None) # type: Optional[PlatformNamingStyle.Value]
scie_only = attr.ib(default=False) # type: bool
busybox_entrypoints = attr.ib(default=None) # type: Optional[BusyBoxEntryPoints]
busybox_pex_entrypoint_env_passthrough = attr.ib(default=False) # type: bool
platforms = attr.ib(default=()) # type: Tuple[SciePlatform.Value, ...]
pbs_release = attr.ib(default=None) # type: Optional[str]
pypy_release = attr.ib(default=None) # type: Optional[str]
Expand Down
18 changes: 13 additions & 5 deletions pex/scie/science.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,26 @@ def args(

def create_cmd(named_entry_point):
# type: (NamedEntryPoint) -> Dict[str, Any]
return {
"name": named_entry_point.name,
"env": {

if (
configuration.options.busybox_pex_entrypoint_env_passthrough
and named_entry_point.entry_point == pex_entry_point
):
env = {"default": default_env(named_entry_point), "remove_exact": ["PEX_VENV"]}
else:
env = {
"default": default_env(named_entry_point),
"replace": {"PEX_MODULE": str(named_entry_point.entry_point)},
"remove_exact": ["PEX_INTERPRETER", "PEX_SCRIPT", "PEX_VENV"],
},
}
return {
"name": named_entry_point.name,
"env": env,
"exe": "{scie.bindings.configure:PYTHON}",
"args": args(named_entry_point, "{scie.bindings.configure:PEX}"),
}

if pex_info.venv:
if pex_info.venv and not configuration.options.busybox_pex_entrypoint_env_passthrough:
# N.B.: Executing the console script directly instead of bouncing through the PEX
# __main__.py using PEX_SCRIPT saves ~10ms of re-exec overhead in informal testing; so
# it's worth specializing here.
Expand Down
1 change: 1 addition & 0 deletions scripts/create-packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def build_pex_scies(
"sha256",
"--scie-busybox",
"@pex",
"--scie-busybox-pex-entrypoint-env-passthrough",
"-o",
output_file,
"-c",
Expand Down

0 comments on commit 1d2dbb2

Please sign in to comment.