U e)$@sddlmZddlZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddl m ZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZed ZddddZdZdddddZGdddZdS)) annotationsN)Callable) Generator)Sequence) file_lock)git)CalledProcessError)clean_path_on_failure cmd_output_b) resource_text)rmtree pre_commitstrreturncCs:tjdp,tjtjdp(tjdd}tj|S)a7Returns the default directory for the Store. This is intentionally underscored to indicate that `Store.get_default_directory` is the intended way to get this information. This is also done so `Store.get_default_directory` can be mocked in tests and `_get_default_directory` can be tested. ZPRE_COMMIT_HOMEXDG_CACHE_HOMEz~/.cachez pre-commit)osenvirongetpathjoin expanduserrealpath)retr>/opt/hc_python/lib/python3.8/site-packages/pre_commit/store.py_get_default_directorys r)z Cargo.tomlzmain.gozgo.modzmain.rsz .npmignorez package.jsonz!pre-commit-package-dev-1.rockspecz&pre_commit_placeholder_package.gemspeczsetup.pyzenvironment.ymlz Makefile.PLz pubspec.yamlz renv.lockzrenv/activate.Rzrenv/LICENSE.renvNone directoryrc CsvtD]l}tj|\}}td|}tj||}tj||}tj|ddt|d}||W5QRXqdS)NZempty_template_Texist_okw) _LOCAL_RESOURCESrrsplitr rmakedirsopenwrite)r resourceZresource_dirnameZresource_basenamecontents target_dirZ target_filefrrr_make_local_repo0s r-c@s(eZdZeeZd8dddddZejddd d Z ejd9dd d d dZ e ddddddZ ddddddddZ ddddddZddddddZd:dddddd d!Zddd"d#d$Zd%dd&d'd(Zddd)d*d+Zd,dd-d.Zd,dd/d0d1Zd2dd3d4Zddddd5d6d7ZdS);StoreN str | Nonerrc Cs(|p t|_tj|jd|_tj|jo>t|jtj  |_ tj|jstj |jddt tj|jdd}| dW5QRXtj|jrdS|xtj|jrW5QRdStj|jd\}}t||j|d}|d ||W5QRXt||jW5QRXdS) Nzdb.dbTr!ZREADMEr#zmThis directory is maintained by the pre-commit project. Learn more: https://github.com/pre-commit/pre-commit )dir)db_pathzuCREATE TABLE repos ( repo TEXT NOT NULL, ref TEXT NOT NULL, path TEXT NOT NULL, PRIMARY KEY (repo, ref));)r.get_default_directoryr rrrr1existsaccessW_OKreadonlyr&r'r(exclusive_locktempfilemkstempcloseconnect executescript_create_config_tablereplace)selfr r,fdZtmpfiledbrrr__init__>s0  zStore.__init__zGenerator[(None, None, None)]rc cs<dddd}ttj|jd| dVW5QRXdS)NrrcSstddS)NzLocking pre-commit directory)loggerinforrrr blocked_cbisz(Store.exclusive_lock..blocked_cbz.lock)rlockrrrr )r?rErrrr7gszStore.exclusive_lockz)Generator[sqlite3.Connection, None, None])r1rc cs@|p|j}tt|}| |VW5QRXW5QRXdS)N)r1 contextlibclosingsqlite3r;)r?r1rArrrr;os z Store.connectrz Sequence[str])repodepsrcCs |r|dd|S|SdS)N:,)r)clsrJrKrrr db_repo_name}szStore.db_repo_namezCallable[[str], None])rJrefrK make_strategyrc s|ddfdd }|}|r0|S|}|rT|W5QRStddtjdjd}t|||W5QRX}| d |gW5QRXW5QRX|S) Nr/rc sD2}|df}|r*|dndW5QRSQRXdS)Nz1SELECT path FROM repos WHERE repo = ? AND ref = ?r)r;executeZfetchone)rAresultrPrJr?rr _get_results  z$Store._new_repo.._get_resultzInitializing environment for .rJ)prefixr0z4INSERT INTO repos (repo, ref, path) VALUES (?, ?, ?)) rOr7rCrDr8mkdtempr r r;rR) r?rJrPrKrQrUrSr rArrTr _new_repos&     zStore._new_repozCallable[(Ellipsis, None)])rPgit_cmdrcCs(|ddd|d||ddddd S) z.clone_strategy.._git_cmd)rZ init_repoZ no_git_envrdrrb)r rirTrhrclone_strategys z#Store.clone..clone_strategy)rY)r?rJrPrKrjrrTrclones z Store.clone)rKrcCs|dtj|tS)Nlocal)rYCZLOCAL_REPO_VERSIONr-)r?rKrrr make_locals zStore.make_localzsqlite3.Connection)rArcCs|ddS)NzQCREATE TABLE IF NOT EXISTS configs ( path TEXT NOT NULL, PRIMARY KEY (path));)r<r?rArrrr=szStore._create_config_table)rrc CsV|jr dStj|}tj|s&dS|}|||d|fW5QRXdS)Nz(INSERT OR IGNORE INTO configs VALUES (?))r6rrrr3r;r=rR)r?rrArrrmark_config_useds    zStore.mark_config_usedz list[str]c CsF|4}|||d}dd|DW5QRSQRXdS)NzSELECT path FROM configscSsg|] \}|qSrr.0rrrr sz,Store.select_all_configs..)r;r=rRfetchall)r?rArowsrrrselect_all_configss  zStore.select_all_configs)configsrc Cs2| }dd|D}|d|W5QRXdS)NcSsg|] }|fqSrrrqrrrrssz(Store.delete_configs..z"DELETE FROM configs WHERE path = ?)r;Z executemany)r?rwrArurrrdelete_configss zStore.delete_configszlist[tuple[str, str, str]]c Cs.|}|dW5QRSQRXdS)Nz!SELECT repo, ref, path from repos)r;rRrtrorrrselect_all_reposs zStore.select_all_repos)rOrPrrc Cs0|}|d||fW5QRXt|dS)Nz,DELETE FROM repos WHERE repo = ? and ref = ?)r;rRr )r?rOrPrrArrr delete_repos  zStore.delete_repo)N)N)r)__name__ __module__ __qualname__ staticmethodrr2rBrGcontextmanagerr7r; classmethodrOrYrbrdrkrnr=rprvrxryrzrrrrr.;s() )  r.) __future__rrGloggingos.pathrrIr8typingrrrZpre_commit.constants constantsrmrrrZpre_commit.utilrr r r r getLoggerrCrr$r-r.rrrrs*