def _postprocess_include(self):
        """Postprocess --include options."""
        # set up included easyblocks, module naming schemes and toolchains/toolchain components
        if self.options.include_easyblocks:
            include_easyblocks(self.tmpdir, self.options.include_easyblocks)

        if self.options.include_module_naming_schemes:
            include_module_naming_schemes(self.tmpdir, self.options.include_module_naming_schemes)

        if self.options.include_toolchains:
            include_toolchains(self.tmpdir, self.options.include_toolchains)
示例#2
0
    def test_include_toolchains(self):
        """Test include_toolchains()."""
        my_toolchains = os.path.join(self.test_prefix, 'my_toolchains')
        mkdir(my_toolchains)

        # include __init__.py file that should be ignored, and shouldn't cause trouble (bug #1697)
        write_file(os.path.join(my_toolchains, '__init__.py'),
                   "# dummy init, should not get included")

        for subdir in ['compiler', 'fft', 'linalg', 'mpi']:
            mkdir(os.path.join(my_toolchains, subdir))

        my_tc_txt = '\n'.join([
            "from easybuild.toolchains.compiler.my_compiler import MyCompiler",
            "class MyTc(MyCompiler):",
            "   pass",
        ])
        write_file(os.path.join(my_toolchains, 'my_tc.py'), my_tc_txt)

        my_compiler_txt = '\n'.join([
            "from easybuild.tools.toolchain.compiler import Compiler",
            "class MyCompiler(Compiler):",
            "   pass",
        ])
        write_file(os.path.join(my_toolchains, 'compiler', 'my_compiler.py'),
                   my_compiler_txt)

        my_tc_bis = os.path.join(self.test_prefix, 'my_tc.py')
        write_file(my_tc_bis, '')

        # include custom toolchains
        glob_paths = [
            os.path.join(my_toolchains, '*.py'),
            os.path.join(my_toolchains, '*', '*.py'), my_tc_bis
        ]
        included_tcs_path = include_toolchains(self.test_prefix, glob_paths)

        expected_paths = [
            '__init__.py', 'toolchains/__init__.py',
            'toolchains/compiler/__init__.py', 'toolchains/my_tc.py',
            'toolchains/compiler/my_compiler.py'
        ]
        for filepath in expected_paths:
            fullpath = os.path.join(included_tcs_path, 'easybuild', filepath)
            self.assertTrue(os.path.exists(fullpath), "%s exists" % fullpath)

        # path to included MNSs should be prepended to Python search path
        self.assertEqual(sys.path[0], included_tcs_path)

        # importing custom MNS should work
        import easybuild.toolchains.my_tc
        my_tc_pyc_path = easybuild.toolchains.my_tc.__file__
        my_tc_real_py_path = os.path.realpath(
            os.path.join(os.path.dirname(my_tc_pyc_path), 'my_tc.py'))
        self.assertTrue(
            os.path.samefile(up(my_tc_real_py_path, 1), my_toolchains))
示例#3
0
    def test_include_toolchains(self):
        """Test include_toolchains()."""
        my_toolchains = os.path.join(self.test_prefix, 'my_toolchains')
        mkdir(my_toolchains)

        # include __init__.py file that should be ignored, and shouldn't cause trouble (bug #1697)
        write_file(os.path.join(my_toolchains, '__init__.py'), "# dummy init, should not get included")

        for subdir in ['compiler', 'fft', 'linalg', 'mpi']:
            mkdir(os.path.join(my_toolchains, subdir))

        my_tc_txt = '\n'.join([
            "from easybuild.toolchains.compiler.my_compiler import MyCompiler",
            "class MyTc(MyCompiler):",
            "   pass",
        ])
        write_file(os.path.join(my_toolchains, 'my_tc.py'), my_tc_txt)

        my_compiler_txt = '\n'.join([
            "from easybuild.tools.toolchain.compiler import Compiler",
            "class MyCompiler(Compiler):",
            "   pass",
        ])
        write_file(os.path.join(my_toolchains, 'compiler', 'my_compiler.py'), my_compiler_txt)

        my_tc_bis = os.path.join(self.test_prefix, 'my_tc.py')
        write_file(my_tc_bis, '')

        # include custom toolchains
        glob_paths = [os.path.join(my_toolchains, '*.py'), os.path.join(my_toolchains, '*', '*.py'), my_tc_bis]
        included_tcs_path = include_toolchains(self.test_prefix, glob_paths)

        expected_paths = ['__init__.py', 'toolchains/__init__.py', 'toolchains/compiler/__init__.py',
                          'toolchains/my_tc.py', 'toolchains/compiler/my_compiler.py']
        for filepath in expected_paths:
            fullpath = os.path.join(included_tcs_path, 'easybuild', filepath)
            self.assertTrue(os.path.exists(fullpath), "%s exists" % fullpath)

        # path to included MNSs should be prepended to Python search path
        self.assertEqual(sys.path[0], included_tcs_path)

        # importing custom MNS should work
        import easybuild.toolchains.my_tc
        my_tc_pyc_path = easybuild.toolchains.my_tc.__file__
        my_tc_real_py_path = os.path.realpath(os.path.join(os.path.dirname(my_tc_pyc_path), 'my_tc.py'))
        self.assertTrue(os.path.samefile(up(my_tc_real_py_path, 1), my_toolchains))