Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Error out when -p has a path that does not point to a valid python #1074

Closed
rcuza opened this issue Oct 12, 2020 · 4 comments
Assignees
Labels

Comments

@rcuza
Copy link

rcuza commented Oct 12, 2020

When creating a pex, I used -p /Users/myacct/.pyenv/shims/python on the command line. This resulted in __main__.py contain BASH commands. It would be great if the pex command validated that paths passed via -p pointed to valid python interpreters.

pex -r /tmp/jupyterlab-requirements.txt -o jupyter-labs.pex -p /Users/myacct/.pyenv/shims/python built a pex that showed the following error when jupyter-labs.pex -e jupyterlab.labapp:main was run:

jupyter-labs.pex -e jupyterlab.labapp:main
Traceback (most recent call last):
  File "/Users/myacct/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_main_module_details(_Error)
  File "/Users/myacct/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 219, in _get_main_module_details
    return _get_module_details(main_name)
  File "/Users/myacct/.pyenv/versions/3.6.9/lib/python3.6/runpy.py", line 128, in _get_module_details
    spec = importlib.util.find_spec(mod_name)
  File "/Users/myacct/.pyenv/versions/3.6.9/lib/python3.6/importlib/util.py", line 91, in find_spec
    return _find_spec(fullname, None)
  File "<frozen importlib._bootstrap>", line 894, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1131, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1112, in _legacy_get_spec
  File "<frozen importlib._bootstrap>", line 441, in spec_from_loader
  File "<frozen importlib._bootstrap_external>", line 544, in spec_from_file_location
  File "/Users/myacct/dev/virtualenvs/tmp-bc02eb6e921a2fd/jupyter-labs.pex/__main__.py", line 3
    [ -n "$PYENV_DEBUG" ] && set -x
                      ^
SyntaxError: invalid syntax
@jsirois
Copy link
Member

jsirois commented Oct 12, 2020

The -p flag does not mean --python it means --preamble-file. Pex just did what you asked there:

$ python -mpex -h
Usage: __main__.py [-o OUTPUT.PEX] [options] [-- arg1 arg2 ...]

__main__.py builds a PEX (Python Executable) file based on the given specifications: sources, requirements, their dependencies and other options.

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -o PEX_NAME, --output-file=PEX_NAME
                        The name of the generated .pex file: Omitting this
                        will run PEX immediately and not save it to a file.
  -p FILE, --preamble-file=FILE
                        The name of a file to be included as the preamble for
                        the generated .pex file
...

@jsirois jsirois self-assigned this Oct 12, 2020
@jsirois
Copy link
Member

jsirois commented Oct 12, 2020

I'm going to close this as answered.

@jsirois jsirois closed this as completed Oct 12, 2020
@jsirois
Copy link
Member

jsirois commented Oct 12, 2020

For posterity, the -p/--preamble-file feature implementation and example tests are in #400.

@rcuza
Copy link
Author

rcuza commented Oct 13, 2020

Thank you and sorry for not reading!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants