Ejemplo n.º 1
0
    def is_installed(self):
        r"""Determine if this model driver is installed on the current
        machine.

        Returns:
            bool: Truth of if this model driver can be run on the current
                machine.

        """
        return (len(tools.get_installed_comm(language='c')) > 0)
Ejemplo n.º 2
0
def test_get_installed():
    r"""Test get_installed_<lang/comm>."""
    tools.get_installed_lang()
    tools.get_installed_comm()
Ejemplo n.º 3
0
def ygginfo():
    r"""Print information about yggdrasil installation."""
    from yggdrasil import __version__, tools, config, platform
    from yggdrasil.components import import_component
    lang_list = tools.get_installed_lang()
    prefix = '    '
    curr_prefix = ''
    vardict = [
        ('Location', os.path.dirname(__file__)), ('Version', __version__),
        ('Languages', ', '.join(lang_list)),
        ('Communication Mechanisms', ', '.join(tools.get_installed_comm())),
        ('Default Comm Mechanism', tools.get_default_comm()),
        ('Config File', config.usr_config_file)
    ]
    parser = argparse.ArgumentParser(
        description=
        'Display information about the current yggdrasil installation.')
    parser.add_argument(
        '--no-languages',
        action='store_true',
        dest='no_languages',
        help='Don\'t print information about individual languages.')
    parser.add_argument(
        '--verbose',
        action='store_true',
        help='Increase the verbosity of the printed information.')
    args = parser.parse_args()
    try:
        # Add language information
        if not args.no_languages:
            # Install languages
            vardict.append(('Installed Languages:', ''))
            curr_prefix += prefix
            for lang in sorted(lang_list):
                drv = import_component('model', lang)
                vardict.append((curr_prefix + '%s:' % lang.upper(), ''))
                curr_prefix += prefix
                if lang == 'executable':
                    vardict.append((curr_prefix + 'Location', ''))
                else:
                    exec_name = drv.language_executable()
                    if not os.path.isabs(exec_name):
                        exec_name = tools.which(exec_name)
                    vardict.append((curr_prefix + 'Location', exec_name))
                vardict.append(
                    (curr_prefix + 'Version', drv.language_version()))
                curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
            curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
            # Not installed languages
            vardict.append(("Languages Not Installed:", ''))
            curr_prefix += prefix
            for lang in tools.get_supported_lang():
                if lang in lang_list:
                    continue
                drv = import_component('model', lang)
                vardict.append((curr_prefix + '%s:' % lang.upper(), ''))
                curr_prefix += prefix
                vardict.append((curr_prefix + "Language Installed",
                                drv.is_language_installed()))
                vardict.append((curr_prefix + "Base Languages Installed",
                                drv.are_base_languages_installed()))
                if not drv.are_base_languages_installed():
                    vardict.append(
                        (curr_prefix + "Base Languages Not Installed", [
                            b for b in drv.base_languages if
                            (not import_component('model', b).is_installed())
                        ]))
                vardict.append((curr_prefix + "Dependencies Installed",
                                drv.are_dependencies_installed()))
                vardict.append((curr_prefix + "Interface Installed",
                                drv.is_interface_installed()))
                vardict.append(
                    (curr_prefix + "Comm Installed", drv.is_comm_installed()))
                vardict.append(
                    (curr_prefix + "Configured", drv.is_configured()))
                vardict.append((curr_prefix + "Disabled", drv.is_disabled()))
                curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
            curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
        # Add verbose information
        if args.verbose:
            # Conda info
            if os.environ.get('CONDA_PREFIX', ''):
                out = tools.bytes2str(
                    subprocess.check_output(['conda', 'info'])).strip()
                curr_prefix += prefix
                vardict.append((curr_prefix + 'Conda Info:',
                                "\n%s%s" % (curr_prefix + prefix,
                                            ("\n" + curr_prefix + prefix).join(
                                                out.splitlines(False)))))
                curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
            # R and reticulate info
            Rdrv = import_component("model", "R")
            if Rdrv.is_installed():
                env_reticulate = copy.deepcopy(os.environ)
                env_reticulate['RETICULATE_PYTHON'] = sys.executable
                # Stack size
                out = Rdrv.run_executable(["-e", "Cstack_info()"]).strip()
                vardict.append((curr_prefix + "R Cstack_info:",
                                "\n%s%s" % (curr_prefix + prefix,
                                            ("\n" + curr_prefix + prefix).join(
                                                out.splitlines(False)))))
                # Compilation tools
                interp = 'R'.join(Rdrv.get_interpreter().rsplit('Rscript', 1))
                vardict.append((curr_prefix + "R C Compiler:", ""))
                curr_prefix += prefix
                for x in ['CC', 'CFLAGS', 'CXX', 'CXXFLAGS']:
                    out = tools.bytes2str(
                        subprocess.check_output([interp, 'CMD', 'config',
                                                 x])).strip()
                    vardict.append((curr_prefix + x,
                                    "%s" % ("\n" + curr_prefix + prefix).join(
                                        out.splitlines(False))))
                curr_prefix = curr_prefix.rsplit(prefix, 1)[0]
                # Session info
                out = Rdrv.run_executable(["-e", "sessionInfo()"]).strip()
                vardict.append((curr_prefix + "R sessionInfo:",
                                "\n%s%s" % (curr_prefix + prefix,
                                            ("\n" + curr_prefix + prefix).join(
                                                out.splitlines(False)))))
                # Reticulate conda_list
                if os.environ.get('CONDA_PREFIX', ''):
                    out = Rdrv.run_executable([
                        "-e",
                        ("library(reticulate); "
                         "reticulate::conda_list()")
                    ],
                                              env=env_reticulate).strip()
                    vardict.append(
                        (curr_prefix + "R reticulate::conda_list():",
                         "\n%s%s" % (curr_prefix + prefix,
                                     ("\n" + curr_prefix + prefix).join(
                                         out.splitlines(False)))))
                # Windows python versions
                if platform._is_win:  # pragma: windows
                    out = Rdrv.run_executable([
                        "-e",
                        ("library(reticulate); "
                         "reticulate::py_versions_windows()")
                    ],
                                              env=env_reticulate).strip()
                    vardict.append(
                        (curr_prefix + "R reticulate::py_versions_windows():",
                         "\n%s%s" % (curr_prefix + prefix,
                                     ("\n" + curr_prefix + prefix).join(
                                         out.splitlines(False)))))
                # conda_binary
                if platform._is_win:  # pragma: windows
                    out = Rdrv.run_executable([
                        "-e",
                        ("library(reticulate); "
                         "conda <- reticulate:::conda_binary(\"auto\"); "
                         "system(paste(conda, \"info --json\"))")
                    ],
                                              env=env_reticulate).strip()
                    vardict.append(
                        (curr_prefix + "R reticulate::py_versions_windows():",
                         "\n%s%s" % (curr_prefix + prefix,
                                     ("\n" + curr_prefix + prefix).join(
                                         out.splitlines(False)))))
                # Reticulate py_config
                out = Rdrv.run_executable([
                    "-e", ("library(reticulate); "
                           "reticulate::py_config()")
                ],
                                          env=env_reticulate).strip()
                vardict.append((curr_prefix + "R reticulate::py_config():",
                                "\n%s%s" % (curr_prefix + prefix,
                                            ("\n" + curr_prefix + prefix).join(
                                                out.splitlines(False)))))
    finally:
        # Print things
        max_len = max(len(x[0]) for x in vardict)
        lines = []
        line_format = '%-' + str(max_len) + 's' + prefix + '%s'
        for k, v in vardict:
            lines.append(line_format % (k, v))
        logger.info("yggdrasil info:\n%s" % '\n'.join(lines))
Ejemplo n.º 4
0
    def description_prefix(self):
        r"""Prefix message with test name."""
        out = super(ExampleTimedPipeTestBase, self).description_prefix
        out += '(%s)' % self._new_default_comm
        return out

    @property
    def results(self):
        r"""Result that should be found in output files."""
        siz = int(self.env['PIPE_MSG_COUNT']) * int(self.env['PIPE_MSG_SIZE'])
        res = '0' * siz
        return [res]

    @property
    def output_files(self):
        r"""Output file."""
        return [os.path.join(self.tempdir, 'output_timed_pipe.txt')]


# Dynamically add test classes for comm types
for c in tools.get_installed_comm():
    if c == _default_comm:
        continue
    new_cls = unittest.skipIf(not tools.is_comm_installed(c),
                              "%s library not installed." % c)(type(
                                  'TestExampleTimedPipe%s' % c,
                                  (ExampleTimedPipeTestBase, ),
                                  {'__new_default_comm': c}))
    globals()[new_cls.__name__] = new_cls
    del new_cls
Ejemplo n.º 5
0
def test_get_installed_comm():
    r"""Test get_installed_comm."""
    tools.get_installed_comm()
Ejemplo n.º 6
0
    _static_ext = '.a'
    if platform._is_mac:
        _shared_ext = '.dylib'
    else:
        _shared_ext = '.so'
_datatypes_static_lib = os.path.join(_incl_dtype,
                                     _prefix + 'datatypes' + _static_ext)
_api_static_c = os.path.join(_incl_interface, _prefix + 'ygg' + _static_ext)
_api_static_cpp = os.path.join(_incl_interface,
                               _prefix + 'ygg++' + _static_ext)
_datatypes_shared_lib = os.path.join(_incl_dtype,
                                     _prefix + 'datatypes' + _shared_ext)
_api_shared_c = os.path.join(_incl_interface, _prefix + 'ygg' + _shared_ext)
_api_shared_cpp = os.path.join(_incl_interface,
                               _prefix + 'ygg++' + _shared_ext)
_c_installed = ((len(tools.get_installed_comm(language='c')) > 0)
                and (ygg_cfg.get('c', 'rapidjson_include', None) is not None))


def get_zmq_flags(for_cmake=False, for_api=False):
    r"""Get the necessary flags for compiling & linking with zmq libraries.

    Args:
        for_cmake (bool, optional): If True, the returned flags will match the
            format required by cmake. Defaults to False.
        for_api (bool, optional): If True, the returned flags will match those
            required for compiling the API static library. Defaults to False.

    Returns:
        tuple(list, list): compile and linker flags.
Ejemplo n.º 7
0
import os
import uuid
import unittest
import tempfile
from yggdrasil import runner, tools
from yggdrasil.examples import yamls
from yggdrasil.tests import YggTestBase
from yggdrasil.drivers.MatlabModelDriver import _matlab_installed

_c_comm_installed = tools.get_installed_comm(language='c')


class TestExample(YggTestBase, tools.YggClass):
    r"""Base class for running examples."""

    example_name = None
    expects_error = False
    env = {}

    def __init__(self, *args, **kwargs):
        tools.YggClass.__init__(self, self.example_name)
        self.language = None
        self.uuid = str(uuid.uuid4())
        self.runner = None
        # self.debug_flag = True
        super(TestExample, self).__init__(*args, **kwargs)

    @property
    def description_prefix(self):
        r"""Prefix message with test name."""
        return self.name