<commit_before>'''
This module contains the command-line parser. All imports are inside the functions
because we don't want to execute code before the parser is created and when Pyg is
used as a library.
'''


def load_options():
    import os.path

    from pyg.core import args_manager
    from pyg.locations import CFG_FILES
    from pyg.log import logger

    if CFG_FILES:
        for cfg in CFG_FILES:
            if os.path.exists(cfg):
                logger.debug('Loading options from {0}', cfg)

                ## This is for potential warnings
                logger.indent = 8
                args_manager.load(cfg)
                logger.indent = 0
                break

def init_parser(version=None):
    import sys
    import os
    import _opts as opts
    from pyg.locations import INSTALL_DIR, USER_SITE
    from pyg.parser.formatter import _formatter
    from pyg.core import args_manager
    from argh import ArghParser, arg, command


    parser = ArghParser(prog='pyg')
    parser.add_argument('-d', '--debug', action='store_true', help='Set logger to DEBUG level')
    parser.add_argument('--verbose', action='store_true', help='Set logger to VERBOSE level')
    if version is not None:
        parser.add_argument('-v', '--version', action='version', version=version)
    parser.add_argument('--no-colors', action='store_true', help='Disable colors')


    @arg('packname', nargs='*')
    @arg('-e', '--editable', action='store_true', help='Install a package from an online repository in editable mode')
    @arg('-r', '--req-file', metavar='<path>', action='append', help='Install packages from the specified requirement file')
    @arg('-U', '--upgrade', action='store_true', help='If the package is already installed re-install it again')
    @arg('-A', '--upgrade-all', action='store_true', help='Install again dependencies too')
    @arg('-n', '--no-deps', action='store_true', help='Do not install dependencies')
    @arg('-g', '--ignore', action='store_true', help='Ignore local files or directories')
    @arg('-i', '--index-url', default='http://pypi.python.org/pypi', metavar='<url>', help='Base URL of Python Package Index (default to %(default)s)')
    @arg('-d', '--install-dir', default=INSTALL_DIR, metavar='<path>', help='Base installation directory')
    @arg('-u', '--user', action='store_true', help='Install to user site')
    @arg('--no-scripts', action='store_true', help='Do not install scripts')
    @arg('--no-data', action='store_true', help='Do not install data files')
    @arg('--force-egg-install', action='store_true', help='Allow installing eggs with a different Python version')
    def install(args):
        '''
        Install a package
        '''

        if args.no_deps:
            args_manager['install']['no_deps'] = True
        if args.upgrade:
            args_manager['install']['upgrade'] = True
        if args.no_script:
            args_manager['install']['no_scripts'] = True
        if args.no_data:
            args_manager['install']['no_data'] = True
        if args.ignore:
            args_manager['install']['ignore'] = True
        if args.force_egg_install:
            args_manager['install']['force_egg_install'] = True
        if args.index_url:
            args_manager['install']['index_url'] = args.index_url
        if args.upgrade_all:
            args_manager['install']['upgrade_all'] = True
            args_manager['install']['upgrade'] = True
        if args.user:
            args_manager['install']['user'] = True
            args_manager['install']['install_dir'] = USER_SITE
        if args.install_dir != INSTALL_DIR:
            dir = os.path.abspath(args.install_dir)
            args_manager['install']['install_dir'] = dir
            if any(os.path.basename(dir) == p for p in args.packname):
                ## Automatically set ignore=True when INSTALL_DIR has the same
                ## name of one of the packages to install
                args_manager['install']['ignore'] = True
        opts.install_func(args.packname, args.req_file, args.editable,
                          args_manager['install']['ignore'])

    @arg('packname', nargs='+')
    @arg('-r', '--req-file', metavar='<path>', help='Uninstall all the packages listed in the given requirement file')
    @arg('-y', '--yes', action='store_true', help='Do not ask confirmation of uninstall deletions')
    @arg('-i', '--info', action='store_true', help='Only list files to delete')<commit_msg>install: Typo fixed<commit_after>'''
This module contains the command-line parser. All imports are inside the functions
because we don't want to execute code before the parser is created and when Pyg is
used as a library.
'''


