Changeset - 6df08d78f8e7
[Not reviewed]
stable
0 1 0
Thomas De Schampheleire - 7 years ago 2019-04-08 22:06:12
thomas.de_schampheleire@nokia.com
cli: fill in git_hook_interpreter at 'config-create' time to really fix potentially invalid interpreter in git hooks (Issue #333)

When generating a configuration file using 'kallithea-cli config-create', it is
probably using the right Python interpreter, so fill in the current Python
executable as 'git_hook_interpreter' in the generated file.

There should thus rarely be any need to configure this manually, and issue #333
will *really* be fixed.

As this causes an absolute path to be encoded inside the ini file, moving
the virtualenv will require updating this path.

For development.ini we do not want to hardcode any path and are happy to leave
it using the old heuristics at runtime.

Suggested-by: Mads Kiilerich <mads@kiilerich.com>
1 file changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/kallithea_cli_config.py
Show inline comments
 
@@ -7,24 +7,25 @@
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import click
 
import kallithea.bin.kallithea_cli_base as cli_base
 

	
 
import os
 
import sys
 
import uuid
 
from collections import defaultdict
 

	
 
import mako.exceptions
 

	
 
from kallithea.lib import inifile
 

	
 
def show_defaults(ctx, param, value):
 
    # Following construct is taken from the Click documentation:
 
    # https://click.palletsprojects.com/en/7.x/options/#callbacks-and-eager-options
 
    # "The resilient_parsing flag is applied to the context if Click wants to
 
    # parse the command line without any destructive behavior that would change
 
@@ -50,25 +51,27 @@ def config_create(config_file, key_value
 
    This command creates a default configuration file, possibly adding/updating
 
    settings you specify.
 

	
 
    The primary high level configuration keys and their default values are
 
    shown with --show-defaults . Custom values for these keys can be specified
 
    on the command line as key=value arguments.
 

	
 
    Additional key=value arguments will be patched/inserted in the [app:main]
 
    section ... until another section name specifies where any following values
 
    should go.
 
    """
 

	
 
    mako_variable_values = {}
 
    mako_variable_values = {
 
        'git_hook_interpreter': sys.executable,
 
    }
 
    ini_settings = defaultdict(dict)
 

	
 
    section_name = None
 
    for parameter in key_value_pairs:
 
        parts = parameter.split('=', 1)
 
        if len(parts) == 1 and parameter.startswith('[') and parameter.endswith(']'):
 
            section_name = parameter
 
        elif len(parts) == 2:
 
            key, value = parts
 
            if section_name is None and key in inifile.default_variables:
 
                mako_variable_values[key] = value
 
            else:
0 comments (0 inline, 0 general)