<commit_before>import logging
import datetime

from assigner.config import requires_config

help = "Interactively initialize a new configuration"

logger = logging.getLogger(__name__)


def prompt(explanation, default=None):
    prompt_string = ''
    if default is not None:
        prompt_string = "{} (default: {}): ".format(explanation, default)
    else:
        prompt_string = "{}: ".format(explanation)
    value = input(prompt_string)

    if value == '':
        if default is not None:
            return default

        return prompt(explanation, default)

    return value


def guess_semester():
    now = datetime.datetime.now()
    if now.month < 5:
        semester = 'SP'
    elif now.month < 8:
        semester = 'SS'
    else:
        semester = 'FS'

    return "{}-{}".format(now.year, semester)


@requires_config
def init(conf, _):
    conf['backend'] = {'name': 'gitlab'}
    conf['backend']['host'] = "https://{}".format(prompt("Gitlab server to use", "gitlab.com"))
    conf['backend']['token'] = prompt("Gitlab access token (from {}/profile/personal_access_tokens)"
                                      .format(conf['gitlab-host']))
    conf['semester'] = prompt("Year and semester, in the format YYYY-(FS|SP|SS)", guess_semester())
    conf['namespace'] = prompt("Gitlab group to create repositories under", "{}-CS1001"
                               .format(conf['semester']))
    do_canvas = input("Do you want to configure Canvas integration? [y/N]: ")
    if do_canvas.lower() == 'y':
        conf['canvas-host'] = prompt("Canvas server to use (???.instructure.com)")
        conf['canvas-token'] = prompt("Canvas access token (from {}/profile/settings)"
                                      .format(conf['canvas-host']))

    print("Congratulations, you're ready to go!")


def setup_parser(parser):
    parser.set_defaults(run=init)
<commit_msg>Update assigner init to generate well-formed configs<commit_after>import logging
import datetime

from assigner.config import requires_config

help = "Interactively initialize a new configuration"

logger = logging.getLogger(__name__)


def prompt(explanation, default=None):
    prompt_string = ''
    if default is not None:
        prompt_string = "{} (default: {}): ".format(explanation, default)
    else:
        prompt_string = "{}: ".format(explanation)
    value = input(prompt_string)

    if value == '':
        if default is not None:
            return default

        return prompt(explanation, default)

    return value


def guess_semester():
    now = datetime.datetime.now()
    if now.month < 5:
        semester = 'SP'
    elif now.month < 8:
        semester = 'SS'
    else:
        semester = 'FS'

    return "{}-{}".format(now.year, semester)


@requires_config
def init(conf, _):
    conf['version'] = 2
    conf['backend'] = {'name': 'gitlab'}
    conf['backend']['host'] = "https://{}".format(prompt("Gitlab server to use", "gitlab.com"))
    conf['backend']['token'] = prompt("Gitlab access token (from {}/profile/personal_access_tokens)"
                                      .format(conf['backend']['host']))
    conf['semester'] = prompt("Year and semester, in the format YYYY-(FS|SP|SS)", guess_semester())
    conf['namespace'] = prompt("Gitlab group to create repositories under", "{}-CS1001"
                               .format(conf['semester']))
    do_canvas = input("Do you want to configure Canvas integration? [y/N]: ")
    if do_canvas.lower() == 'y':
        conf['canvas-host'] = prompt("Canvas server to use (???.instructure.com)")
        conf['canvas-token'] = prompt("Canvas access token (from {}/profile/settings)"
                                      .format(conf['canvas-host']))

    print("Congratulations, you're ready to go!")


def setup_parser(parser):
    parser.set_defaults(run=init)

{'fraction_non_alphanumeric': 0.1468057366362451, 'fraction_numerical': 0.003389830508474576, 'mean_word_length': 2.882591093117409, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4859791', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1075, 'n_words': 284}