<commit_before>from __future__ import print_function

import argparse
import sys
from plumbum import local

from pre_commit_hooks.util import entry


@entry
def fix_trailing_whitespace(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('filenames', nargs='*', help='Filenames to fix')
    args = parser.parse_args(argv)

    bad_whitespace_files = local['grep'][
        ('-l', '[[:space:]]$') + tuple(args.filenames)
    ](retcode=None).strip().splitlines()

    if bad_whitespace_files:
        for bad_whitespace_file in bad_whitespace_files:
            print('Fixing {0}'.format(bad_whitespace_file))
            local['sed']['-i', '-e', 's/[[:space:]]*$//', bad_whitespace_file]()
        return 1
    else:
        return 0


if __name__ == '__main__':
    sys.exit(fix_trailing_whitespace())<commit_msg>Use fileinput instead of sed.<commit_after>from __future__ import print_function

import argparse
import fileinput
import sys
from plumbum import local

from pre_commit_hooks.util import entry


def _fix_file(filename):
    for line in fileinput.input([filename], inplace=True):
        print(line.rstrip())


@entry
def fix_trailing_whitespace(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('filenames', nargs='*', help='Filenames to fix')
    args = parser.parse_args(argv)

    bad_whitespace_files = local['grep'][
        ('-l', '[[:space:]]$') + tuple(args.filenames)
    ](retcode=None).strip().splitlines()

    if bad_whitespace_files:
        for bad_whitespace_file in bad_whitespace_files:
            print('Fixing {0}'.format(bad_whitespace_file))
            _fix_file(bad_whitespace_file)
        return 1
    else:
        return 0


if __name__ == '__main__':
    sys.exit(fix_trailing_whitespace())
{'fraction_non_alphanumeric': 0.12598870056497175, 'fraction_numerical': 0.003389830508474576, 'mean_word_length': 3.8653846153846154, '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': '1075841', 'n_tokens_mistral': 601, 'n_tokens_neox': 589, 'n_words': 120}