How to use the easybuild.tools.run.run_cmd 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 / easybuild / tools / systemtools.py View on Github external
:return: total memory as an integer, specifically a number of megabytes
    """
    memtotal = None
    os_type = get_os_type()

    if os_type == LINUX and is_readable(PROC_MEMINFO_FP):
        _log.debug("Trying to determine total memory size on Linux via %s", PROC_MEMINFO_FP)
        meminfo = read_file(PROC_MEMINFO_FP)
        mem_mo = re.match(r'^MemTotal:\s*(\d+)\s*kB', meminfo, re.M)
        if mem_mo:
            memtotal = int(mem_mo.group(1)) // 1024

    elif os_type == DARWIN:
        cmd = "sysctl -n hw.memsize"
        _log.debug("Trying to determine total memory size on Darwin via cmd '%s'", cmd)
        out, ec = run_cmd(cmd, force_in_dry_run=True, trace=False, stream_output=False)
        if ec == 0:
            memtotal = int(out.strip()) // (1024**2)

    if memtotal is None:
        memtotal = UNKNOWN
        _log.warning("Failed to determine total memory, returning %s", memtotal)

    return memtotal
github easybuilders / easybuild-framework / test / framework / sandbox / easybuild / easyblocks / t / toy.py View on Github external
def build_step(self, name=None, buildopts=None):
        """Build toy."""

        if buildopts is None:
            buildopts = self.cfg['buildopts']

        if name is None:
            name = self.name
        run_cmd('%(prebuildopts)s gcc %(name)s.c -o %(name)s %(buildopts)s' % {
            'name': name,
            'prebuildopts': self.cfg['prebuildopts'],
            'buildopts': buildopts,
        })
github easybuilders / JSC / Custom_EasyBlocks / 2017b / dolfin.py View on Github external
# Boost config parameters
        self.cfg.update('configopts', "-DBOOST_INCLUDEDIR=%s/include" % self.depsdict['Boost'])
        self.cfg.update('configopts', "-DBoost_DEBUG=ON -DBOOST_ROOT=%s" % self.depsdict['Boost'])

        # UFC and Armadillo config params
        if 'UFC' in self.depsdict:
            self.cfg.update('configopts', "-DUFC_DIR=%s" % self.depsdict['UFC'])
        if 'Armadillo' in self.depsdict:
            self.cfg.update('configopts', "-DARMADILLO_DIR:PATH=%s " % self.depsdict['Armadillo'])

        # Eigen config params
        if 'Eigen' in self.depsdict:
            self.cfg.update('configopts', "-DEIGEN3_INCLUDE_DIR=%s " % os.path.join(self.depsdict['Eigen'], 'include'))

        # specify Python paths
        (outtxt, _) = run_cmd("which python", log_all=True)
        # Check if the scipy stack includes the interpreter
        python_in_scipy = re.search("SciPy-Stack",outtxt)
        if python_in_scipy:
            python = self.depsdict['SciPy-Stack']
            (outtxt, _) = run_cmd("python --version 2>&1 | awk '{print $2}'", log_all=True)
            pyver = '.'.join(outtxt.split('.')[:2])
        else:
            python = self.depsdict['Python']
            pyver = '.'.join(get_software_version('Python').split('.')[:2])
        self.cfg.update('configopts', "-DPYTHON_INCLUDE_PATH=%s/include/python%s" % (python, pyver))
        if pyver.split('.')[0] == '2':
            self.cfg.update('configopts', "-DPYTHON_LIBRARY=%s/lib/libpython%s.%s" % (python, pyver, shlib_ext))
        else:
            self.cfg.update('configopts', "-DPYTHON_LIBRARY=%s/lib/libpython%sm.%s" % (python, pyver, shlib_ext))

        # SuiteSparse config params
github eth-cscs / production / easybuild / easyblocks / pycuda.py View on Github external
finaltxt = finaltxt.replace('SITECFGINCDIR', repl)

            self.log.debug("Using %s: %s" % (self.sitecfgfn, finaltxt))
            try:
                if os.path.exists(self.sitecfgfn):
                    txt = open(self.sitecfgfn).read()
                    self.log.debug("Found %s: %s" % (self.sitecfgfn, txt))
                config = open(self.sitecfgfn, 'w')
                config.write(finaltxt)
                config.close()
            except IOError:
                raise EasyBuildError("Creating %s failed", self.sitecfgfn)

        # creates log entries for python being used, for debugging
        run_cmd("python -V")
        run_cmd("which python")
        run_cmd("python -c 'import sys; print(sys.executable)'")

        # don't add user site directory to sys.path (equivalent to python -s)
        # see https://www.python.org/dev/peps/pep-0370/
        env.setvar('PYTHONNOUSERSITE', '1')
        run_cmd("python -c 'import sys; print(sys.path)'")
github easybuilders / easybuild-framework / easybuild / tools / systemtools.py View on Github external
if vendor_regex and is_readable(PROC_CPUINFO_FP):
            vendor_id = None

            proc_cpuinfo = read_file(PROC_CPUINFO_FP)
            res = vendor_regex.search(proc_cpuinfo)
            if res:
                vendor_id = res.group(1)

            if vendor_id in VENDOR_IDS:
                vendor = VENDOR_IDS[vendor_id]
                _log.debug("Determined CPU vendor on Linux as being '%s' via regex '%s' in %s",
                           vendor, vendor_regex.pattern, PROC_CPUINFO_FP)

    elif os_type == DARWIN:
        cmd = "sysctl -n machdep.cpu.vendor"
        out, ec = run_cmd(cmd, force_in_dry_run=True, trace=False, stream_output=False)
        out = out.strip()
        if ec == 0 and out in VENDOR_IDS:
            vendor = VENDOR_IDS[out]
            _log.debug("Determined CPU vendor on DARWIN as being '%s' via cmd '%s" % (vendor, cmd))

    if vendor is None:
        vendor = UNKNOWN
        _log.warning("Could not determine CPU vendor on %s, returning %s" % (os_type, vendor))

    return vendor
github easybuilders / easybuild-framework / easybuild / tools / systemtools.py View on Github external
def get_avail_core_count():
    """
    Returns the number of available CPUs, according to cgroups and taskssets limits
    """
    core_cnt = None
    os_type = get_os_type()

    if os_type == LINUX:
        # simple use available sched_getaffinity() function (yields a long, so cast it down to int)
        core_cnt = int(sum(sched_getaffinity()))
    else:
        # BSD-type systems
        out, _ = run_cmd('sysctl -n hw.ncpu', force_in_dry_run=True, trace=False, stream_output=False)
        try:
            if int(out) > 0:
                core_cnt = int(out)
        except ValueError:
            pass

    if core_cnt is None:
        raise SystemToolsException('Can not determine number of cores on this system')
    else:
        return core_cnt
github eth-cscs / production / easybuild / easyblocks / boost.py View on Github external
def build_boost_variant(self, bjamoptions, paracmd):
        """Build Boost library with specified options for bjam."""
        # build with specified options
        cmd = "%s ./bjam %s %s %s" % (self.cfg['prebuildopts'], bjamoptions, paracmd, self.cfg['buildopts'])
        run_cmd(cmd, log_all=True, simple=True)
        # install built Boost library
        cmd = "%s ./bjam %s install %s %s" % (self.cfg['preinstallopts'], bjamoptions, paracmd, self.cfg['installopts'])
        run_cmd(cmd, log_all=True, simple=True)
        # clean up before proceeding with next build
        run_cmd("./bjam --clean-all", log_all=True, simple=True)
github easybuilders / easybuild-framework / easybuild / tools / systemtools.py View on Github external
for pkg_cmd in pkg_cmds:
        if which(pkg_cmd):
            cmd = ' '.join([pkg_cmd, pkg_cmd_flag.get(pkg_cmd), dep])
            found = run_cmd(cmd, simple=True, log_all=False, log_ok=False,
                            force_in_dry_run=True, trace=False, stream_output=False)
            if found:
                break

    if not found:
        # fallback for when os-dependency is a binary/library
        found = which(dep)

        # try locate if it's available
        if not found and which('locate'):
            cmd = 'locate --regexp "/%s$"' % dep
            found = run_cmd(cmd, simple=True, log_all=False, log_ok=False, force_in_dry_run=True, trace=False,
                            stream_output=False)

    return found
github easybuilders / JSC / Custom_EasyBlocks / 2016a / scotch.py View on Github external
#USE 64 bit index
        if self.toolchain.options['i8']:
            cflags += " -DINTSIZE64"

        if self.cfg['threadedmpi']: 
            cflags += " -DSCOTCH_PTHREAD"

        # actually build
        apps = ['scotch', 'ptscotch']
        if LooseVersion(self.version) >= LooseVersion('6.0'):
            # separate target for esmumps in recent versions
            apps.extend(['esmumps', 'ptesmumps'])
        for app in apps:
            cmd = 'make CCS="%s" CCP="%s" CCD="%s" CFLAGS="%s" %s' % (ccs, ccp, ccd, cflags, app)
            run_cmd(cmd, log_all=True, simple=True)