@classmethod
    def import_module(cls):
        """
        Attempt to import the configured module.

        If it could not be imported, use the executable.

        """

        if hasattr(cls, '_cmd'):
            return

        module = getattr(cls, 'module', None)
        cls._cmd = None
        cmd = cls.cmd
        script = None

        if isinstance(cls.cmd, (list, tuple)):
            cmd = cls.cmd[0]

        if module is not None:
            try:
                module = importlib.import_module(module)
                persist.debug('{} imported {}'.format(cls.name, module))

                # If the linter specifies a python version, check to see
                # if ST's python satisfies that version.
                if cmd and not callable(cmd):
                    match = util.PYTHON_CMD_RE.match(cmd)

                    if match and match.group('version'):
                        version, script = match.group('version', 'script')
                        version = util.find_python(version=version, script=script, module=module)

                        # If we cannot find a python or script of the right version,
                        # we cannot use the module.
                        if version[0] is None or script and version[1] is None:
                            module = None

            except __HOLE__:
                message = '{}import of {} module in {} failed'

                if cls.check_version:
                    warning = 'WARNING: '
                    message += ', linter will not work with python 3 code'
                else:
                    warning = ''
                    message += ', linter will not run using built in python'

                persist.printf(message.format(warning, module, cls.name))
                module = None

            except Exception as ex:
                persist.printf(
                    'ERROR: unknown exception in {}: {}'
                    .format(cls.name, str(ex))
                )
                module = None

        # If no module was specified, or the module could not be imported,
        # or ST's python does not satisfy the version specified, see if
        # any version of python available satisfies the linter. If not,
        # set the cmd to '' to disable the linter.
        can_lint = True

        if not module and cmd and not callable(cmd):
            match = util.PYTHON_CMD_RE.match(cmd)

            if match and match.group('version'):
                can_lint = False
                version, script = match.group('version', 'script')
                version = util.find_python(version=version, script=script)

                if version[0] is not None and (not script or version[1] is not None):
                    can_lint = True

        if can_lint:
            cls._cmd = cls.cmd

            # If there is a module, setting cmd to None tells us to
            # use the check method.
            if module:
                cls.cmd = None
        else:
            persist.printf(
                'WARNING: {} deactivated, no available version of python{} satisfies {}'
                .format(
                    cls.name,
                    ' or {}'.format(script) if script else '',
                    cmd
                ))

            cls.disabled = True

        cls.module = module
dataset/ETHPy150Open SublimeLinter/SublimeLinter3/lint/python_linter.py/PythonLinter.import_module