<commit_before>"""
yq: Command-line YAML processor - jq wrapper for YAML documents

See https://github.com/kislyuk/yq for more information.
"""

from __future__ import absolute_import, division, print_function, unicode_literals

import os, sys, argparse, subprocess, json
import yaml

class Parser(argparse.ArgumentParser):
    def print_help(self):
        argparse.ArgumentParser.print_help(self)
        print()
        try:
            subprocess.check_call(["jq", "--help"])
        except:
            pass

parser = Parser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("jq_args", nargs=argparse.REMAINDER)

def main(args=None):
    args = parser.parse_args(args=args)
    try:
        # Note: universal_newlines is just a way to induce subprocess to make stdin a text buffer and encode it for us
        jq = subprocess.Popen(['jq'] + args.jq_args, stdin=subprocess.PIPE, universal_newlines=True)
    except OSError as e:
        parser.exit("yq: Error while starting jq: {}: {}. Is jq installed and available on PATH?".format(type(e).__name__, e))
    try:
        json.dump(yaml.safe_load(sys.stdin), jq.stdin)
        jq.stdin.close()
        jq.wait()
        exit(jq.returncode)
    except Exception as e:
        parser.exit("yq: Error while running jq: {}: {}.".format(type(e).__name__, e))
<commit_msg>Docstring improvements<commit_after>"""
yq: Command-line YAML processor - jq wrapper for YAML documents

yq transcodes YAML documents to JSON and passes them to jq.
See https://github.com/kislyuk/yq for more information.
"""

from __future__ import absolute_import, division, print_function, unicode_literals

import os, sys, argparse, subprocess, json
import yaml

class Parser(argparse.ArgumentParser):
    def print_help(self):
        yq_help = argparse.ArgumentParser.format_help(self).splitlines()
        print("\n".join(["usage: yq [options] <jq filter> [YAML file...]"] + yq_help[1:] + [""]))
        try:
            subprocess.check_call(["jq", "--help"])
        except:
            pass

parser = Parser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("jq_args", nargs=argparse.REMAINDER)

def main(args=None):
    args = parser.parse_args(args=args)
    if sys.stdin.isatty():
        return parser.print_help()
    try:
        # Note: universal_newlines is just a way to induce subprocess to make stdin a text buffer and encode it for us
        jq = subprocess.Popen(['jq'] + args.jq_args, stdin=subprocess.PIPE, universal_newlines=True)
    except OSError as e:
        parser.exit("yq: Error while starting jq: {}: {}. Is jq installed and available on PATH?".format(type(e).__name__, e))
    try:
        json.dump(yaml.safe_load(sys.stdin), jq.stdin)
        jq.stdin.close()
        jq.wait()
        exit(jq.returncode)
    except Exception as e:
        parser.exit("yq: Error while running jq: {}: {}.".format(type(e).__name__, e))

{'fraction_non_alphanumeric': 0.12115059221658206, 'fraction_numerical': 0.00033840947546531303, 'mean_word_length': 3.445112781954887, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '454908', 'n_tokens_mistral': 976, 'n_tokens_neox': 941, 'n_words': 244}