Ejemplo n.º 1
0
def update_config():
    r"""Update the user config file for yggdrasil."""
    from yggdrasil import config, tools
    from yggdrasil.components import import_component
    parser = argparse.ArgumentParser(
        description='Update the user config file.')
    parser.add_argument('--show-file', action='store_true',
                        help='Print the path to the config file without updating it.')
    parser.add_argument('--remove-file', action='store_true',
                        help='Remove the existing config file and return.')
    parser.add_argument('--overwrite', action='store_true',
                        help='Overwrite the existing file.')
    parser.add_argument('--languages', nargs='+',
                        default=tools.get_supported_lang(),
                        help=('One or more languages that should be'
                              'configured.'))
    parser.add_argument('--disable-languages', nargs='+',
                        default=[], dest='disable_languages',
                        help='One or more languages that should be disabled.')
    parser.add_argument('--enable-languages', nargs='+', default=[],
                        help='One or more languages that should be enabled.')
    if ('-h' in sys.argv) or ('--help' in sys.argv):
        prelang = tools.get_supported_lang()
    else:
        prelang = parser.parse_known_args()[0].languages
    lang_args = {}
    old_args = set([x.dest for x in parser._actions])
    for l in prelang:
        drv = import_component('model', l)
        drv.update_config_argparser(parser)
        new_args = set([x.dest for x in parser._actions])
        lang_args[drv.language] = list(new_args - old_args)
        old_args = new_args
    args = parser.parse_args()
    lang_kwargs = {l: {k: getattr(args, k) for k in alist}
                   for l, alist in lang_args.items()}
    if args.show_file:
        print('Config file located here: %s' % config.usr_config_file)
    if args.remove_file and os.path.isfile(config.usr_config_file):
        os.remove(config.usr_config_file)
    if args.show_file or args.remove_file:
        return
    drv = [import_component('model', l) for l in args.languages]
    config.update_language_config(drv, overwrite=args.overwrite, verbose=True,
                                  disable_languages=args.disable_languages,
                                  enable_languages=args.enable_languages,
                                  lang_kwargs=lang_kwargs)
Ejemplo n.º 2
0
def test_update_language_config():
    r"""Test updating configuration for installed languages."""
    drv = [import_component('model', l) for l in tools.get_supported_lang()]
    config.update_language_config(drv, overwrite=True, verbose=True)
    try:
        config.update_language_config(drv[0], disable_languages=[drv[0].language])
        config.update_language_config(drv[0],
                                      disable_languages=[drv[0].language],
                                      enable_languages=[drv[0].language])
    finally:
        config.update_language_config(drv[0], enable_languages=[drv[0].language])
Ejemplo n.º 3
0
def update_config():
    r"""Update the user config file for yggdrasil."""
    from yggdrasil import config, tools
    from yggdrasil.components import import_component
    parser = argparse.ArgumentParser(
        description='Update the user config file.')
    parser.add_argument(
        '--show-file',
        action='store_true',
        help='Print the path to the config file without updating it.')
    parser.add_argument('--remove-file',
                        action='store_true',
                        help='Remove the existing config file and return.')
    parser.add_argument('--overwrite',
                        action='store_true',
                        help='Overwrite the existing file.')
    parser.add_argument('--languages',
                        nargs='+',
                        default=tools.get_supported_lang(),
                        help=('One or more languages that should be'
                              'configured.'))
    parser.add_argument('--disable-languages',
                        nargs='+',
                        default=[],
                        dest='disable_languages',
                        help='One or more languages that should be disabled.')
    parser.add_argument('--enable-languages',
                        nargs='+',
                        default=[],
                        help='One or more languages that should be enabled.')
    args = parser.parse_args()
    if args.show_file:
        print('Config file located here: %s' % config.usr_config_file)
    if args.remove_file and os.path.isfile(config.usr_config_file):
        os.remove(config.usr_config_file)
    if args.show_file or args.remove_file:
        return
    drv = [import_component('model', l) for l in args.languages]
    config.update_language_config(drv,
                                  overwrite=args.overwrite,
                                  verbose=True,
                                  disable_languages=args.disable_languages,
                                  enable_languages=args.enable_languages)
Ejemplo n.º 4
0
def test_update_language_config():
    r"""Test updating configuration for installed languages."""
    languages = tools.get_supported_lang()
    config.update_language_config(overwrite=True, verbose=True)
    try:
        config.update_language_config(languages[0],
                                      disable_languages=[languages[0]])
        config.update_language_config(languages[0],
                                      disable_languages=[languages[0]],
                                      enable_languages=[languages[0]])
    finally:
        config.update_language_config(languages[0],
                                      enable_languages=[languages[0]])
