full-author-61014
01/05/2024, 8:32 PMsystem_binary(
name="drawio",
binary_name="drawio",
fingerprint_args=["--version"],
)
This leads to
ValueError: Could not find a binary with name `drawio`. The following paths were searched: /bin, /opt/drawio, /opt/homebrew/bin, /usr/bin, /usr/local/bin, /usr/sbin.
When looking at the generated __run.sh
#!/usr/bin/env bash
# This command line should execute the same process as pants did internally.
cd /tmp/pants-sandbox-lpxUQZ
env -i /opt/drawio/drawio --version
and executing it manually, it reveals the problem
[134070:0105/234425.825288:ERROR:ozone_platform_x11.cc(240)] Missing X server or $DISPLAY
[134070:0105/234425.825328:ERROR:env.cc(257)] The platform failed to initialize. Exiting.
./__run.sh: line 4: 134070 Segmentation fault (core dumped) env -i /opt/drawio/drawio --version
Drawio relies on the DISPLAY variable which is lost after executing with env -i
.
Is there an option to preserve a named list of environment variables when fingerprinting?late-keyboard-89314
01/05/2024, 8:46 PMsubprocess-environment
subsystem to configure which env vars are included globally: https://www.pantsbuild.org/docs/reference-subprocess-environmentlate-keyboard-89314
01/05/2024, 8:46 PMpants.toml
should work:
[subprocess-environment]
env_vars.add = ["DISPLAY"]
late-keyboard-89314
01/05/2024, 8:48 PMfull-author-61014
01/05/2024, 9:10 PM[subprocess-environment]
env_vars = [ "FOO=BAR" ]
Does not appear in the file.full-author-61014
01/05/2024, 10:09 PM-i
completely clears the environment. The link you mentioned https://www.pantsbuild.org/docs/reference-subprocess-environment says the default includes a couple of variables like LANG
, but they are not there, too.
The variable LANG
is set in the environment of the pants run.happy-kitchen-89482
01/05/2024, 10:10 PMsubprocess-environment
only works for python processes right now, its documentation is wrong.happy-kitchen-89482
01/05/2024, 10:11 PMlate-keyboard-89314
01/05/2024, 10:11 PMfull-author-61014
01/05/2024, 10:21 PMDISPLAY
variable for fingerprinting and also for execution as _runnable_dependency_shims_...
later on. The execution also lacks the option to pass certain variables. I guess this is not possible yet?full-author-61014
01/05/2024, 10:23 PMadhoc_tool
, I guess this is worth mentioning.full-author-61014
01/05/2024, 10:27 PMextra_env_vars
adds the variable to the adhoc_tool invocation:
adhoc_tool(
name="build-html",
runnable=":sphinx-build",
args=["-M", "html", ".", "_build/html"],
execution_dependencies=DOC_DEPS,
runnable_dependencies=[
":drawio",
":git",
],
extra_env_vars=[ "DISPLAY" ],
output_directories=["_build/html"],
root_output_directory="./_build/html",
log_output=True,
)
This however does not solve the fingerprint issue, so the drawio executable can still not be found.happy-kitchen-89482
01/05/2024, 10:32 PMhappy-kitchen-89482
01/05/2024, 10:33 PMfull-author-61014
01/05/2024, 10:49 PMsystem_binary
which will fingerprint it (whether I need that or not).
The environment in which this is done cannot be modified, so it always looks like this
#!/usr/bin/env bash
# This command line should execute the same process as pants did internally.
cd /tmp/pants-sandbox-lpxUQZ
env -i /opt/drawio/drawio --version
env -i
kills all environment variables, however drawio relies on DISPLAY
.
That's why it fails with
[134070:0105/234425.825288:ERROR:<http://ozone_platform_x11.cc|ozone_platform_x11.cc>(240)] Missing X server or $DISPLAY
[134070:0105/234425.825328:ERROR:<http://env.cc|env.cc>(257)] The platform failed to initialize. Exiting.
./__run.sh: line 4: 134070 Segmentation fault (core dumped) env -i /opt/drawio/drawio --version
Is that helpful?full-author-61014
01/05/2024, 10:51 PMValueError: Could not find a binary with name `drawio`.
happy-kitchen-89482
01/05/2024, 11:49 PMhappy-kitchen-89482
01/05/2024, 11:49 PMhappy-kitchen-89482
01/05/2024, 11:50 PMextra_env_vars=[ "DISPLAY" ],
through when we run it to get its version?happy-kitchen-89482
01/05/2024, 11:52 PMsystem_binary
should take and use an extra_env_vars
, and 2) we should more generally make subprocess-environment
live up to its documentationfull-author-61014
01/06/2024, 7:06 AMfull-author-61014
01/06/2024, 7:11 AMhappy-kitchen-89482
01/06/2024, 4:56 PMfull-author-61014
01/06/2024, 5:04 PMpants_version
parameter also support setting a SHA or is that only possible on each invocation as described here https://www.pantsbuild.org/docs/installation#running-pants-from-unreleased-builds?full-author-61014
01/06/2024, 7:53 PMenv -i DISPLAY=:0.0 HOME=/home/marco DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1004/bus drawio --version
I will create an issue for that and try to assemble a PR soon. I guess improving pants is a better investment of my time than fiddling with workarounds 🙂full-author-61014
01/06/2024, 8:10 PMhappy-kitchen-89482
01/06/2024, 10:26 PMhappy-kitchen-89482
01/06/2024, 10:26 PMhappy-kitchen-89482
01/06/2024, 10:26 PMfull-author-61014
01/07/2024, 9:05 PM