def load_options():
    import os.path

    from pyg.core import args_manager
    from pyg.locations import CFG_FILES
    from pyg.log import logger

    if CFG_FILES:
        for cfg in CFG_FILES:
            if os.path.exists(cfg):
                logger.debug('Loading options from {0}', cfg)

                ## This is for potential warnings
                logger.indent = 8
                args_manager.load(cfg)
                logger.indent = 0
                break

def init_parser(version=None):
    import sys
    import os
    import _opts as opts
    from pyg.locations import INSTALL_DIR, USER_SITE
    from pyg.parser.formatter import _formatter
    from pyg.core import args_manager
    from argh import ArghParser, arg, command


    parser = ArghParser(prog='pyg')
    parser.add_argument('-d', '--debug', action='store_true', help='Set logger to DEBUG level')
    parser.add_argument('--verbose', action='store_true', help='Set logger to VERBOSE level')
    if version is not None:
        parser.add_argument('-v', '--version', action='version', version=version)
    parser.add_argument('--no-colors', action='store_true', help='Disable colors')


    @arg('packname', nargs='*')
    @arg('-e', '--editable', action='store_true', help='Install a package from an online repository in editable mode')
    @arg('-r', '--req-file', metavar='<path>', action='append', help='Install packages from the specified requirement file')
    @arg('-U', '--upgrade', action='store_true', help='If the package is already installed re-install it again')
    @arg('-A', '--upgrade-all', action='store_true', help='Install again dependencies too')
    @arg('-n', '--no-deps', action='store_true', help='Do not install dependencies')
    @arg('-g', '--ignore', action='store_true', help='Ignore local files or directories')
    @arg('-i', '--index-url', default='http://pypi.python.org/pypi', metavar='<url>', help='Base URL of Python Package Index (default to %(default)s)')
    @arg('-d', '--install-dir', default=INSTALL_DIR, metavar='<path>', help='Base installation directory')
    @arg('-u', '--user', action='store_true', help='Install to user site')
    @arg('--no-scripts', action='store_true', help='Do not install scripts')
    @arg('--no-data', action='store_true', help='Do not install data files')
    @arg('--force-egg-install', action='store_true', help='Allow installing eggs with a different Python version')
    def install(args):
        '''
        Install a package
        '''

        if args.no_deps:
            args_manager['install']['no_deps'] = True
        if args.upgrade:
            args_manager['install']['upgrade'] = True
        if args.no_scripts:
            args_manager['install']['no_scripts'] = True
        if args.no_data:
            args_manager['install']['no_data'] = True
        if args.ignore:
            args_manager['install']['ignore'] = True
        if args.force_egg_install:
            args_manager['install']['force_egg_install'] = True
        if args.index_url:
            args_manager['install']['index_url'] = args.index_url
        if args.upgrade_all:
            args_manager['install']['upgrade_all'] = True
            args_manager['install']['upgrade'] = True
        if args.user:
            args_manager['install']['user'] = True
            args_manager['install']['install_dir'] = USER_SITE
        if args.install_dir != INSTALL_DIR:
            dir = os.path.abspath(args.install_dir)
            args_manager['install']['install_dir'] = dir
            if any(os.path.basename(dir) == p for p in args.packname):
                ## Automatically set ignore=True when INSTALL_DIR has the same
                ## name of one of the packages to install
                args_manager['install']['ignore'] = True
        opts.install_func(args.packname, args.req_file, args.editable,
                          args_manager['install']['ignore'])

    @arg('packname', nargs='+')
    @arg('-r', '--req-file', metavar='<path>', help='Uninstall all the packages listed in the given requirement file')
    @arg('-y', '--yes', action='store_true', help='Do not ask confirmation of uninstall deletions')
    @arg('-i', '--info', action='store_true', help='Only list files to delete')
{'fraction_non_alphanumeric': 0.14509103093934994, 'fraction_numerical': 0.0006701664246621244, 'mean_word_length': 2.9884187082405345, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2089713', 'n_tokens_mistral': 2625, 'n_tokens_neox': 2542, 'n_words': 713}