python-launcher 0.4.0

The Python launcher for UNIX
Documentation

The Python Launcher for UNIX

An implementation of the py command for UNIX-based platforms.

The goal is to have py become the cross-platform command that all Python users use when executing a Python interpreter. By having a version-agnostic command it side-steps the "what should the python command point to?" debate by clearly specifying that upfront (i.e. the newest version of Python that is installed). This also unifies the suggested command to document which needs to target both Windows as UNIX as py has existed as the preferred command on Windows for some time.

Search order

Please note that at various points in searching for the most appropriate Python version that the version being searched for can become more specific. This leads to a switch in the search algorithm to one more appropriate to the specificity of the version.

py -3.6 (specific version)

  1. Search PATH for python3.6

py -3 (loose/major version)

  1. Use the version found in the PY_PYTHON3 environment variable if defined (e.g. PY_PYTHON3=3.6)
  2. Search PATH for all instances of python3.Y
  3. Find the executable with largest Y

py (any/unknown version)

  1. If first argument is a file path
    1. Check for a shebang
    2. If executable starts with /usr/bin/python, /usr/local/bin/python, /usr/bin/env python or python, proceed based on the version found (bare python is considered python2 for backwards-compatibility)
    3. A bare python is considered python2 for backwards compatibility (because of this the search will not continue as if no version details were known)
  2. Use ${VIRTUAL_ENV}/bin/python immediately if available
  3. Use the version found in the PY_PYTHON environment variable if defined (e.g. PY_PYTHON=3 or PY_PYTHON=3.6)
  4. Search PATH for all instances of pythonX.Y
  5. Find the executable with largest X.Y

TODO

NOTE: I am using this project to learn Rust, so please don't be offended if I choose to implement something myself instead of accepting a pull request that you submit. (Pull requests to do something I have already implemented in a more idiomatic fashion are very much appreciated, though.)

PEP 397: Python launcher for Windows (documentation)

  • PYLAUNCH_DEBUG
  • py -0/py --list/py -0p/py --list-paths
    • Output well-formatted JSON to start in order for it to be consumable?
    • Output column format like pip list?
  • py -h emits its own help before continuing on to call python
  • Configuration files
    • Customized commands
    • Want a better format like TOML?
    • Want to use Pipfile/Pipfile.lock and its python_version field?
    • pyenv and its .python-version or PYENV_VERSION?
    • Probably want a way to override things, e.g. wanting a framework build on macOS somehow
      • Aliasing? E.g. 2.7-framework=/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python?
      • Just provide a way to specify a specific interpreter for a specific version? E.g. 2.7=/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
    • How should config file search work?
      • Pre-defined locations?
      • Walk up from current directory?