U e @sddlmZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZedZdddddZ dddddZ!dddddZ"dddddZ#dd d!d"d#Z$dd$d!d%d&Z%d'd'd'd(d)d*Z&d'd+d'd,d-d.d/Z'd'd+d'd,d-d0d1Z(d'd+d'd,d-d2d3Z)d4d+d$d5d6d7Z*d'd+d,d8d9d:Z+dS);) annotationsN)Any)Sequence) languages) load_manifest)LOCAL)META) parse_version)Hook)environment_dir)Prefix)Store)clean_path_on_failure)rmtreeZ pre_commitstr)venvreturncCstj|dS)Nz.install_state_v1ospathjoinrrC/opt/hc_python/lib/python3.8/site-packages/pre_commit/repository.py_state_filename_v1srcCstj|dS)Nz.install_state_v2rrrrr_state_filename_v2sr Sequence[str]object)additional_depsrcCsd|iS)Nadditional_dependenciesr)rrrr_state#sr z object | Nonec CsBt|}tj|sdSt|}t|W5QRSQRXdSN)rrrexistsopenjsonload)rfilenamefrrr _read_state's   r(r bool)hookrcCs^t|j}|jdkrdSt|j|j|j}tjt |sLt |t |j ko\| |j|j S)NT)rlanguageENVIRONMENT_DIRr prefixlanguage_versionrrr"rr(r r health_check)r*langrrrr_hook_installed0s  r1Nonec CsDtd|jdtdtd|jdkrTtd|jdt|jdt|j}|jdk slt t |j |j|j }t j|rt|t|||j |j |j||j |j }|rt d |jd |t|}|d }t|d }|tt|jW5QRXt ||tt|d W5QRXdS)NzInstalling environment for .z/Once installed this environment will be reused.zThis may take a few minutes...Z python_venvz`repo: zz` uses deprecated `language: python_venv`. This is an alias for `language: python`. Often `pre-commit autoupdate --repo z` will fix this.zBUG: expected environment for zh to be healthy immediately after install, please open an issue describing your environment more info: stagingwza+)loggerinfosrcr+warningshlexquoterr,AssertionErrorr r-r.rrr"rrZinstall_environmentrr/rr#writer$dumpsr replacerclose)r*r0rZ health_errorZstate_filenamer4Z state_filerrr _hook_installCsB           rAzdict[str, Any]) hook_dicts root_configrc GsBt|d|dd}}|D]}||q|d}t|ttjkrttd|dd|dtjdtd|d }|d tjkr|d ||d <|d tjkrt | |d <|d s|d |d <t |j dkr>|d tjkrtd|dd|dtd|dr>td|dd|dtd|S)NrZminimum_pre_commit_versionz The hook `idz` requires pre-commit version z but version z? is installed. Perhaps run `pip install --upgrade pre-commit`.r+r.Zdefault_language_versionZstagesZdefault_stagesz6` specifies `language_version` but is using language `zW` which does not install an environment. Perhaps you meant to use a specific language?rz=` specifies `additional_dependencies` but is using language `) dictupdater CVERSIONr6errorexitDEFAULTrZget_default_versionr,)rCrBretrestdctversionr0rrr_hookws8   rQr ztuple[Hook, ...]) repo_configstorerCrcs4ddddfdd tfddd DS) Nrrr ) language_namedepsrcs0t|}|jdkrttSt|SdSr!)rr,r rgetcwdZ make_local)rTrUr+)rSrr_prefixs  z-_non_cloned_repository_hooks.._prefixc 3s6|].}td|d|dt|dVqdS)repor+rrCN)r createrQ.0r*)rWrRrCrr s  z/_non_cloned_repository_hooks..hookstuplerRrSrCr)rWrRrCrSr_non_cloned_repository_hookss rbcsddtjtj}ddt|DdD]4}|dkrDtd|ddd t d qDfd d dD}t fd d|DS)NrXrevcSsi|]}|d|qS)rErr[rrr sz,_cloned_repository_hooks..r^rE`z` is not present in repository z`. Typo? Perhaps it is introduced in a newer version? Often `pre-commit autoupdate` fixes this.rDcs"g|]}t|d|dqS)rErY)rQr[)by_idrCrr sz,_cloned_repository_hooks..c 3s2|]*}tdt|d|VqdS)rXrN)r rZr cloner[)rXrRrcrSrrr]s z+_cloned_repository_hooks..) rrrrhrHZ MANIFEST_FILErr6rJrKr`)rRrSrCZ manifest_pathr*Z hook_dctsr)rfrXrRrcrCrSr_cloned_repository_hookss    ricCs,|dtthkrt|||St|||SdS)NrX)rrrbrirarrr_repository_hookss rjzSequence[Hook])r^rSrc sHddfdd }|sdS||D] }t|q,W5QRXdS)Nz list[Hook])rcs@t}g}D],}|j|kr.t|s.||||jq|Sr!)setZ install_keyr1appendadd)seenrMr*r^rr_need_installeds z*install_hook_envs.._need_installed)Zexclusive_lockrA)r^rSrpr*rrorinstall_hook_envss    rq)rCrSrcstfdddDS)Nc3s$|]}t|D] }|VqqdSr!)rj)r\rXr*rCrSrrr]szall_hooks..Zreposr_rrrrrr all_hookssrs), __future__rr$loggingrr:typingrrZpre_commit.constants constantsrHZpre_commit.all_languagesrZpre_commit.clientlibrrrr Zpre_commit.hookr Zpre_commit.lang_baser Zpre_commit.prefixr Zpre_commit.storer Zpre_commit.utilrr getLoggerr6rrr r(r1rArQrbrirjrqrsrrrrs>                 4/