11from __future__ import annotations
22
3- import json
43import logging
54import os
65from typing import Any
2322logger = logging .getLogger ('pre_commit' )
2423
2524
26- def _state (additional_deps : Sequence [str ]) -> object :
27- return {'additional_dependencies' : sorted (additional_deps )}
28-
29-
3025def _state_filename (venv : str ) -> str :
31- return os .path .join (venv , f'.install_state_v{ C .INSTALLED_STATE_VERSION } ' )
32-
33-
34- def _read_state (venv : str ) -> object | None :
35- filename = _state_filename (venv )
36- if not os .path .exists (filename ):
37- return None
38- else :
39- with open (filename ) as f :
40- return json .load (f )
26+ return os .path .join (venv , '.install_state_v2' )
4127
4228
4329def _hook_installed (hook : Hook ) -> bool :
@@ -51,7 +37,7 @@ def _hook_installed(hook: Hook) -> bool:
5137 hook .language_version ,
5238 )
5339 return (
54- _read_state ( venv ) == _state ( hook . additional_dependencies ) and
40+ os . path . exists ( _state_filename ( venv )) and
5541 not lang .health_check (hook .prefix , hook .language_version )
5642 )
5743
@@ -87,13 +73,8 @@ def _hook_install(hook: Hook) -> None:
8773 f'your environment\n \n '
8874 f'more info:\n \n { health_error } ' ,
8975 )
90- # Write our state to indicate we're installed
91- state_filename = _state_filename (venv )
92- staging = f'{ state_filename } staging'
93- with open (staging , 'w' ) as state_file :
94- state_file .write (json .dumps (_state (hook .additional_dependencies )))
95- # Move the file into place atomically to indicate we've installed
96- os .replace (staging , state_filename )
76+ # touch state file to indicate we're installed
77+ open (_state_filename (venv ), 'a+' ).close ()
9778
9879
9980def _hook (
0 commit comments