<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals

import argparse
import os
import sys
import time

import yaml

from inlineplz import interfaces
from inlineplz import env
from inlineplz import linters
from inlineplz import __version__


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--pull-request', type=int)
    parser.add_argument('--owner', type=str)
    parser.add_argument('--repo', type=str)
    parser.add_argument('--repo-slug', type=str)
    parser.add_argument('--token', type=str)
    parser.add_argument('--interface', type=str, choices=interfaces.INTERFACES)
    parser.add_argument('--url', type=str)
    parser.add_argument('--enabled-linters', type=str, nargs='+')
    parser.add_argument('--disabled-linters', type=str, nargs='+')
    parser.add_argument('--dryrun', action='store_true')
    parser.add_argument('--zero-exit', action='store_true')
    parser.add_argument('--install', action='store_true')
    parser.add_argument('--trusted', action='store_true', help='allow installing all local dependencies')
    parser.add_argument('--max-comments', default=25, type=int, help='maximum comments to write')
    parser.add_argument(
        '--autorun',
        action='store_true',
        help='automatically run linters with reasonable defaults'
    )
    parser.add_argument(
        '--config-dir',
        help='default directory to search for linter config files'
    )
    args = parser.parse_args()
    args = env.update_args(args)
    if args.config_dir:
        args.config_dir = os.path.abspath(args.config_dir)
        if not os.path.exists(args.config_dir):
            args.config_dir = None
    print('inline-plz version: {}'.format(__version__))
    print('Python version: {}'.format(sys.version))
    start = time.time()
    result = inline(args)
    print('inline-plz ran for {} seconds'.format(int(time.time() - start)))
    print('inline-plz returned exit code {}'.format(result))
    return result


def update_from_config(args, config):
    blacklist = [
        'trusted', 'token', 'interface', 'owner', 'repo', 'config_dir'
        'repo_slug', 'pull_request', 'zero_exit', 'dryrun', 'url'
    ]
    for key, value in config.items():
        if not key.startswith('_') and key not in blacklist:
            args.__dict__[key] = args.__dict__.get(key) or value
    return args


def load_config(args, config_path='.inlineplz.yml'):
    """Load inline-plz config from yaml config file with reasonable defaults."""
    config = {}
    print(config_path)
    try:
        with open(config_path) as configfile:
            try:
                config = yaml.safe_load(configfile) or {}
                if config:
                    print('Loaded config from {}'.format(config_path))
            except yaml.parser.ParserError:
                pass
    except (IOError, OSError):
        pass
    args = update_from_config(args, config)
    args.ignore_paths = args.__dict__.get('ignore_paths') or ['node_modules', '.git', '.tox']
    if config_path != '.inlineplz.yml':<commit_msg>ignore godeps be default. (#173)<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals

import argparse
import os
import sys
import time

import yaml

from inlineplz import interfaces
from inlineplz import env
from inlineplz import linters
from inlineplz import __version__


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--pull-request', type=int)
    parser.add_argument('--owner', type=str)
    parser.add_argument('--repo', type=str)
    parser.add_argument('--repo-slug', type=str)
    parser.add_argument('--token', type=str)
    parser.add_argument('--interface', type=str, choices=interfaces.INTERFACES)
    parser.add_argument('--url', type=str)
    parser.add_argument('--enabled-linters', type=str, nargs='+')
    parser.add_argument('--disabled-linters', type=str, nargs='+')
    parser.add_argument('--dryrun', action='store_true')
    parser.add_argument('--zero-exit', action='store_true')
    parser.add_argument('--install', action='store_true')
    parser.add_argument('--trusted', action='store_true', help='allow installing all local dependencies')
    parser.add_argument('--max-comments', default=25, type=int, help='maximum comments to write')
    parser.add_argument(
        '--autorun',
        action='store_true',
        help='automatically run linters with reasonable defaults'
    )
    parser.add_argument(
        '--config-dir',
        help='default directory to search for linter config files'
    )
    args = parser.parse_args()
    args = env.update_args(args)
    if args.config_dir:
        args.config_dir = os.path.abspath(args.config_dir)
        if not os.path.exists(args.config_dir):
            args.config_dir = None
    print('inline-plz version: {}'.format(__version__))
    print('Python version: {}'.format(sys.version))
    start = time.time()
    result = inline(args)
    print('inline-plz ran for {} seconds'.format(int(time.time() - start)))
    print('inline-plz returned exit code {}'.format(result))
    return result


def update_from_config(args, config):
    blacklist = [
        'trusted', 'token', 'interface', 'owner', 'repo', 'config_dir'
        'repo_slug', 'pull_request', 'zero_exit', 'dryrun', 'url'
    ]
    for key, value in config.items():
        if not key.startswith('_') and key not in blacklist:
            args.__dict__[key] = args.__dict__.get(key) or value
    return args


def load_config(args, config_path='.inlineplz.yml'):
    """Load inline-plz config from yaml config file with reasonable defaults."""
    config = {}
    print(config_path)
    try:
        with open(config_path) as configfile:
            try:
                config = yaml.safe_load(configfile) or {}
                if config:
                    print('Loaded config from {}'.format(config_path))
            except yaml.parser.ParserError:
                pass
    except (IOError, OSError):
        pass
    args = update_from_config(args, config)
    args.ignore_paths = args.__dict__.get('ignore_paths') or ['node_modules', '.git', '.tox', 'godeps']
    if config_path != '.inlineplz.yml':
{'fraction_non_alphanumeric': 0.13620015637216576, 'fraction_numerical': 0.0014073494917904612, 'mean_word_length': 3.295500335795836, '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': '2800907', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1915, 'n_words': 452}