(ctx, check, autofix)
Validate proper imports in checks.

    If `check` is specified, only the check will be validated, if check value is 'changed' will only apply to changed
    checks, an 'all' or empty `check` value will validate all README files.
Validate proper imports in checks.
Validate proper imports in checks .
def imports(ctx, check, autofix):
    """Validate proper imports in checks.

    If `check` is specified, only the check will be validated, if check value is 'changed' will only apply to changed
    checks, an 'all' or empty `check` value will validate all README files.
    """
    checks = process_checks_option(check, source='integrations')
    echo_info(f"Validating imports for {len(checks)} checks to avoid deprecated modules ...")
    failed = False
    for check_name in checks:
        validation_fails = {}
        echo_debug(f'Checking {check_name}')

        # focus on check and testing directories
        for fpath in get_check_files(check_name):
            success, lines = validate_import(fpath, check_name, autofix)

            if not success:
                failed = True
                validation_fails[fpath] = lines

        if validation_fails:
            num_files = len(validation_fails)
            num_failures = sum(len(lines) for lines in validation_fails.values())
            header_message = f'\nValidation failed: {num_failures} deprecated imports found in {num_files} files:\n'
            echo_failure(header_message)
            for f, lines in validation_fails.items():
                for line in lines:
                    linenum, linetext = line
                    echo_warning(f'{f}: line # {linenum + 1}', indent='  ')
                    echo_info(f'{linetext}', indent='    ')
                    message = 'Detected deprecated import: `{}`, run "ddev validate imports --autofix" to fix.'.format(
                        linetext.strip("\n")
                    )
                    annotate_error(
                        f,
                        message,
                        line=linenum + 1,
                    )

        if failed:
            abort()
    else:
        echo_success('Validation passed!')
def imports ( ctx , check , autofix ) : checks = process_checks_option ( check , source = 'integrations' ) echo_info ( f"Validating imports for {len(checks)} checks to avoid deprecated modules ..." ) failed = False for check_name in checks : validation_fails = { } echo_debug ( f'Checking {check_name}' ) # focus on check and testing directories for fpath in get_check_files ( check_name ) : success , lines = validate_import ( fpath , check_name , autofix ) if not success : failed = True validation_fails [ fpath ] = lines if validation_fails : num_files = len ( validation_fails ) num_failures = sum ( len ( lines ) for lines in validation_fails . values ( ) ) header_message = f'\nValidation failed: {num_failures} deprecated imports found in {num_files} files:\n' echo_failure ( header_message ) for f , lines in validation_fails . items ( ) : for line in lines : linenum , linetext = line echo_warning ( f'{f}: line # {linenum + 1}' , indent = '  ' ) echo_info ( f'{linetext}' , indent = '    ' ) message = 'Detected deprecated import: `{}`, run "ddev validate imports --autofix" to fix.' . format ( linetext . strip ( "\n" ) ) annotate_error ( f , message , line = linenum + 1 , ) if failed : abort ( ) else : echo_success ( 'Validation passed!' )