Exemple #1
0
    def find_compiler(self, cmp_cls, *paths):
        # function-local so that cnl doesn't depend on spack.config
        import spack.spec

        compilers = []
        if cmp_cls.PrgEnv:
            if not cmp_cls.PrgEnv_compiler:
                tty.die('Must supply PrgEnv_compiler with PrgEnv')

            modulecmd = get_module_cmd()

            output = modulecmd('avail',
                               cmp_cls.PrgEnv_compiler,
                               output=str,
                               error=str)
            version_regex = r'(%s)/([\d\.]+[\d])' % cmp_cls.PrgEnv_compiler
            matches = re.findall(version_regex, output)
            for name, version in matches:
                v = version
                comp = cmp_cls(spack.spec.CompilerSpec(name + '@' + v), self,
                               "any", ['cc', 'CC', 'ftn'],
                               [cmp_cls.PrgEnv, name + '/' + v])

                compilers.append(comp)

        return compilers
Exemple #2
0
 def _detect_crayos_version(self):
     modulecmd = get_module_cmd()
     output = modulecmd("avail", "PrgEnv-", output=str, error=str)
     matches = re.findall(r'PrgEnv-\w+/(\d+).\d+.\d+', output)
     major_versions = set(matches)
     latest_version = max(major_versions)
     return latest_version
Exemple #3
0
def test_get_module_cmd_from_bash_parens(save_env):
    os.environ['BASH_FUNC_module()'] = '() { eval $(echo fill sh $*)\n}'

    module_cmd = get_module_cmd()
    module_cmd_list = module_cmd('list', output=str, error=str)

    assert module_cmd_list == 'fill python list\n'
Exemple #4
0
 def _detect_crayos_version(self):
     modulecmd = get_module_cmd()
     output = modulecmd("avail", "PrgEnv-", output=str, error=str)
     matches = re.findall(r'PrgEnv-\w+/(\d+).\d+.\d+', output)
     major_versions = set(matches)
     latest_version = max(major_versions)
     return latest_version
Exemple #5
0
def test_get_module_cmd_from_bash_ticks(save_env):
    os.environ['BASH_FUNC_module()'] = '() { eval `echo bash $*`\n}'

    module_cmd = get_module_cmd()
    module_cmd_list = module_cmd('list', output=str, error=str)

    assert module_cmd_list == 'python list\n'
Exemple #6
0
    def find_compiler(self, cmp_cls, *paths):
        # function-local so that cnl doesn't depend on spack.config
        import spack.spec

        compilers = []
        if cmp_cls.PrgEnv:
            if not cmp_cls.PrgEnv_compiler:
                tty.die('Must supply PrgEnv_compiler with PrgEnv')

            modulecmd = get_module_cmd()

            output = modulecmd(
                'avail', cmp_cls.PrgEnv_compiler, output=str, error=str)
            version_regex = r'(%s)/([\d\.]+[\d])' % cmp_cls.PrgEnv_compiler
            matches = re.findall(version_regex, output)
            for name, version in matches:
                v = version
                comp = cmp_cls(
                    spack.spec.CompilerSpec(name + '@' + v),
                    self, "any",
                    ['cc', 'CC', 'ftn'], [cmp_cls.PrgEnv, name + '/' + v])

                compilers.append(comp)

        return compilers
Exemple #7
0
def test_get_module_cmd_from_bash_parens(save_env):
    os.environ['BASH_FUNC_module()'] = '() { eval $(echo fill sh $*)\n}'

    module_cmd = get_module_cmd()
    module_cmd_list = module_cmd('list', output=str, error=str)

    assert module_cmd_list == 'fill python list\n'
Exemple #8
0
def test_get_module_cmd_from_bash_ticks(save_env):
    os.environ['BASH_FUNC_module()'] = '() { eval `echo bash $*`\n}'

    module_cmd = get_module_cmd()
    module_cmd_list = module_cmd('list', output=str, error=str)

    assert module_cmd_list == 'python list\n'
Exemple #9
0
 def _avail_targets(self):
     '''Return a list of available CrayPE CPU targets.'''
     if getattr(self, '_craype_targets', None) is None:
         module = get_module_cmd()
         output = module('avail', '-t', 'craype-', output=str, error=str)
         craype_modules = _get_modules_in_modulecmd_output(output)
         self._craype_targets = targets = []
         _fill_craype_targets_from_modules(targets, craype_modules)
     return self._craype_targets
Exemple #10
0
 def _avail_targets(self):
     '''Return a list of available CrayPE CPU targets.'''
     if getattr(self, '_craype_targets', None) is None:
         module = get_module_cmd()
         output = module('avail', '-t', 'craype-', output=str, error=str)
         craype_modules = _get_modules_in_modulecmd_output(output)
         self._craype_targets = targets = []
         _fill_craype_targets_from_modules(targets, craype_modules)
     return self._craype_targets
Exemple #11
0
def test_get_module_cmd_from_which(tmpdir, save_env):
    f = tmpdir.mkdir('bin').join('modulecmd')
    f.write('#!/bin/bash\n' 'echo $*')
    f.chmod(0o770)

    os.environ['PATH'] = str(tmpdir.join('bin')) + ':' + os.environ['PATH']
    os.environ.pop('BASH_FUNC_module()')

    module_cmd = get_module_cmd(b'--norc')
    module_cmd_list = module_cmd('list', output=str, error=str)

    assert module_cmd_list == 'python list\n'
Exemple #12
0
def test_get_module_cmd_from_which(tmpdir, save_env):
    f = tmpdir.mkdir('bin').join('modulecmd')
    f.write('#!/bin/bash\n'
            'echo $*')
    f.chmod(0o770)

    os.environ['PATH'] = str(tmpdir.join('bin')) + ':' + os.environ['PATH']
    os.environ.pop('BASH_FUNC_module()')

    module_cmd = get_module_cmd(b'--norc')
    module_cmd_list = module_cmd('list', output=str, error=str)

    assert module_cmd_list == 'python list\n'
Exemple #13
0
    def find_compilers(self, *paths):
        """Calls the overridden method but prevents it from detecting Cray
        compiler wrappers to avoid possible false detections. The detected
        compilers come into play only if a user decides to work with the Cray's
        frontend OS as if it was a regular Linux environment."""

        env_bu = None

        # We rely on the fact that the PrgEnv-* modules set the PE_ENV
        # environment variable.
        if 'PE_ENV' in os.environ:
            # Copy environment variables to restore them after the compiler
            # detection. We expect that the only thing PrgEnv-* modules do is
            # the environment variables modifications.
            env_bu = os.environ.copy()

            # Get the name of the module from the environment variable.
            prg_env = 'PrgEnv-' + os.environ['PE_ENV'].lower()

            # Unload the PrgEnv-* module. By doing this we intentionally
            # provoke errors when the Cray's compiler wrappers are executed
            # (Error: A PrgEnv-* modulefile must be loaded.) so they will not
            # be detected as valid compilers by the overridden method. We also
            # expect that the modules that add the actual compilers' binaries
            # into the PATH environment variable (i.e. the following modules:
            # 'intel', 'cce', 'gcc', etc.) will also be unloaded since they are
            # specified as prerequisites in the PrgEnv-* modulefiles.
            modulecmd = get_module_cmd()
            exec(
                compile(
                    modulecmd('unload', prg_env, output=str, error=os.devnull),
                    '<string>', 'exec'))

        # Call the overridden method.
        clist = super(CrayFrontend, self).find_compilers(*paths)

        # Restore the environment.
        if env_bu is not None:
            os.environ.clear()
            os.environ.update(env_bu)

        return clist
Exemple #14
0
    def find_compilers(self, *paths):
        """Calls the overridden method but prevents it from detecting Cray
        compiler wrappers to avoid possible false detections. The detected
        compilers come into play only if a user decides to work with the Cray's
        frontend OS as if it was a regular Linux environment."""

        env_bu = None

        # We rely on the fact that the PrgEnv-* modules set the PE_ENV
        # environment variable.
        if 'PE_ENV' in os.environ:
            # Copy environment variables to restore them after the compiler
            # detection. We expect that the only thing PrgEnv-* modules do is
            # the environment variables modifications.
            env_bu = os.environ.copy()

            # Get the name of the module from the environment variable.
            prg_env = 'PrgEnv-' + os.environ['PE_ENV'].lower()

            # Unload the PrgEnv-* module. By doing this we intentionally
            # provoke errors when the Cray's compiler wrappers are executed
            # (Error: A PrgEnv-* modulefile must be loaded.) so they will not
            # be detected as valid compilers by the overridden method. We also
            # expect that the modules that add the actual compilers' binaries
            # into the PATH environment variable (i.e. the following modules:
            # 'intel', 'cce', 'gcc', etc.) will also be unloaded since they are
            # specified as prerequisites in the PrgEnv-* modulefiles.
            modulecmd = get_module_cmd()
            exec(compile(
                modulecmd('unload', prg_env, output=str, error=os.devnull),
                '<string>', 'exec'))

        # Call the overridden method.
        clist = super(CrayFrontend, self).find_compilers(*paths)

        # Restore the environment.
        if env_bu is not None:
            os.environ.clear()
            os.environ.update(env_bu)

        return clist
Exemple #15
0
def test_get_module_cmd_fails(save_env):
    os.environ.pop('BASH_FUNC_module()')
    os.environ.pop('PATH')
    with pytest.raises(ModuleError):
        module_cmd = get_module_cmd(b'--norc')
        module_cmd()  # Here to avoid Flake F841 on previous line
Exemple #16
0
def test_get_module_cmd_fails(save_env):
    os.environ.pop('BASH_FUNC_module()')
    os.environ.pop('PATH')
    with pytest.raises(ModuleError):
        module_cmd = get_module_cmd(b'--norc')
        module_cmd()  # Here to avoid Flake F841 on previous line