<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
cookiecutter.hooks
------------------

Functions for discovering and executing various cookiecutter hooks.
"""

import os
import subprocess

_HOOKS = [
    'pre_gen_project',
    'post_gen_project',
    # TODO: other hooks should be listed here
]

def find_hooks(template_root):
    '''
    Return a dict of all hook scripts provided with the template located at
    `template_root`.
    Dict's key will be the hook/script's name, without extension, while
    values will be the absolute path to the script.
    Missing scripts will not be included in the returned dict.
    '''
    hooks_dir = os.path.join(template_root, 'hooks')
    r = {}
    if not os.path.isdir(hooks_dir):
        return r
    for f in os.listdir(hooks_dir):
        basename = os.path.splitext(os.path.basename(f))[0]
        if basename in _HOOKS:
            r[basename] = os.path.abspath(os.path.join(hooks_dir, f))
    return r


def _run_hook(script_path, cwd='.'):
    '''
    Run a sigle external script located at `script_path` (path should be 
    absolute).
    If `cwd` is provided, the script will be run from that directory.
    '''
    subprocess.call(script_path)


def run_hook(hook_name, input_dir, output_dir):
    '''
    Try and find a script mapped to `hook_name` in `input_dir`,
    and execute it with the current working directory.
    '''
    script = find_hooks(input_dir).get(hook_name)
    if script is None: 
        return
    return _run_hook(script, output_dir)<commit_msg>Put cwd param of subprocess back in.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
cookiecutter.hooks
------------------

Functions for discovering and executing various cookiecutter hooks.
"""

import os
import subprocess

_HOOKS = [
    'pre_gen_project',
    'post_gen_project',
    # TODO: other hooks should be listed here
]

def find_hooks(template_root):
    '''
    Return a dict of all hook scripts provided with the template located at
    `template_root`.
    Dict's key will be the hook/script's name, without extension, while
    values will be the absolute path to the script.
    Missing scripts will not be included in the returned dict.
    '''
    hooks_dir = os.path.join(template_root, 'hooks')
    r = {}
    if not os.path.isdir(hooks_dir):
        return r
    for f in os.listdir(hooks_dir):
        basename = os.path.splitext(os.path.basename(f))[0]
        if basename in _HOOKS:
            r[basename] = os.path.abspath(os.path.join(hooks_dir, f))
    return r


def _run_hook(script_path, cwd='.'):
    '''
    Run a sigle external script located at `script_path` (path should be 
    absolute).
    If `cwd` is provided, the script will be run from that directory.
    '''
    subprocess.call(script_path, cwd=cwd)


def run_hook(hook_name, input_dir, output_dir):
    '''
    Try and find a script mapped to `hook_name` in `input_dir`,
    and execute it with the current working directory.
    '''
    script = find_hooks(input_dir).get(hook_name)
    if script is None: 
        return
    return _run_hook(script, output_dir)
{'fraction_non_alphanumeric': 0.10979513444302176, 'fraction_numerical': 0.0012804097311139564, 'mean_word_length': 2.911138923654568, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4472697', 'n_tokens_mistral': 995, 'n_tokens_neox': 987, 'n_words': 318}