Skip to content

Feature proposal: Shim launcher for Python #3658

@J-M0

Description

@J-M0
  • I was not able to find an open or closed issue matching what I'm seeing

I recently started working with Windows more and interacting with Git for Windows more and got to thinking about how to make it easier for Windows users to use git-filter-repo and get the full experience since installing it has proved problematic for Windows users. I would like to propose a small shim installed at /usr/bin/python and /usr/bin/python3 that would make using git-filter-repo work like it does on a UNIX install of git.

I have a rough draft here:

#!/bin/bash

# Look for all `python` commands in ${PATH}
found_pythons=($(type -ap python 2>/dev/null))

# Look for a valid python interpreter
for python in "${found_pythons[@]}"
do
    #  Make sure we don't call ourselves             Check that we aren't running the Microsoft Store shortcut
    if [[ ! ${python} =~ (\/usr)?\/bin\/python ]] && "${python}" --version &>/dev/null
    then
        exec "${python}" $@
    fi
done

# If we didn't find a `python`, try to use the py launcher
if command -v py &>/dev/null
then
    exec py $@
fi

echo "No python command found. Please install Python"
exit 1

This shell script will, in order

  1. Find all python commands on the ${PATH}
  2. Test each one to see if it is a valid python interpreter
  3. If it finds a valid python, pass all arguments to the interpreter, else
  4. Try to find the py launcher and pass all arguments to it, else
  5. Exit with an error

I've tested it on my machine and it seems to work pretty well with a python.org Python and a Microsoft Store Python. I'm hoping with this shim, Git for Windows could start to include git-filter-repo in the same way it includes other extensions like git-flow and git-lfs, and that git-p4 could become a first-class citizen again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions