U e-7 @sXddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl m Z ddl mZddl mZddl mZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%e&dZ'dddddZ(dddddddZ)dddddddddd d!d"Z*d#ddd$d%d&d'Z+Gd(d)d)Z,d*d+d,d-d.Z-d/Z.d0Z/ddd1d2d3d4Z0d)d5d+dd6ddd7d8d9d:Z1d;dd<d=d>Z2d?d#d@dAdBZ3d6dCdDdEZ4dFd;d+d?ddGdHdIZ5ddCdJdKZ6dddLdMdNZ7ej8fddOd?d*ddPdQdRZ9dS)S) annotationsN)Any) Generator)Iterable)MutableMapping)Sequencetags_from_path)color)git)output) languages) load_config)Hook) all_hooks)install_hook_envs)staged_files_only)Store cmd_output_b pre_commitstrint)msgreturncs(dddddddtfdd|DS)N)AFHNZNaWc3s|]}t|VqdSN) unicodedataeast_asian_width).0cwidthsE/opt/hc_python/lib/python3.8/site-packages/pre_commit/commands/run.py &sz_len_cjk..)sum)rr)r'r*_len_cjk$sr-)startcolsend_lenrcCs$d|t||d}||S)N.r)r-)r.r/r0dotsr)r)r* _start_msg)sr3)postfixbool)r.r/end_msg end_color use_colorr5rcCsHd|t|t|t|d}t|||}||||dS)Nr1r )r-lenr format_color)r.r/r7r8r9r5r2endr)r)r* _full_msg.s $r> Iterable[str]Generator[str, None, None])namesincludeexcludercs*t|t|fdd|DS)Nc3s&|]}|r|s|VqdSr")search)r%filenameZ exclude_reZ include_rer)r*r+Bs  z,filter_by_include_exclude..)recompile)rArBrCr)rFr*filter_by_include_exclude<s rIc@sveZdZdddddZejdddd d d d Zddddd dddZdd dddZe dddddddZ dS) Classifierr?None) filenamesrcCsdd|D|_dS)NcSsg|]}tj|r|qSr))ospathlexistsr%fr)r)r* Ks z'Classifier.__init__..)rL)selfrLr)r)r*__init__JszClassifier.__init__N)maxsizerset[str])rErcCst|Sr"r)rSrEr)r)r*_types_for_fileMszClassifier._types_for_filer@)rAtypestypes_or exclude_typesrccsRt|}t|}t|}|D]0}||}||kr|r>||@r||@s|VqdSr") frozensetrW)rSrArXrYrZrEtagsr)r)r*by_typesQs zClassifier.by_typesr)hookrcCs$|t|j|j|j|j|j|jSr")r]rIrLfilesrCrXrYrZ)rSr^r)r)r*filenames_for_hookdszClassifier.filenames_for_hook)rLrBrCrcCs6tjdkr"tjdkr"dd|D}t|||}t|S)N/\css|]}|tjtjVqdSr")replacerMsepaltseprPr)r)r*r+|sz)Classifier.from_config..)rMrerdrIrJ)clsrLrBrCr)r)r* from_configps  zClassifier.from_config) __name__ __module__ __qualname__rT functools lru_cacherWr]r` classmethodrgr)r)r)r*rJIs  rJzMutableMapping[str, str]rV)environrcCs |dd}dd|dDS)NZSKIPr4cSsh|]}|r|qSr))strip)r%skipr)r)r* sz_get_skips..,)getsplit)rnskipsr)r)r* _get_skipss rvZSkippedz(no files to check)rK)sr9rcCstt|tj|dSr")r write_liner r<ZSUBTLE)rwr9r)r)r* _subtle_linesryrbytesztuple[bool, bytes]) classifierr^rur/ diff_beforeverboser9rc Cs$t||}|j|ks"|j|krVtt|jtt j ||dd}d} |} d} d} n|s|j stt|jt tt j ||dd}d} |} d} d} ntt|jd|d|jsd}t} t|j}||j|j0|j|j|j|j||jd k|j|d \} } W5QRXtt| d p"d}t} || k} | s>| rJt j}d }n t j}d }t t !||||s|j"s| s| rt#d|j||s|j"r|dk rt#d|d|| rt#d| || rt#d|| $rt tj%| $|j&dt | pt'| | fS)N)r.r7r8r9r/rF)r.r5r7r8r9r/)r.r0r/r)local)is_localrequire_serialr rZFailedZPassedz - hook id: z - duration: rwz - exit code: z"- files were modified by this hook)Z logfile_name)(tupler`idaliasr writer>nameSKIPPEDr ZYELLOWZ always_runNO_FILESZ TURQUOISEr3Zpass_filenamestime monotonicr languageZin_envprefixZlanguage_versionZrun_hookentryargssrcrround _get_diffZREDZGREENrxr<r}ryroZ write_line_bZlog_filer6)r{r^rur/r|r}r9rLdurationretcodeZ diff_afterZfiles_modifiedoutZ time_beforerZ print_colorstatusr)r)r*_run_single_hooks         rzSequence[Hook])hooksrcCsB|rtdd|D}nd}|dttdtt}t|dS)zCompute the number of columns to display hook messages. The widest that will be displayed is in the no files skipped case: Hook name...(no files to check) Skipped css|]}t|jVqdSr")r-rr%r^r)r)r*r+sz _compute_cols..rrP)maxr;rr)rZname_lenr/r)r)r* _compute_colss rzargparse.Namespace)rrcCsr|jdkrdS|jdkr |jfS|jr<|jr pre-rebase post-rewrite post-merge post-checkout post-commitr)prepare-commit-msg commit-msg) hook_stagecommit_msg_filenamefrom_refto_refr Zget_changed_filesr_ all_filesZ get_all_filesZis_in_merge_conflictZget_conflicted_filesZget_staged_filesrr)r)r*_all_filenamess   r)rcCstddddddd\}}}|S)Nr diff --no-ext-diffz --no-textconvz--ignore-submodulesFcheckr)_rr)r)r*rs rzdict[str, Any])configrrurrc Cst|}tt||d|d}d}t}|D]@}t||||||j|jd\} }|| O}|r0|dsl|jr0qrq0|r|j r|r|j rt dt d|jrdnd } t d d d d d| f|S)zActually run the hooks.r_rCr)r}r9 fail_fastzpre-commit hook(s) made changes. If you are seeing this message in CI, reproduce locally with: `pre-commit run --all-files`. To run `pre-commit` as part of git workflow, use `pre-commit install`.zAll changes made by hooks:alwaysneverr z --no-pagerrrz--color=)rrJrgrrrr}r rZshow_diff_on_failurerr rx subprocesscall) rrrurr/r{retvalZ prior_diffr^Zcurrent_retvalZ git_color_optr)r)r* _run_hookssH  rcCstddd\}}}t|S)Nr zls-filesz --unmerged)rr6ro)rstdoutr)r)r*_has_unmerged_pathsDsr) config_filercCs"tdddd|dd\}}}|dkS)Nr rz--quietrFrrr)rrrr)r)r*_has_unstaged_configIs rr)rstorerrnrc svj oj }|r(tr(tddStjtjkrJtddS|rlt|rltd|ddSj dkrj stdj ddSj d kr| d rd Sj rj |d <j r̈j |d <jrjrj|d<j|d<j|d<j|d<jr(jr(j|d<j|d<jrpjrpjrpjrpj|d<j|d<j|d<j|d<jrj|d<jrj|d<jrj|d<d|d<t}|r|t|jt|}fddt||D}jr&|s&t djd j dW5QRdSt!|fd!d|D}t"||t#||W5QRSQRXt$d"dS)#Nz+Unmerged files. Resolve before committing.rz%Specify both --from-ref and --to-ref.z4Your pre-commit configuration is unstaged. `git add z` to fix this.rz6`--commit-msg-filename` is required for `--hook-stage `rZ_PRE_COMMIT_SKIP_POST_CHECKOUTrZPRE_COMMIT_COMMIT_MSG_SOURCEZPRE_COMMIT_COMMIT_OBJECT_NAMEZPRE_COMMIT_ORIGINZPRE_COMMIT_SOURCEZPRE_COMMIT_FROM_REFZPRE_COMMIT_TO_REFZPRE_COMMIT_PRE_REBASE_UPSTREAMZPRE_COMMIT_PRE_REBASE_BRANCHZPRE_COMMIT_LOCAL_BRANCHZPRE_COMMIT_REMOTE_BRANCHZPRE_COMMIT_REMOTE_NAMEZPRE_COMMIT_REMOTE_URLZPRE_COMMIT_CHECKOUT_TYPEZPRE_COMMIT_IS_SQUASH_MERGEZPRE_COMMIT_REWRITE_COMMAND1Z PRE_COMMITcs:g|]2}jr&|jjks&|jjkrj|jkr|qSr))r^rrrZstagesrrr)r*rRs   zrun..zNo hook with id `z ` in stage `cs$g|]}|jkr|jkr|qSr))rrr)rur)r*rRs Z unreachable)%rr_rloggererrorr6rrrrrrsZprepare_commit_message_sourceZcommit_object_nameZpre_rebase_upstreamZpre_rebase_branchZ remote_name remote_urlZ remote_branchZ local_branchZ checkout_typeZis_squash_mergeZrewrite_command contextlib ExitStack enter_contextr directoryrrr^r rxrvrrAssertionError) rrrrnstashZ exit_stackrr to_installr))rrur*runQs                         r): __future__rargparserrkloggingrMrGrrr#typingrrrrrZidentify.identifyr rr r r Zpre_commit.all_languagesr Zpre_commit.clientlibrZpre_commit.hookrZpre_commit.repositoryrrZpre_commit.staged_files_onlyrZpre_commit.storerZpre_commit.utilr getLoggerrr-r3r>rIrJrvrrryrrrrrrrrnrr)r)r)r*s\                     8`*