Ejemplo n.º 5
0
def test_update_language_config():
    r"""Test updating configuration for installed languages."""
    languages = tools.get_supported_lang()
    cfg_orig = config.ygg_cfg_usr.file_to_update
    cfg_copy = '_copy'.join(os.path.splitext(cfg_orig))
    shutil.copy2(cfg_orig, cfg_copy)
    try:
        if config.ygg_cfg_usr.has_option('c', 'vcpkg_dir'):
            config.update_language_config('c',
                                          lang_kwargs={
                                              'c': {
                                                  'vcpkg_dir':
                                                  config.ygg_cfg_usr.get(
                                                      'c', 'vcpkg_dir')
                                              }
                                          })
        config.update_language_config(overwrite=True, verbose=True)
        if len(languages) > 0:
            config.ygg_cfg_usr.remove_section(languages[0])
            config.update_language_config(languages[0],
                                          disable_languages=[languages[0]])
            config.update_language_config(languages[0],
                                          disable_languages=[languages[0]],
                                          enable_languages=[languages[0]])
            config.update_language_config(languages[0],
                                          enable_languages=[languages[0]])
        if len(languages) > 1:
            config.ygg_cfg_usr.remove_section(languages[1])
            config.update_language_config(languages[1],
                                          enable_languages=[languages[1]])
    finally:
        shutil.move(cfg_copy, cfg_orig)
        config.ygg_cfg_usr.reload()
        config.ygg_cfg.reload()
Ejemplo n.º 6
0
def update_config():
    r"""Update the user config file for yggdrasil."""
    from yggdrasil import config, tools, platform
    parser = argparse.ArgumentParser(
        description='Update the user config file.')
    parser.add_argument(
        '--show-file',
        action='store_true',
        help='Print the path to the config file without updating it.')
    parser.add_argument('--remove-file',
                        action='store_true',
                        help='Remove the existing config file and return.')
    parser.add_argument('--overwrite',
                        action='store_true',
                        help='Overwrite the existing file.')
    parser.add_argument('--languages',
                        nargs='+',
                        default=tools.get_supported_lang(),
                        help=('One or more languages that should be'
                              'configured.'))
    parser.add_argument('--disable-languages',
                        nargs='+',
                        default=[],
                        dest='disable_languages',
                        help='One or more languages that should be disabled.')
    parser.add_argument('--enable-languages',
                        nargs='+',
                        default=[],
                        help='One or more languages that should be enabled.')
    if ('-h' in sys.argv) or ('--help' in sys.argv):
        prelang = tools.get_supported_lang()
    else:
        prelang = parser.parse_known_args()[0].languages
    lang_args = {}
    lang_args2kwargs = {}
    if platform._is_mac:
        lang_args.setdefault('c', [])
        lang_args['c'].append((('--macos-sdkroot', '--sdkroot'), {
            'help': ('The full path to the MacOS SDK '
                     'that should be used.')
        }))
    for l in prelang:
        if l in lang_args:
            lang_args2kwargs[l] = []
            for args, kwargs in lang_args.get(l, []):
                parser.add_argument(*args, **kwargs)
                lang_args2kwargs[l].append(parser._actions[-1].dest)
    args = parser.parse_args()
    lang_kwargs = {
        l: {k: getattr(args, k)
            for k in alist}
        for l, alist in lang_args2kwargs.items()
    }
    if args.show_file:
        print('Config file located here: %s' % config.usr_config_file)
    if args.remove_file and os.path.isfile(config.usr_config_file):
        os.remove(config.usr_config_file)
    if args.show_file or args.remove_file:
        return
    config.update_language_config(args.languages,
                                  overwrite=args.overwrite,
                                  verbose=True,
                                  disable_languages=args.disable_languages,
                                  enable_languages=args.enable_languages,
                                  lang_kwargs=lang_kwargs)
Ejemplo n.º 7
0
such that they can be run simultaneously, passing input back and forth."""
import os
import sys
import shutil
import logging
from ._version import get_versions
from yggdrasil import platform, config

logging.basicConfig()
logger = logging.getLogger(__name__)

if platform._is_win:  # pragma: windows
    # This is required to fix crash on Windows in case of Ctrl+C
    # https://github.com/ContinuumIO/anaconda-issues/issues/905#issuecomment-232498034
    os.environ['FOR_DISABLE_CONSOLE_CTRL_HANDLER'] = 'T'

if not os.path.isfile(config.usr_config_file):  # pragma: config
    from yggdrasil.languages import install_languages
    shutil.copy(config.def_config_file, config.usr_config_file)
    install_languages.install_all_languages(from_setup=True)
    if not any([
            x.endswith(('yggconfig', 'yggconfig.exe', 'config'))
            for x in sys.argv
    ]):
        # Don't configure if that is what is going to happen anyway
        config.update_language_config(verbose=True)

__all__ = []
__version__ = get_versions()['version']
del get_versions
Ejemplo n.º 8
0
        _test_package_name = order[1]
        _test_package = importlib.import_module(_test_package_name)
    except ImportError:
        _test_package_name = None
        _test_package = None

if platform._is_win:  # pragma: windows
    # This is required to fix crash on Windows in case of Ctrl+C
    # https://github.com/ContinuumIO/anaconda-issues/issues/905#issuecomment-232498034
    os.environ['FOR_DISABLE_CONSOLE_CTRL_HANDLER'] = 'T'

if not os.path.isfile(config.usr_config_file):  # pragma: no cover
    from yggdrasil.languages import install_languages
    shutil.copy(config.def_config_file, config.usr_config_file)
    install_languages.install_all_languages(from_setup=True)
    config.update_language_config()
    with open(config.usr_config_file, 'r') as fd:
        print(fd.read())


def expand_and_add(path, path_list, dir_list):  # pragma: no cover
    r"""Expand the specified path and add it's expanded forms to the provided
    list.

    Args:
        path (str): Absolute/relative path with or without regex wildcard
            expressions to expand.
        path_list (list): Existing list that expansions should be added to.
        dir_list (list): Directories that should be tried for relative paths.

    Returns: