(self, module_path)
return parser
Load the module.
Load the module.
Load the module .
def _load_module(self, module_path):
        """Load the module."""
        # __import__ will fail on unicode,
        # so we ensure module path is a string here.
        module_path = str(module_path)

        try:
            module_name, attr_name = module_path.split(':', 1)
        except ValueError:  # noqa
            raise self.error(
                '"{}" is not of format "module:parser"'.format(module_path)
            )

        try:
            mod = __import__(module_name, globals(), locals(), [attr_name])
        except (Exception, SystemExit) as exc:  # noqa
            err_msg = 'Failed to import "{}" from "{}". '.format(attr_name, module_name)
            if isinstance(exc, SystemExit):
                err_msg += 'The module appeared to call sys.exit()'
            else:
                err_msg += 'The following exception was raised:\n{}'.format(
                    traceback.format_exc()
                )

            raise self.error(err_msg)

        if not hasattr(mod, attr_name):
            raise self.error(
                'Module "{}" has no attribute "{}"'.format(module_name, attr_name)
            )

        parser = getattr(mod, attr_name)

        if not isinstance(parser, click.BaseCommand):
            raise self.error(
                '"{}" of type "{}" is not derived from '
                '"click.BaseCommand"'.format(type(parser), module_path)
            )
        return parser
def _load_module ( self , module_path ) : # __import__ will fail on unicode, # so we ensure module path is a string here. module_path = str ( module_path ) try : module_name , attr_name = module_path . split ( ':' , 1 ) except ValueError : # noqa raise self . error ( '"{}" is not of format "module:parser"' . format ( module_path ) ) try : mod = __import__ ( module_name , globals ( ) , locals ( ) , [ attr_name ] ) except ( Exception , SystemExit ) as exc : # noqa err_msg = 'Failed to import "{}" from "{}". ' . format ( attr_name , module_name ) if isinstance ( exc , SystemExit ) : err_msg += 'The module appeared to call sys.exit()' else : err_msg += 'The following exception was raised:\n{}' . format ( traceback . format_exc ( ) ) raise self . error ( err_msg ) if not hasattr ( mod , attr_name ) : raise self . error ( 'Module "{}" has no attribute "{}"' . format ( module_name , attr_name ) ) parser = getattr ( mod , attr_name ) if not isinstance ( parser , click . BaseCommand ) : raise self . error ( '"{}" of type "{}" is not derived from ' '"click.BaseCommand"' . format ( type ( parser ) , module_path ) ) return parser