Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0920cb3

Browse files
committed
simplify install state
the additional bookkeeping has been unnecessary since b827694 unfortunately this will cause a rebuild of all hooks in order to be forward/backward compatible -- shrugs
1 parent c787efd commit 0920cb3

2 files changed

Lines changed: 4 additions & 25 deletions

File tree

pre_commit/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
CONFIG_FILE = '.pre-commit-config.yaml'
66
MANIFEST_FILE = '.pre-commit-hooks.yaml'
77

8-
# Bump when installation changes in a backwards / forwards incompatible way
9-
INSTALLED_STATE_VERSION = '1'
108
# Bump when modifying `empty_template`
119
LOCAL_REPO_VERSION = '1'
1210

pre_commit/repository.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import json
43
import logging
54
import os
65
from typing import Any
@@ -23,21 +22,8 @@
2322
logger = logging.getLogger('pre_commit')
2423

2524

26-
def _state(additional_deps: Sequence[str]) -> object:
27-
return {'additional_dependencies': sorted(additional_deps)}
28-
29-
3025
def _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

4329
def _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

9980
def _hook(

0 commit comments

Comments
 (0)