<commit_before>import os
from jinja2 import Environment, PackageLoader, FileSystemLoader, ChoiceLoader
from txtools.gen import GenDesc
from textx.lang import get_language


PARAM_NAMES = ()


def genconf_model():
    """
    Returns genconf model for '{{package_name}}' generator and '{{language}}'
    language.
    """
    gc_meta = get_language("genconf")
    curr_dir = os.path.dirname(__file__)
    return gc_meta.model_from_file(
        os.path.join(curr_dir, '{{package_name}}.genconf'))


def render(template_path, context, root_path=None):
    """
    Returns rendered template. By default search for template at the given
    root path. If not found search is continued in the generator templates
    folder.

    Args:
        template_path (str): Relative path to the template inside the root_path.
        context (dict)
        root_path (str): The root where templates should be searched first.
            If None no override is performed.
    """

    # By default jinja2 is used but this can be changed by the user.
    env = Environment(loader=ChoiceLoader([
        FileSystemLoader(root_path),
        PackageLoader('{{package_name}}', 'templates')
    ]))

    return env.get_template(template_path).render(**context)


# This object is registered in setup.py under entry point textx_gen
gendesc = GenDesc(name="{{package_name}}", lang="{{language}}",
                  desc="{{package_name}} generator for {{language}} language",
                  genconf=genconf_model, render=render,
                  param_names=PARAM_NAMES)
<commit_msg>Check generator parameters in scaffolding generator.<commit_after>import os
from jinja2 import Environment, PackageLoader, FileSystemLoader, ChoiceLoader
from txtools.gen import GenDesc
from textx.lang import get_language
from txtools.exceptions import TextXToolsException


PARAM_NAMES = ()


def genconf_model():
    """
    Returns genconf model for '{{package_name}}' generator and '{{language}}'
    language.
    """
    gc_meta = get_language("genconf")
    curr_dir = os.path.dirname(__file__)
    gc_model = gc_meta.model_from_file(
        os.path.join(curr_dir, '{{package_name}}.genconf'))

    # Check parameters
    for p in gc_model.params:
        if p.name not in PARAM_NAMES:
            raise TextXToolsException('Undefined generator parameter "{}".'
                                      .format(p.name))


def render(template_path, context, root_path=None):
    """
    Returns rendered template. By default search for template at the given
    root path. If not found search is continued in the generator templates
    folder.

    Args:
        template_path (str): Relative path to the template inside the root_path.
        context (dict)
        root_path (str): The root where templates should be searched first.
            If None no override is performed.
    """

    # By default jinja2 is used but this can be changed by the user.
    env = Environment(loader=ChoiceLoader([
        FileSystemLoader(root_path),
        PackageLoader('{{package_name}}', 'templates')
    ]))

    return env.get_template(template_path).render(**context)


# This object is registered in setup.py under entry point textx_gen
gendesc = GenDesc(name="{{package_name}}", lang="{{language}}",
                  desc="{{package_name}} generator for {{language}} language",
                  genconf=genconf_model, render=render,
                  param_names=PARAM_NAMES)

{'fraction_non_alphanumeric': 0.09602552944589499, 'fraction_numerical': 0.0011604293588627793, 'mean_word_length': 3.18955042527339, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7311075', 'n_tokens_mistral': 955, 'n_tokens_neox': 911, 'n_words': 295}