<commit_before># ActivitySim
# See full license in LICENSE.txt.

import argparse
import os
import yaml

import logging
from activitysim.core import inject

logger = logging.getLogger(__name__)


def handle_standard_args(parser=None):
    """
    Adds 'standard' activitysim arguments:
        --config : specify path to config_dir
        --output : specify path to output_dir
        --data   : specify path to data_dir

    Parameters
    ----------
    parser : argparse.ArgumentParser or None
        to  custom argument handling, pass in a parser with arguments added
        and handle them based on returned args. This method will hand the args it adds
    Returns
    -------

    args : parser.parse_args() result
    """

    if parser is None:
        parser = argparse.ArgumentParser()

    parser.add_argument("-c", "--config", help="path to config dir")
    parser.add_argument("-o", "--output", help="path to output dir")
    parser.add_argument("-d", "--data", help="path to data dir")
    args = parser.parse_args()

    if args.config:
        if not os.path.exists(args.config):
            raise IOError("Could not find configs dir '%s'." % args.config)
            inject.add_injectable("configs_dir", args.config)
    if args.output:
        if not os.path.exists(args.output):
            raise IOError("Could not find output dir '%s'." % args.config)
            inject.add_injectable("output_dir", args.output)
    if args.data:
        if not os.path.exists(args.data):
            raise IOError("Could not find data dir '%s'." % args.config)
            inject.add_injectable("data_dir", args.data)

    return args


def setting(key, default=None):

    settings = inject.get_injectable('settings')

    return settings.get(key, default)


def read_model_settings(configs_dir, file_name):
    settings = None
    file_path = os.path.join(configs_dir,  file_name)
    if os.path.isfile(file_path):
        with open(file_path) as f:
            settings = yaml.load(f)

    if settings is None:
        settings = {}

    return settings

<commit_msg>fix stupid indent bug in handle_standard_args<commit_after># ActivitySim
# See full license in LICENSE.txt.

import argparse
import os
import yaml

import logging
from activitysim.core import inject

logger = logging.getLogger(__name__)


def handle_standard_args(parser=None):
    """
    Adds 'standard' activitysim arguments:
        --config : specify path to config_dir
        --output : specify path to output_dir
        --data   : specify path to data_dir

    Parameters
    ----------
    parser : argparse.ArgumentParser or None
        to  custom argument handling, pass in a parser with arguments added
        and handle them based on returned args. This method will hand the args it adds
    Returns
    -------

    args : parser.parse_args() result
    """

    if parser is None:
        parser = argparse.ArgumentParser()

    parser.add_argument("-c", "--config", help="path to config dir")
    parser.add_argument("-o", "--output", help="path to output dir")
    parser.add_argument("-d", "--data", help="path to data dir")
    args = parser.parse_args()

    if args.config:
        if not os.path.exists(args.config):
            raise IOError("Could not find configs dir '%s'." % args.config)
        inject.add_injectable("configs_dir", args.config)
    if args.output:
        if not os.path.exists(args.output):
            raise IOError("Could not find output dir '%s'." % args.config)
        inject.add_injectable("output_dir", args.output)
    if args.data:
        if not os.path.exists(args.data):
            raise IOError("Could not find data dir '%s'." % args.config)
        inject.add_injectable("data_dir", args.data)

    return args


def setting(key, default=None):

    settings = inject.get_injectable('settings')

    return settings.get(key, default)


def read_model_settings(configs_dir, file_name):
    settings = None
    file_path = os.path.join(configs_dir,  file_name)
    if os.path.isfile(file_path):
        with open(file_path) as f:
            settings = yaml.load(f)

    if settings is None:
        settings = {}

    return settings


{'fraction_non_alphanumeric': 0.11015325670498084, 'fraction_numerical': 0.0, 'mean_word_length': 2.6576182136602453, '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': '2102067', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1182, 'n_words': 367}