(hook: Hook)
| 63 | |
| 64 | |
| 65 | def _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 | |
| 109 | def _hook( |
no test coverage detected