MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / _hook_install

Function _hook_install

pre_commit/repository.py:65–106  ·  view source on GitHub ↗
(hook: Hook)

Source from the content-addressed store, hash-verified

63
64
65def _hook_install(hook: Hook) -> None:
66 logger.info(f'Installing environment for {hook.src}.')
67 logger.info('Once installed this environment will be reused.')
68 logger.info('This may take a few minutes...')
69
70 lang = languages[hook.language]
71 assert lang.ENVIRONMENT_DIR is not None
72
73 venv = environment_dir(
74 hook.prefix,
75 lang.ENVIRONMENT_DIR,
76 hook.language_version,
77 )
78
79 # There's potentially incomplete cleanup from previous runs
80 # Clean it up!
81 if os.path.exists(venv):
82 rmtree(venv)
83
84 with clean_path_on_failure(venv):
85 lang.install_environment(
86 hook.prefix, hook.language_version, hook.additional_dependencies,
87 )
88 health_error = lang.health_check(hook.prefix, hook.language_version)
89 if health_error:
90 raise AssertionError(
91 f'BUG: expected environment for {hook.language} to be healthy '
92 f'immediately after install, please open an issue describing '
93 f'your environment\n\n'
94 f'more info:\n\n{health_error}',
95 )
96
97 # TODO: remove v1 state writing, no longer needed after pre-commit 3.0
98 # Write our state to indicate we're installed
99 state_filename = _state_filename_v1(venv)
100 staging = f'{state_filename}staging'
101 with open(staging, 'w') as state_file:
102 state_file.write(json.dumps(_state(hook.additional_dependencies)))
103 # Move the file into place atomically to indicate we've installed
104 os.replace(staging, state_filename)
105
106 open(_state_filename_v2(venv), 'a+').close()
107
108
109def _hook(

Callers 1

install_hook_envsFunction · 0.85

Calls 9

environment_dirFunction · 0.90
rmtreeFunction · 0.90
clean_path_on_failureFunction · 0.90
_state_filename_v1Function · 0.85
_stateFunction · 0.85
_state_filename_v2Function · 0.85
existsMethod · 0.80
install_environmentMethod · 0.80
health_checkMethod · 0.80

Tested by

no test coverage detected