U e@sddlmZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddl m ZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!Gddde Z"Gddde#Z$ddddddZ%dddddd d!d"Z&e'd#Z(d4d%d&dd'd(d)d*Z)d%d&dd+d,d-Z*d5d%ddd0ddd1d2d3Z+dS)6) annotationsN)Any) NamedTuple)Sequence)git)output)xargs)InvalidManifestError) load_config) load_manifest)LOCAL)META)migrate_config)CalledProcessError) cmd_output) cmd_output_b) yaml_dump) yaml_loadc@s^eZdZUded<ded<dZded<eZded<ed dd d d Zd d ddddZ dS)RevInfostrreporevNz str | Nonefrozenzfrozenset[str]hook_idsdict[str, Any])configreturncCs||d|dS)Nrr)clsrrrL/opt/hc_python/lib/python3.8/site-packages/pre_commit/commands/autoupdate.py from_config"szRevInfo.from_configbool) tags_onlyfreezerc Cst}dtjd|f}|r&d}nd}|ddd|f}t||jt|dt|dzt|d}Wn(t k rt|dd}YnX|rt ||}d}|rt|d|fd} | |kr| |}}z6t|d|dt j ft|d|dt j fWnt k r,YnXzt tj|t j } Wn:tk r} ztd|jd| W5d} ~ XYnXtdd| D} W5QRX|j||| dS)Nrz-Cz --abbrev=0z--exactZdescribe FETCH_HEAD--tagsrextensions.partialClonetruefetchoriginHEAD--quiet--filter=blob:none rev-parseshow:checkoutz--[] css|]}|dVqdS)idNr.0hookrrr Psz!RevInfo.update..)rrr)r)rr&r')r(r)r*r+r,r%)r.r$)tempfileTemporaryDirectoryrZ NO_FS_MONITORZ init_reporrrstriprZget_best_candidate_tagCZ MANIFEST_FILEr ospathjoinr RepositoryCannotBeUpdatedError frozenset_replace) selfr"r#tmp_gitZtag_optZtag_cmdrrexactmanifesterrrrupdate&sN    (zRevInfo.update) __name__ __module__ __qualname____annotations__rrAr classmethodr rIrrrrrs  rc@s eZdZdS)r@N)rJrKrLrrrrr@Usr@rNone) repo_configinforcCsDdd|dD}||j}|r@td|jddt|dS)NcSsh|] }|dqS)r4rr5rrr ^sz2_check_hooks_still_exist_at_rev..hooksr2zB] Cannot update because the update target is missing these hooks: z, )rr@rr?sorted)rPrQrSZ hooks_missingrrr_check_hooks_still_exist_at_revYs  rUintr!ztuple[int, RevInfo, RevInfo])irr"r#rcCs,t|}|j||d}t|||||fS)Nr"r#)rr rIrU)rWrr"r#oldnewrrr _update_onegs  r[z,^(\s+)rev:(\s*)([\'"]?)([^\s#]+)(.*)(\r?\n)$Frzlist[RevInfo | None]ztuple[list[str], list[int]])r> rev_infosretryrc Cst|dd}|}W5QRX|d}ddt|D}t|t|krT||fS|rbtdn6t|d}|tt|W5QRXt ||ddSd S) z(detect `rev:` lines or reformat the filenewlineTcSsg|]\}}t|r|qSr) REV_LINE_REmatch)r6rWlinerrr s z#_original_lines..zcould not find rev linesw)r]N) openread splitlines enumeratelenAssertionErrorwriterr_original_lines)r>r\r]foriginallinesidxsrrrrmws   rm)r>r\rc Cst||\}}t||D]\}}|dkr*qt||}|dk sDttd|ji|dd}|ddd}|j dk rd|j } n |d drd } n|d} |dd |d || |d ||<qt |d d d} | d |W5QRXdS)Nr) default_styler0r-z # frozen: z # frozen:r^zrev:rer_)rmziprarbrkrrsplitr;r startswithrfrlr?) r>r\rprqidxZrev_inforbZ new_rev_sZnew_revcommentrnrrr_write_new_configs   ,r|rr-z Sequence[str]) config_filer"r#reposjobsrc slt|ddd}d}ddt|dD}dgt|}|pBt}t|tpVt|}t|d }tj |fd dt |D} tj | D]} z| \} } } Wn4t k r}ztt|d }W5d}~XYqX| j| jkr0d}| jr| jd }n| j}d | jd |}| || <nd}td| jd|qW5QRX|rht|||S)zBAuto-update the pre-commit config to the latest versions of repos.T)quietFrcSs g|]}|dtthkr|qS)r)r r )r6rrrrrdszautoupdate..r~Nr-c s4g|],\}}r|dkrjt||dqS)rrX)submitr[)r6rWrexer#r~r"rrrds z (frozen)z updating z -> zalready up to date!r2r3)rr rjr cpu_countminmax concurrentfuturesThreadPoolExecutorri as_completedresultr@rZ write_linerrrrr|)r}r"r#r~rchangedZretvZ config_reposr\rfuturerWrYrZrHZnew_smsgrrr autoupdates@     $ r)F)rr-), __future__rconcurrent.futuresros.pathr=rer9typingrrrZpre_commit.constants constantsr<Z pre_commitrrrZpre_commit.clientlibr r r r r Z"pre_commit.commands.migrate_configrZpre_commit.utilrrrZpre_commit.yamlrrr RuntimeErrorr@rUr[compilerarmr|rrrrrsB                   9