I'm trying to express "run this runnable (a pex) w...
# general
c
I'm trying to express "run this runnable (a pex) with these args, depending on [these files], and letting in ENV_VAR_FOO)" as discrete thing that can itself be run. I /though/ that would be a chance to try out
adhoc_tool
But pants tells me (NoApplicableTargetsException) that I can't
run
an
adhoc_tool
I'm unsure if I'm missing something obvious here or should be looking at another target type (
shell_command
?).
c
not all targets are runnable. I was about to suggest to look at the union members of
RunFieldSet
to get an idea what targets you have that are runnable, but it turns out it was non-obvious what targets those apply to..
Copy code
pants RunFieldSet --help
13:17:19.62 [INFO] Initializing scheduler...
13:17:23.81 [INFO] Scheduler initialized.

`pants.core.goals.run.RunFieldSet` api type
-------------------------------------------

The fields necessary from a target to run a program/script.

activated by : pants.core
union members: DeployJarFieldSet
               DockerRunFieldSet
               GoBinaryFieldSet
               JavaFieldSet
               JvmArtifactFieldSet
               PexBinaryFieldSet
               PyOxidizerFieldSet
               PythonRequirementFieldSet
               PythonSourceFieldSet
               RunShellCommand
               ScalaFieldSet

Include API types and rules dependency information by running `./pants help-advanced pants.core.goals.run.RunFieldSet`.
c
So I see that way that
shell_command
isn't runnable either:
Copy code
NoApplicableTargetsException: No applicable files or targets matched. The `run` goal works with these target types:

  * docker_image
  * pex_binary
  * python_requirement
  * python_source
  * python_test
  * run_shell_command
So I tried
run_shell_command
Copy code
$ ./pants help run_shell_command
Unknown entity: run_shell_command
:-/ But the ergonomics there are awkward:
Copy code
run_shell_command(
    command="cd {chroot} && ./src.py.foo/bar-cli.pex --help",
and
workdir='.'
seems to be ignored. Still feel like I'm missing something! (2.16.0.dev7)
c
The help ought to work.. do you have the shell backend enabled?
Copy code
Activated by pants.backend.shell
c
Copy code
backend_packages = [
  "pants.backend.build_files.fmt.black",
  "pants.backend.docker",
  "pants.backend.docker.lint.hadolint",
  "pants.backend.experimental.adhoc",
  "pants.backend.experimental.helm",
  "pants.backend.python",
  "pants.backend.python.mixed_interpreter_constraints",
  "pants.backend.python.typecheck.mypy",
  "pants.backend.shell"
]
c
cc @ancient-vegetable-10556 regarding the workdir and ergonomics as he’s deep into that 😉
a
👀
When you say “run”, do you mean “consume as a build step”, or something else?
Oh right, I see you mean
pants run
So at the moment,
adhoc_tool
is really only meant for things that are being run for side-effects in the sandbox, not orchestrating tools for use with
pants run
Currently the awkwardness of
run_shell_command
is your best bet. If there’s weirdness going on with
workdir
, it’d be useful if you can file an issue for it
c
Thanks for the clarification! Tickets filed https://github.com/pantsbuild/pants/issues/18333 https://github.com/pantsbuild/pants/issues/18335 I didn't file a ticket for this circular message:
Copy code
14:52:42.99 [WARN] DEPRECATED: the target name run_shell_command is scheduled to be removed in version 2.18.0.dev0.

Instead, use `run_shell_command`, which behaves the same. Run `./pants update-build-files` to automatically fix your BUILD files.
Since I think https://github.com/pantsbuild/pants/commit/51de7e7a873984e5ea17ac4f7d45e14447a7a593 already fixed that
👍 1