cool-easter-32542
08/31/2023, 12:13 AMrunnable_dependencies field is documented as "Note that these dependencies will be made available on the PATH with the name of the target." https://www.pantsbuild.org/docs/reference-run_shell_command
This doesn't seem to work for `run_shell_command`: the command's $PATH is identical to that of the ambient shell that's running pants, and the targets cannot be executed, unlike shell_command.
Reproducer:
cd $(mktemp -d)
cat > pants.toml <<EOF
[GLOBAL]
pants_version = "2.16.0"
backend_packages.add = ["pants.backend.shell", "pants.backend.python"]
[python]
interpreter_constraints = ["==3.10.*"]
[anonymous-telemetry]
enabled = false
EOF
cat > BUILD <<'EOF'
python_source(name="some-script", source="some_script.py")
shell_command(
name="shell_command",
command="echo PATH=$PATH; some-script",
runnable_dependencies=[":some-script"],
log_output=True,
)
run_shell_command(
name="run_shell_command",
command="echo PATH=$PATH; some-script",
runnable_dependencies=[":some-script"],
)
EOF
echo 'print(f"hello from {__file__}")' > some_script.py
# GOOD: the shell_command can run the script and prints the hello (plus a limited $PATH):
pants export-codegen :shell_command
#> PATH=/private/.../pants-sandbox-.../_binary_shims_...:/private/.../pants-sandbox-.../_runnable_dependency_shims_...
#> hello from /private/.../pants_sandbox-..././some_script.py
# for reference, what's the ambient path?
echo "ambient PATH=$PATH"
# BUG: the run_shell_command has the same $PATH as above , and cannot run `some-script`
pants run :run_shell_command
#> PATH=<same as ambient>
#> some-script: command not found
The output is like, for example:
10:10:16.97 [INFO] Starting: Running the `shell_command` at `//:shell_command`
10:10:17.00 [INFO] Completed: Running the `shell_command` at `//:shell_command`
10:10:17.00 [INFO] PATH=/private/var/folders/sv/vd266m4d4lvctgs2wpnhjs9w0000gn/T/pants-sandbox-qzkXjv/_binary_shims_e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855:/private/var/folders/sv/vd266m4d4lvctgs2wpnhjs9w0000gn/T/pants-sandbox-qzkXjv/_runnable_dependency_shims_31adfb747358bcf19a253a85a320c383fb5e33abf35e8c2f7c7a8c1759f51c7a
hello from /private/var/folders/sv/vd266m4d4lvctgs2wpnhjs9w0000gn/T/pants-sandbox-qzkXjv/./some_script.py
10:10:17.00 [INFO] Writing generated files to dist/codegen
ambient PATH=/opt/homebrew/opt/sdkman-cli/libexec/candidates/java/current/bin:...:/opt/homebrew/bin:/Users/huon/.cargo/bin
PATH=/opt/homebrew/opt/sdkman-cli/libexec/candidates/java/current/bin:...:/opt/homebrew/bin:/Users/huon/.cargo/bin
pants run //:run_shell_command --: some-script: command not found
Pants version
2.16.0, 2.17.0
OS
macOS
Additional info
Add any other information about the problem here, such as attachments or links to gists, if relevant.
pantsbuild/pants