Skip to content

Incorrect shebang in .git/hooks/pre-commit for python3 only installations #878

Closed

Description

@fristedt

The shebang for .git/hooks/pre-commit is #!/usr/bin/env python. I work with setups where python3 is the only python in env.

Could the shebang be the install python instead? I.e. the installation under INSTALL_PYTHON = '/usr/bin/python3'

Activity

  1. asottile commented on Dec 4, 2018

    @asottile
    Member

    hmm! that's a good point I hadn't thought of but presents some issues I can think of:

    • windows (official python installs) always use python and not python3
    • INSTALL_PYTHON might be ephemeral, it's why there's three options for detecting pre-commit in the script

    that said, I think we can get this right, probably by inspecting sys.executable and determining what possible values could be used.

  2. asottile commented on Dec 4, 2018

    @asottile
    Member

    Maybe something like this?

    if sys.platform != 'win32' and six.PY3:
        return '#!/usr/bin/env python3'
    else:
        return '#!/usr/bin/env python'
  3. fristedt commented on Dec 5, 2018

    @fristedt
    Author

    Maybe something like this?

    if sys.platform != 'win32' and six.PY3:
        return '#!/usr/bin/env python3'
    else:
        return '#!/usr/bin/env python'

    Thanks for the quick reply! I believe that would solve my problem.

  4. asottile commented on Dec 10, 2018

    @asottile
    Member

    hmmm I just thought of another case while working on this that might not work. Some distributions (for instance arch) install python 3.x as /usr/bin/python and won't (?) necessarily have a /usr/bin/python3 executable

    I'll have to think about this some more -- maybe inspecting sys.executable is necessary. Maybe something like this

  5. asottile commented on Dec 25, 2018

    @asottile
    Member

    @fristedt can you try out the branch in #893?

  6. fristedt commented on Jan 2, 2019

    @fristedt
    Author

    @fristedt can you try out the branch in #893?

    Tested, it works. Thanks @asottile!

  7. asottile commented on Jan 8, 2019

    @asottile
    Member

    This has been released as part of v1.14.0 🎉 -- thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions