How to use the easybuild.framework.easyblock.EasyBlock function in easybuild

To help you get started, we’ve selected a few easybuild examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github easybuilders / easybuild-framework / test / framework / utilities.py View on Github external
# initialize configuration so config.get_modules_tool function works
    eb_go = eboptions.parse_options(args=args, with_include=with_include)
    config.init(eb_go.options, eb_go.get_options_by_section('config'))

    # initialize build options
    if build_options is None:
        build_options = {}

    default_build_options = {
        'extended_dry_run': False,
        'external_modules_metadata': ConfigObj(),
        'local_var_naming_check': 'error',
        'silence_deprecation_warnings': eb_go.options.silence_deprecation_warnings,
        'suffix_modules_path': GENERAL_CLASS,
        'valid_module_classes': module_classes(),
        'valid_stops': [x[0] for x in EasyBlock.get_steps()],
    }
    for key in default_build_options:
        if key not in build_options:
            build_options[key] = default_build_options[key]

    config.init_build_options(build_options=build_options)

    return eb_go.options
github easybuilders / easybuild-easyconfigs / test / easyconfigs / easyconfigs.py View on Github external
"""Baseclass for easyconfig testcases."""

    # initialize configuration (required for e.g. default modules_tool setting)
    eb_go = eboptions.parse_options()
    config.init(eb_go.options, eb_go.get_options_by_section('config'))
    build_options = {
        'check_osdeps': False,
        'external_modules_metadata': {},
        'force': True,
        'local_var_naming_check': 'error',
        'optarch': 'test',
        'robot_path': get_paths_for("easyconfigs")[0],
        'silent': True,
        'suffix_modules_path': GENERAL_CLASS,
        'valid_module_classes': config.module_classes(),
        'valid_stops': [x[0] for x in EasyBlock.get_steps()],
    }
    config.init_build_options(build_options=build_options)
    set_tmpdir()
    del eb_go

    # put dummy 'craype-test' module in place, which is required for parsing easyconfigs using Cray* toolchains
    TMPDIR = tempfile.mkdtemp()
    os.environ['MODULEPATH'] = TMPDIR
    write_file(os.path.join(TMPDIR, 'craype-test'), '#%Module\n')

    log = fancylogger.getLogger("EasyConfigTest", fname=False)

    # make sure a logger is present for main
    eb_main._log = log
    ordered_specs = None
    parsed_easyconfigs = []
github easybuilders / easybuild-framework / test / framework / easyblock.py View on Github external
"toolchain = {'name': 'dummy', 'version': 'dummy'}",
            "dependencies = [('GCC', '6.4.0-2.28'), ('toy', '0.0-deps')]",
            "builddependencies = [('OpenMPI', '2.1.2-GCC-6.4.0-2.28')]",
            # hidden deps must be included in list of (build)deps
            "hiddendependencies = [('toy', '0.0-deps'), ('OpenMPI', '2.1.2-GCC-6.4.0-2.28')]",
            "modextravars = %s" % str(modextravars),
            "modextrapaths = %s" % str(modextrapaths),
        ])

        test_dir = os.path.dirname(os.path.abspath(__file__))
        os.environ['MODULEPATH'] = os.path.join(test_dir, 'modules')

        # test if module is generated correctly
        self.writeEC()
        ec = EasyConfig(self.eb_file)
        eb = EasyBlock(ec)
        eb.installdir = os.path.join(config.install_path(), 'pi', '3.14')
        eb.check_readiness_step()
        eb.make_builddir()
        eb.prepare_step()

        modpath = os.path.join(eb.make_module_step(), name, version)
        if get_module_syntax() == 'Lua':
            modpath += '.lua'
        self.assertTrue(os.path.exists(modpath), "%s exists" % modpath)

        # verify contents of module
        txt = read_file(modpath)
        if get_module_syntax() == 'Tcl':
            self.assertTrue(re.search(r"^#%Module", txt.split('\n')[0]))
            self.assertTrue(re.search(r"^conflict\s+%s$" % name, txt, re.M))
github easybuilders / easybuild-framework / test / framework / easyblock.py View on Github external
defaulttxt = eb.make_module_extra().strip()
        self.assertTrue(expected_default.match(defaulttxt),
                        "Pattern %s found in %s" % (expected_default.pattern, defaulttxt))

        alttxt = eb.make_module_extra(altroot='/opt/software/tau/6.28', altversion='6.28').strip()
        self.assertTrue(expected_alt.match(alttxt),
                        "Pattern %s found in %s" % (expected_alt.pattern, alttxt))

        installver = '3.14-gompi-2018a'

        # also check how absolute paths specified in modexself.contents = '\n'.join([
        self.contents += "\nmodextrapaths = {'TEST_PATH_VAR': ['foo', '/test/absolute/path', 'bar']}"
        self.writeEC()
        ec = EasyConfig(self.eb_file)
        eb = EasyBlock(ec)
        eb.installdir = os.path.join(config.install_path(), 'pi', installver)
        eb.check_readiness_step()

        # absolute paths are not allowed by default
        error_pattern = "Absolute path .* passed to update_paths which only expects relative paths"
        self.assertErrorRegex(EasyBuildError, error_pattern, eb.make_module_step)

        # allow use of absolute paths, and verify contents of module
        self.contents += "\nallow_prepend_abs_path = True"
        self.writeEC()
        ec = EasyConfig(self.eb_file)
        eb = EasyBlock(ec)
        eb.installdir = os.path.join(config.install_path(), 'pi', installver)
        eb.check_readiness_step()

        modrootpath = eb.make_module_step()
github easybuilders / easybuild-framework / test / framework / easyblock.py View on Github external
self.writeEC()
        eb = EasyBlock(EasyConfig(self.eb_file))
        eb.installdir = config.install_path()

        # no $MODULEPATH extensions for default module naming scheme (EasyBuildMNS)
        self.assertEqual(eb.make_module_extend_modpath(), '')
        usermodsdir = 'my/own/modules'
        modclasses = ['compiler', 'tools']
        os.environ['EASYBUILD_MODULE_NAMING_SCHEME'] = 'CategorizedHMNS'
        build_options = {
            'subdir_user_modules': usermodsdir,
            'valid_module_classes': modclasses,
            'suffix_modules_path': 'funky',
        }
        init_config(build_options=build_options)
        eb = EasyBlock(EasyConfig(self.eb_file))
        eb.installdir = config.install_path()

        txt = eb.make_module_extend_modpath()
        if get_module_syntax() == 'Tcl':
            regexs = [r'^module use ".*/modules/funky/Compiler/pi/3.14/%s"$' % c for c in modclasses]
            home = r'\$::env\(HOME\)'
            fj_usermodsdir = 'file join "%s" "funky" "Compiler/pi/3.14"' % usermodsdir
            regexs.extend([
                # extension for user modules is guarded
                r'if { \[ file isdirectory \[ file join %s \[ %s \] \] \] } {$' % (home, fj_usermodsdir),
                # no per-moduleclass extension for user modules
                r'^\s+module use \[ file join %s \[ %s \] \]$' % (home, fj_usermodsdir),
            ])
        elif get_module_syntax() == 'Lua':
            regexs = [r'^prepend_path\("MODULEPATH", ".*/modules/funky/Compiler/pi/3.14/%s"\)$' % c for c in modclasses]
            home = r'os.getenv\("HOME"\)'
github easybuilders / easybuild-framework / test / framework / easyconfig.py View on Github external
'exts_default_options = {"source_urls": [PYPI_SOURCE]}',
            'exts_list = [',
            '   ("toy", "0.0", {',
            # %(name)s and %(version_major_minor)s should be resolved using name/version of extension (not parent)
            # %(pymajver)s should get resolved because Python is listed as a (runtime) dep
            # %(versionsuffix)s should get resolved with value of parent
            '       "source_tmpl": "%(name)s-%(version_major_minor)s-py%(pymajver)s%(versionsuffix)s.tar.gz",',
            '       "patches": ["%(name)s-%(version)s_fix-silly-typo-in-printf-statement.patch"],',
            # use hacky prebuildopts that is picked up by 'EB_Toy' easyblock, to check whether templates are resolved
            '       "prebuildopts": "gcc -O2 %(name)s.c -o toy-%(version)s && mv toy-%(version)s toy #",',
            '   }),',
            ']',
        ])
        self.prep()
        ec = EasyConfig(self.eb_file)
        eb = EasyBlock(ec)
        eb.fetch_step()

        # run extensions step to install 'toy' extension
        eb.extensions_step()

        # check whether template values were resolved correctly in Extension instances that were created/used
        toy_ext = eb.ext_instances[0]
        self.assertEqual(os.path.basename(toy_ext.src), 'toy-0.0-py3-test.tar.gz')
        self.assertEqual(toy_ext.patches, [os.path.join(self.test_prefix, toy_patch_fn)])
        expected = {
            'patches': ['toy-0.0_fix-silly-typo-in-printf-statement.patch'],
            'prebuildopts': 'gcc -O2 toy.c -o toy-0.0 && mv toy-0.0 toy #',
            'source_tmpl': 'toy-0.0-py3-test.tar.gz',
            'source_urls': ['https://pypi.python.org/packages/source/t/toy'],
        }
        self.assertEqual(toy_ext.options, expected)
github easybuilders / easybuild-framework / test / framework / sandbox / easybuild / easyblocks / o / openmpi.py View on Github external
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild.  If not, see .
##
"""
Dummy easyblock for OpenMPI

@author: Kenneth Hoste (Ghent University)
"""
from easybuild.framework.easyblock import EasyBlock


class EB_OpenMPI(EasyBlock):
    pass
github easybuilders / easybuild-framework / test / framework / easyconfig.py View on Github external
def test_multi_deps_templated_builddeps(self):
        """Test effect of multi_deps on builddependencies w.r.t. resolving templates like %(pyver)s."""
        test_ecs_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
        toy_ec = os.path.join(test_ecs_dir, 't', 'toy', 'toy-0.0.eb')
        toy_ec_txt = read_file(toy_ec)

        test_ec = os.path.join(self.test_prefix, 'test.eb')
        test_ec_txt = toy_ec_txt + "\nmulti_deps = {'Python': ['3.7.2', '2.7.15']}"
        write_file(test_ec, test_ec_txt + "\nbuilddependencies = [('SWIG', '3.0.12', '-Python-%(pyver)s')]")
        ec = EasyConfig(test_ec)
        eb = EasyBlock(ec)
        eb.silent = True

        # start iteration #0
        eb.handle_iterate_opts()

        builddeps = ec['builddependencies']

        self.assertTrue(isinstance(builddeps, list))
        self.assertEqual(len(builddeps), 2)
        self.assertTrue(all(isinstance(bd, dict) for bd in builddeps))

        # 1st listed build dep should be first version of Python (via multi_deps)
        self.assertEqual(builddeps[0]['name'], 'Python')
        self.assertEqual(builddeps[0]['version'], '3.7.2')
        self.assertEqual(builddeps[0]['full_mod_name'], 'Python/3.7.2')
github easybuilders / easybuild-framework / test / framework / easyblock.py View on Github external
def test_gen_dirs(self):
        """Test methods that generate/set build/install directory names."""
        self.contents = '\n'.join([
            'easyblock = "ConfigureMake"',
            "name = 'pi'",
            "version = '3.14'",
            "homepage = 'http://example.com'",
            "description = 'test easyconfig'",
            "toolchain = {'name': 'dummy', 'version': 'dummy'}",
        ])
        self.writeEC()
        stdoutorig = sys.stdout
        sys.stdout = open("/dev/null", 'w')
        eb = EasyBlock(EasyConfig(self.eb_file))
        resb = eb.gen_builddir()
        resi = eb.gen_installdir()
        eb.make_builddir()
        eb.make_installdir()
        # doesn't return anything
        self.assertEqual(resb, None)
        self.assertEqual(resi, None)
        # directories are set, and exist
        self.assertTrue(os.path.isdir(eb.builddir))
        self.assertTrue(os.path.isdir(eb.installdir))

        # make sure cleaning up old build dir is default
        self.assertTrue(eb.cfg['cleanupoldbuild'] or eb.cfg.get('cleanupoldbuild', True))
        builddir = eb.builddir
        eb.gen_builddir()
        self.assertEqual(builddir, eb.builddir)
github easybuilders / easybuild-framework / easybuild / easyblocks / _generic_ / intelbase.py View on Github external
    @staticmethod
    def extra_options(extra_vars=None):
        origvars = EasyBlock.extra_options(extra_vars)
        intel_vars = [
                      ('license', [None, "License file path (default: None)", MANDATORY]),
                      ('license_activation', ['license_server', "Indicates license activation type (default: 'license_server')", CUSTOM]),
                       # 'usetmppath':
                       # workaround for older SL5 version (5.5 and earlier)
                       # used to be True, but False since SL5.6/SL6
                       # disables TMP_PATH env and command line option
                      ('usetmppath', [False, "Use temporary path for installation (default: False)", CUSTOM]),
                      ('m32', [False, "Enable 32-bit toolchain (default: False)", CUSTOM]),
                     ]
        intel_vars.extend(origvars)
        return intel_vars