Пример #1
0
    def get_installed_python_packages(self, names_only=True, python_cmd=None):
        """Return list of Python packages that are installed

        When names_only is True then only the names are returned, else the full info from `pip list`.
        Note that the names are reported by pip and might be different to the name that need to be used to import it
        """
        if python_cmd is None:
            python_cmd = self.python_cmd
        # Check installed python packages but only check stdout, not stderr which might contain user facing warnings
        cmd_list = [
            python_cmd, '-m', 'pip', 'list', '--isolated',
            '--disable-pip-version-check', '--format', 'json'
        ]
        full_cmd = ' '.join(cmd_list)
        self.log.info("Running command '%s'" % full_cmd)
        proc = subprocess_popen_text(cmd_list, env=os.environ)
        (stdout, stderr) = proc.communicate()
        ec = proc.returncode
        msg = "Command '%s' returned with %s: stdout: %s; stderr: %s" % (
            full_cmd, ec, stdout, stderr)
        if ec:
            self.log.info(msg)
            raise EasyBuildError(
                'Failed to determine installed python packages: %s', stderr)

        self.log.debug(msg)
        pkgs = json.loads(stdout.strip())
        if names_only:
            return [pkg['name'] for pkg in pkgs]
        else:
            return pkgs
Пример #2
0
    def get_installed_python_packages(self):
        """Return list of Python package names that are installed

        Note that the names are reported by pip and might be different to the name that needs to be used to import it
        """
        # Check installed python packages but only check stdout, not stderr which might contain user facing warnings
        cmd_list = [
            self.python_cmd, '-m', 'pip', 'list', '--isolated',
            '--disable-pip-version-check', '--format', 'json'
        ]
        full_cmd = ' '.join(cmd_list)
        self.log.info("Running command '%s'" % full_cmd)
        proc = subprocess_popen_text(cmd_list, env=os.environ)
        (stdout, stderr) = proc.communicate()
        ec = proc.returncode
        self.log.info("Command '%s' returned with %s: stdout: %s; stderr: %s" %
                      (full_cmd, ec, stdout, stderr))
        if ec:
            raise EasyBuildError(
                'Failed to determine installed python packages: %s', stderr)

        return [pkg['name'] for pkg in json.loads(stdout.strip())]
    def make_module_extra(self, *args, **kwargs):
        """Add extra statements to generated module file specific to UCX plugins"""
        txt = super(EB_UCX_Plugins, self).make_module_extra(*args, **kwargs)

        base_conf = dict()
        cmd = ['ucx_info', '-b']
        full_cmd = ' '.join(cmd)
        self.log.info("Running command '%s'" % full_cmd)
        proc = subprocess_popen_text(cmd, env=os.environ)
        (stdout, stderr) = proc.communicate()
        ec = proc.returncode
        msg = "Command '%s' returned with %s: stdout: %s; stderr: %s" % (
            full_cmd, ec, stdout, stderr)
        if ec:
            self.log.info(msg)
            raise EasyBuildError('Failed to determine base UCX info: %s',
                                 stderr)

        for line in stdout.split('\n'):
            try:
                variable, value = line.split(None, 3)[1:]
            except ValueError:
                continue
            if 'MODULES' in variable:
                base_conf[variable] = [
                    x for x in value.strip('"').split(':') if x
                ]

        txt += self.module_generator.prepend_paths('UCX_MODULE_DIR', 'ucx')
        for framework, extra_plugins in self.plugins.items():
            if extra_plugins:
                variable = framework + '_MODULES'
                all_plugins = base_conf[variable] + extra_plugins
                plugins_str = ':' + ':'.join(all_plugins)
                txt += self.module_generator.set_environment(
                    'EB_UCX_' + variable, plugins_str)
        return txt