https://pantsbuild.org/ logo
#development
Title
# development
f

future-oxygen-10553

04/20/2023, 3:18 PM
I have a question about the docs for the `pex_binary.args` option. The annotation says that it should be an
Iterable[str]
, which from my experience with
subprocess.run
means it should be
["arg1", "arg2"]
, but this results in an error from Pex that the args should be a single string. I presume this behavior is intentional, but then does the
pex_binary.args
need to be an iterable? Could it just be a single string? If it needs to be an iterable for typing, I can try to update the docs
1
e

enough-analyst-54434

04/20/2023, 4:20 PM
Just to make sure you're building up from ground truth as you read Pants code:
Copy code
jsirois@Gill-Windows:~ $ pex --inject-args Hello --inject-args Nay --inject-args "Moo, Moo" cowsay -c cowsay -o cowsay.pex
jsirois@Gill-Windows:~ $ ./cowsay.pex
  __________________
| Hello Nay Moo, Moo |
  ==================
                  \
                   \
                     ^__^
                     (oo)\_______
                     (__)\       )\/\
                         ||----w |
                         ||     ||
jsirois@Gill-Windows:~ $ pex-tools cowsay.pex info -i2 | jq .inject_args
[
  "Hello",
  "Nay",
  "Moo,",
  "Moo"
]
So you can both pass multiple
--inject-args
and Pex
shlex.split
s each arg you inject.
Copy code
jsirois@Gill-Windows:~ $ pex --inject-args Hello --inject-args Nay --inject-args '"Moo, Moo"' cowsay -c cowsay -o cowsay.pex
jsirois@Gill-Windows:~ $ ./cowsay.pex
  __________________
| Hello Nay Moo, Moo |
  ==================
                  \
                   \
                     ^__^
                     (oo)\_______
                     (__)\       )\/\
                         ||----w |
                         ||     ||
jsirois@Gill-Windows:~ $ pex-tools cowsay.pex info -i2 | jq .inject_args
[
  "Hello",
  "Nay",
  "Moo, Moo"
]
f

future-oxygen-10553

04/20/2023, 4:44 PM
So from the pants side, how should this behave? Should pants be turning an iterable of strings into multiple
--inject-args
parts for the pex?
e

enough-analyst-54434

04/20/2023, 4:46 PM
That's where I leave off except to say it seems to me the answer should flow from the principle that Pants should never get in the way of using the tools it supports. So however Pants spells it, it should probably be as close as possible to how the tool spells it and allow you to do all the same things. Deviating from that only leads to frustration for end users.
f

future-oxygen-10553

04/20/2023, 4:47 PM
Thanks for clarifying @enough-analyst-54434! I didn’t actually know about multiple
--inject-args
for pex either, so TIL
c

curved-television-6568

04/21/2023, 1:19 AM
but this results in an error from Pex that the args should be a single string.
are you able to show the error message and actual BUILD file target? (redacted if need be)
f

future-oxygen-10553

04/21/2023, 2:27 PM
Target:
Copy code
pex_binary(
    name="inference-server",
    layout="packed",
    include_tools=True,
    dependencies=["./ackbar/inference_server"],
    platforms=["linux_x86_64-cp-310-cp310"],
    script="uvicorn",
    args=["<http://ackbar.inference_server.app:app|ackbar.inference_server.app:app>", "--host", "0.0.0.0", "--port", "8080"],
)
Error:
Copy code
pants package src:inference-server
08:26:57.83 [INFO] Initializing scheduler...
08:26:59.05 [INFO] Scheduler initialized.
08:27:00.98 [INFO] Completed: Building 2 requirements for src/inference-server.pex from the 3rdparty/python-lock.txt resolve: fastapi<0.96.0,>=0.95.1, uvicorn[standard]>=0.21.1
08:27:00.99 [ERROR] 1 Exception encountered:

Engine traceback:
  in `package` goal

ProcessExecutionFailure: Process 'Building 2 requirements for src/inference-server.pex from the 3rdparty/python-lock.txt resolve: fastapi<0.96.0,>=0.95.1, uvicorn[standard]>=0.21.1' failed with exit code 2.
stdout:

stderr:
usage: pex [-o OUTPUT.PEX] [options] [-- arg1 arg2 ...]

pex builds a PEX (Python Executable) file based on the given specifications: sources, requirements, their dependencies and other options.
Command-line options can be provided in one or more files by prefixing the filenames with an @ symbol. These files must contain one argument per line.
pex: error: argument --inject-args: expected one argument



Use `--keep-sandboxes=on_failure` to preserve the process chroot for inspection.
This is with pants 2.16.0rc0
c

curved-television-6568

04/21/2023, 2:37 PM
I suspect a bug in pants, where
str(injected_arg)
ought to have been
repr(injected_arg)
Try this as work-around:
Copy code
args=["<http://ackbar.inference_server.app:app|ackbar.inference_server.app:app>", "'--host'", "0.0.0.0", "'--port'", "8080"],
i.e. quote the
--
options
what I expect you’d see in the debug log is something like this:
Copy code
pex --inject-args <http://ackbar.inference_server.app:app|ackbar.inference_server.app:app> --inject-args --host --inject-args 0.0.0.0 ...
and there it’s clear pex will see
--host
as a pex arg, not the value for inject-args.
f

future-oxygen-10553

04/21/2023, 2:44 PM
Thanks @curved-television-6568 that workaround worked!
c

curved-television-6568

04/21/2023, 2:45 PM
sweet. cc @happy-kitchen-89482