U ek/@sddlmZddlZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddl Z ddl m Z ddlmZddlmZddlmZdd lmZed Ze e je jZd ZedzZd ddddZd ddddZ d ddddZ!ddddZ"d d dddZ#Gd d!d!e Z$Gd"d#d#e$Z%e &d$d%e 'd%e je 'd&e je 'd'e je 'd(e (ee )d)e jd*e )d+ed*e )d,ed-e )d.e *ed/ge )d0e *ege )d1e *ege )d2e *e jge )d3e *e jge )d4e j+d5e )d6e j+d5e )d7e j+d8e )d9e jd*e )d:e jej,e )d;e jd*e )de j+d5e%d?ge )d@e j+d5Z-e .e-Z/GdAdBdBeZ0ej1e j2e/ee0dCZ3dDZ4dEZ5GdFdGdGe j6Z7GdHdIdIe j8Z9GdJdKdKe j8Z:d d dLdMdNZ;dOdOdPddQdRdSZej?dYfd'e;dZfffd[d\d+dXe>ej?dYfd'e;d]fffd^d_d`d'e;d^ffffZ@Gdadbdbe j8ZAe j&d$d%e 'd%e je 'd%e (eBdcdde@De )d(e (dehdeeAd'e jCfdfdde@Ddgdde-jDDZEe j&d$d%e 'd%e jfdhdde-jDDe$d?ge9d+e je9d,e jfZFe j&d{e-jDe9d+e je9d,e jfZGe &didje 'dje je Hdke .eFdje Ie4e5e Hdke .eGdje4e Hdke .eEdje5e7dle jdje Ie4e5d8dme Jdne=ZKe j&dode LefdpddeDZMe &dqde Ndre .eKe )dse *e (edge OdteMie%duee )d+ed*e )d,ed-e )d6e j+d5e )d2sz parse_version...)tuplesplit)rrrr parse_version0sr )versionrcCs0t|ttjkr,td|dtjddS)Nzpre-commit version z is required but version z? is installed. Perhaps run `pip install --upgrade pre-commit`.)r CVERSIONrr)r!rrrcheck_min_version5sr$r r r )commitz merge-commitpush)stagercCs t||Sr)_STAGESget)r'rrrtransform_stageEsr*c@sNeZdZUded<ded<ddddd Zdddd d Zdddd d ZdS)StagesMigrationNoDefaultrkey Sequence[str]defaultdict[str, Any]rdctrcCsN|j|krdS||j}ttj|dd|D}ttt|dS)NcSsg|] }t|qSrr*rvrrr Tsz2StagesMigrationNoDefault.check..)r,r check_array check_any check_one_ofSTAGES)selfr1valrrrcheckMs   zStagesMigrationNoDefault.checkcCs,|j|krdSdd||jD||j<dS)NcSsg|] }t|qSrr2r3rrrr5Zsz:StagesMigrationNoDefault.apply_default..)r,r:r1rrr apply_defaultWs z&StagesMigrationNoDefault.apply_defaultcCstdSr)NotImplementedErrorr=rrrremove_default\sz'StagesMigrationNoDefault.remove_defaultN)__name__ __module__ __qualname____annotations__r<r>r@rrrrr+Is  r+cs$eZdZdddfdd ZZS)StagesMigrationr/rr0cs ||j|jt|dSr) setdefaultr,r.superr>r= __class__rrr>aszStagesMigration.apply_default)rArBrCr> __classcell__rrrHrrE`srEHookidnameentrylanguagealiasfilesexcludez^$typesfileZtypes_orZ exclude_typesZadditional_dependenciesargsZ always_runF fail_fastZpass_filenamesT descriptionZlanguage_versionZlog_fileminimum_pre_commit_version0Zrequire_serialstagesverbosec@s eZdZdS)InvalidManifestErrorNrArBrCrrrrr]sr])ZschemaZ load_strategyZexc_tplocalmetacs$eZdZdddfdd ZZS)WarnMutableRevr/rr0csVt||j|krR||j}d|krRtd|sRtd|jd|dddS)Nrz^[a-fA-F0-9]+$The z field of repo repoa appears to be a mutable reference (moving tag / branch). Mutable references are never updated after first install and are not supported. See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details. Hint: `pre-commit autoupdate` often fixes this.)rGr<r,rematchloggerwarning)r:r1revrHrrr<s   zWarnMutableRev.checkrArBrCr<rJrrrHrrasracs$eZdZdddfdd ZZS)OptionalSensibleRegexAtHookr/rr0c st|d||jdkr>td|jd|dddD]:}|||jdkrBtd|jd|dd |qBdS) N/*rQrbz field in hook rLzJ is a regex, not a glob -- matching '/*' probably isn't what you want herez[\\/]z[\/]z[/\\]z%pre-commit normalizes slashes in the z1 to forward slashes, so you can use / instead of rGr<r)r,rfrgr:r1Z fwd_slash_rerHrrr<s z!OptionalSensibleRegexAtHook.checkrirrrHrrjsrjcs$eZdZdddfdd ZZS)OptionalSensibleRegexAtTopr/rr0csjt|d||jdkr2td|jddD].}|||jdkr6td|jd|q6dS)NrkrQzThe top-level zP field is a regex, not a glob -- matching '/*' probably isn't what you want hererlz3pre-commit normalizes the slashes in the top-level z7 field to forward slashes, so you can use / instead of rmrnrHrrr<s  z OptionalSensibleRegexAtTop.checkrirrrHrrosro)modnamercCsttjd|S)zthe hook `entry` is passed through `shlex.split()` by the command runner, so to prevent issues with spaces and backslashes (on Windows) it must be quoted here. z -m pre_commit.meta_hooks.)shlexquotesys executable)rprrr_entrysrur-zdict[str, str])extra orig_keysr1rcCstdd|dS)Nz#Unexpected key(s) present at root: , rfrgjoinrvrwr1rrrwarn_unknown_keys_rootsr|cCs$td|ddd|dS)NzUnexpected key(s) present on rcz: rxryr{rrrwarn_unknown_keys_reposr}zcheck-hooks-apply)rMz#Check hooks apply to the repository^$Zcheck_hooks_applyzcheck-useless-excludes)rMzCheck for useless excludesZcheck_useless_excludesidentity)rMr)r\Tc@seZdZdddddZdS) NotAllowedr/rr0cCs |j|krt|jddS)Nz cannot be overridden)r,rrr=rrrr<s zNotAllowed.checkN)rArBrCr<rrrrrsrccs|]\}}|VqdSrr)rk_rrrr srsystemc cs4|],\}}|D]\}}t|tj|d|VqqdS)rLN)rZConditionalOptionalr7)rZhook_idvaluesr,valuerrrrsccs,|]$}|jdkr t|j|jn|VqdS)>rMrNrONr,rOptionalNoDefaultZcheck_fnritemrrrrsccs2|]*}|jdkr|jdkrt|j|jVqdS)rLr[Nrrrrrr(s  Z Repositoryrchooksrh)Z condition_keyZcondition_valueZ ensure_absent)rcrhrZDefaultLanguageVersionccs |]}t|tjtjVqdSr)rOptional check_stringr"DEFAULT)rxrrrrWsZConfigreposdefault_install_hook_typesdefault_language_versiondefault_stages) rrrrrRrSrWrYcirc@s eZdZdS)InvalidConfigErrorNr^rrrrrsr)r )rKrL)U __future__r functoolsloggingrdrqrstypingrrrrZidentify.identifyrZpre_commit.constants constantsr"Zpre_commit.all_languagesrZpre_commit.errorsrZpre_commit.yamlr getLoggerrfZ check_andrZ check_regexZcheck_string_regexZ HOOK_TYPESr9rr r$r(r*r+rEZMapZRequiredr8rr6Z check_boolrZMANIFEST_HOOK_DICTZArrayZMANIFEST_SCHEMAr]partialZload_from_filenameZ load_manifestZLOCALZMETAZ Conditionalrarrjrorur|r}escapeZ CONFIG_FILE_metarrr7itemsZMETA_HOOK_DICTZCONFIG_HOOK_DICTZLOCAL_HOOK_DICTZConditionalRecurseNotInZWarnAdditionalKeysZCONFIG_REPO_DICTZNoAdditionalKeysZDEFAULT_LANGUAGE_VERSIONZRequiredRecurseZOptionalRecurseZ check_typedictZ CONFIG_SCHEMArZ load_configrrrrs                                          +