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

curved-television-6568

03/25/2021, 1:53 PM
This is likely a pex question, but I’ll post it here anyways, feel free to do with it what you like. Not sure if this is a bug or feature, but I noticed that I could not run a pex file from another directory, only from current dir.
Copy code
~/src/.../
$ /private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionQXCoGY/pylint_runner.pex --version
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionQXCoGY/pylint_runner.pex/__main__.py", line 74, in <module>
  File "/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionQXCoGY/pylint_runner.pex/__main__.py", line 31, in __maybe_run_venv__
  File "/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionQXCoGY/pylint_runner.pex/.bootstrap/pex/variables.py", line 689, in venv_dir
  File "/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionQXCoGY/pylint_runner.pex/.bootstrap/pex/variables.py", line 687, in add_pex_path_items
  File "/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionQXCoGY/pylint_runner.pex/.bootstrap/pex/pex_info.py", line 99, in from_pex
FileNotFoundError: [Errno 2] No such file or directory: 'pylint.pex/PEX-INFO'
~/src/.../
$ cd /private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionQXCoGY
/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionQXCoGY
$ ls
__plugins                            pylint.pex                           pylint_runner.pex_bin_python_shim.sh requirements.pex
__run.sh                             pylint_runner.pex                    pylint_runner.pex_pex_shim.sh        src
/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionQXCoGY
$ ./pylint_runner.pex --version
pylint 2.7.2
...
e

enough-analyst-54434

03/25/2021, 3:00 PM
This turns out to be a bit of both. The
./pylint_runner.pex
file is an "aggregator" PEX that is empty save for specifying a PEX_PATH in its metadata. In this case, Pants uses a relative PEX_PATH and so the PEX can only be run from the sandbox root where the paths are relative to. You were trying to run the PEX file directly which there may not be much to do about, but we could lessen surprises by having the
__run.sh
script - which is supposed to emulate the process execution Pants performed - do a cd to the proper workdir before continuing. If
__run.sh
had that improved fidelity and you had used it, then surprise could have been avoided.
c

curved-television-6568

03/25/2021, 3:42 PM
OK, makes sense. In this case, I was looking for a way to run “pylint --version” to determine which version it was actually using (as well as the version of asteriod), so that’s why I didn’t use the
__run.sh
script.
e

enough-analyst-54434

03/25/2021, 4:30 PM
OK, yeah. I'm not sure about that case. It probably makes sense for Pex to absolutize relative components of the PEX_PATH as
<path to pex>/<relative pex path>
at runtime so that CWD would not be a factor. I need to think through any corners though.
Talking it out makes it seem to make more and more sense, but I'm still not quite there. FIled: https://github.com/pantsbuild/pex/issues/1289
c

curved-television-6568

03/26/2021, 9:23 AM
Agree. Formally, when using relative paths in a PEX file, are they expected to be relative to the PEX file or to CWD? (I would think relative to the PEX file, as CWD is unpredictable.) But I guess it could be abused when relative to CWD, as that could make a bootstrap PEX do different things depending on where you run it from (given the context works..) Maybe have a feature flag or something to choose between the two? Not sure if that’s feasible.