[PATCH 1 of 3 v2] hooks: add intermediate function _get_python_executable

Mads Kiilerich mads at kiilerich.com
Wed Apr 3 22:41:28 UTC 2019


On 4/3/19 10:28 PM, Thomas De Schampheleire wrote:
> # HG changeset patch
> # User Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
> # Date 1554320638 -7200
> #      Wed Apr 03 21:43:58 2019 +0200
> # Branch stable
> # Node ID 8d7e20c6980cd4e27eeafa15f574d929d836dd76
> # Parent  953047e8c88a9c5ccaa4ddc1bb417622de37f01f
> hooks: add intermediate function _get_python_executable
>
> ... to avoid code duplication.


(and to give a place where we easily can tweak the heurstics)


> diff --git a/kallithea/model/scm.py b/kallithea/model/scm.py
> --- a/kallithea/model/scm.py
> +++ b/kallithea/model/scm.py
> @@ -720,6 +720,10 @@ class ScmModel(object):
>   
>           return choices, hist_l
>   
> +    def _get_python_executable(self):
> +        """Return a Python executable for use in hooks."""


Perhaps clarify "suitable to be written in the posix #! line for Git 
hook scripts so they invoke Kallithea code with the right interpreter 
and in the right environment".


> +        return sys.executable or 'python2'
> +
>       def install_git_hooks(self, repo, force_create=False):
>           """
>           Creates a kallithea hook inside a git repository
> @@ -734,11 +738,11 @@ class ScmModel(object):
>           if not os.path.isdir(loc):
>               os.makedirs(loc)
>   
> -        tmpl_post = "#!/usr/bin/env %s\n" % sys.executable or 'python2'
> +        tmpl_post = "#!/usr/bin/env %s\n" % self._get_python_executable()


Also, can you remind me (and perhaps clarify in code): #! paths are only 
used on posix. How does this work on Windows? Or is that covered by 
tribal "Don't use Git on Windows" knowledge? Especially: With git having 
one hardcoded executable name for each hook, how does it generally work 
finding the right hook script interpreter when Windows doesn't use #! paths?

(Also, AFAIK, /usr/bin/env is really mainly for searching in PATH so we 
don't have to specify full path. If we specify full paths, it thus seems 
a bit wrong to use env? That is an old thing that we don't have to care 
about now, but perhaps keep it in mind if it pops up now.)

/Mads



More information about the kallithea-general mailing list