"""cfn-list test runner."""from__future__importannotationsimportlocaleimportloggingimportrunpyimportsysfrompathlibimportPathfromtypingimportTYPE_CHECKING,Anyimportyamlfrom..._loggingimportPrefixAdaptorfrom...utilsimportargvfrom.baseimportTestHandlerifTYPE_CHECKING:from...config.components.runway.baseimportConfigPropertyTYPE_NAME="cfn-lint"LOGGER=logging.getLogger(__name__)
[docs]@classmethoddefhandle(cls,name:str,args:ConfigProperty|dict[str,Any])->None:"""Perform the actual test. Relies on .cfnlintrc file to be located beside the Runway config file. """logger=PrefixAdaptor(name,LOGGER)cfnlintrc=Path("./.cfnlintrc")ifnotcfnlintrc.is_file():logger.error("file must exist to use this test: %s",cfnlintrc)sys.exit(1)# prevent duplicate log messages by not passing to the root loggerlogging.getLogger("cfnlint").propagate=Falsetry:withargv(*["cfn-lint",*args.get("cli_args",[])]):runpy.run_module("cfnlint",run_name="__main__")exceptSystemExitaserr:# this call will always result in SystemExitiferr.code!=0:# ignore zero exit codes but re-raise for non-zeroifnot(yaml.safe_load(cfnlintrc.read_text(encoding=locale.getpreferredencoding(do_setlocale=False)))or{}).get("templates"):logger.warning('cfnlintrc is missing a "templates" section which is required by cfn-lint')raise