<commit_before>
import argparse
import os

from rinoh import paper

from rinoh.backend import pdf
from rinoh.frontend.rst import ReStructuredTextParser

from rinohlib.templates.article import Article, ArticleOptions


def main():
    parser = argparse.ArgumentParser(description='Render a reStructuredText '
                                                 'document.')
    parser.add_argument('input', type=str, nargs='?',
                       help='the reStructuredText document to render')
    parser.add_argument('--paper', type=str, nargs='?', default='A4',
                       help='the paper size to render to')
    args = parser.parse_args()

    input_dir, input_file = os.path.split(args.input)
    input_base, input_ext = os.path.splitext(input_file)

    if input_dir:
        os.chdir(input_dir)
    parser = ReStructuredTextParser()
    document_tree = parser.parse(input_file)
    options = ArticleOptions(page_size=getattr(paper, args.paper.upper()))
    document = Article(document_tree, options, backend=pdf)
    document.render(input_base)<commit_msg>rinoh: print help when no filename is given<commit_after>
import argparse
import os

from rinoh import paper

from rinoh.backend import pdf
from rinoh.frontend.rst import ReStructuredTextParser

from rinohlib.templates.article import Article, ArticleOptions


def main():
    parser = argparse.ArgumentParser(description='Render a reStructuredText '
                                                 'document to PDF.')
    parser.add_argument('input', type=str, nargs='?',
                       help='the reStructuredText document to render')
    parser.add_argument('--paper', type=str, nargs='?', default='A4',
                       help='the paper size to render to')
    args = parser.parse_args()

    try:
        input_dir, input_file = os.path.split(args.input)
    except AttributeError:
        parser.print_help()
        return

    input_base, input_ext = os.path.splitext(input_file)
    if input_dir:
        os.chdir(input_dir)
    parser = ReStructuredTextParser()
    document_tree = parser.parse(input_file)
    options = ArticleOptions(page_size=getattr(paper, args.paper.upper()))
    document = Article(document_tree, options, backend=pdf)
    document.render(input_base)
{'fraction_non_alphanumeric': 0.09779735682819383, 'fraction_numerical': 0.000881057268722467, 'mean_word_length': 3.055357142857143, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1247554', 'n_tokens_mistral': 653, 'n_tokens_neox': 639, 'n_words': 153}