|
3 | 3 | from pre_commit.languages import helpers |
4 | 4 | from pre_commit.languages import python |
5 | 5 | from pre_commit.prefixed_command_runner import CalledProcessError |
| 6 | +from pre_commit.util import clean_path_on_failure |
6 | 7 |
|
7 | 8 |
|
8 | 9 | NODE_ENV = 'node_env' |
@@ -30,22 +31,30 @@ def install_environment(repo_cmd_runner): |
30 | 31 | if repo_cmd_runner.exists(NODE_ENV): |
31 | 32 | return |
32 | 33 |
|
33 | | - repo_cmd_runner.run(['virtualenv', '{{prefix}}{0}'.format(python.PY_ENV)]) |
34 | | - |
35 | | - with python.in_env(repo_cmd_runner) as python_env: |
36 | | - python_env.run('pip install nodeenv') |
37 | | - |
38 | | - # Try and use the system level node executable first |
39 | | - try: |
40 | | - python_env.run('nodeenv -n system {{prefix}}{0}'.format(NODE_ENV)) |
41 | | - except CalledProcessError: |
42 | | - # TODO: log failure here |
43 | | - # cleanup |
44 | | - # TODO: local.path(NODE_ENV).delete() |
45 | | - python_env.run('nodeenv --jobs 4 {{prefix}}{0}'.format(NODE_ENV)) |
| 34 | + with clean_path_on_failure(repo_cmd_runner.path(python.PY_ENV)): |
| 35 | + repo_cmd_runner.run( |
| 36 | + ['virtualenv', '{{prefix}}{0}'.format(python.PY_ENV)], |
| 37 | + ) |
46 | 38 |
|
47 | | - with in_env(repo_cmd_runner) as node_env: |
48 | | - node_env.run('cd {prefix} && npm install -g') |
| 39 | + with python.in_env(repo_cmd_runner) as python_env: |
| 40 | + python_env.run('pip install nodeenv') |
| 41 | + |
| 42 | + with clean_path_on_failure(repo_cmd_runner.path(NODE_ENV)): |
| 43 | + # Try and use the system level node executable first |
| 44 | + try: |
| 45 | + python_env.run( |
| 46 | + 'nodeenv -n system {{prefix}}{0}'.format(NODE_ENV), |
| 47 | + ) |
| 48 | + except CalledProcessError: |
| 49 | + # TODO: log failure here |
| 50 | + # cleanup |
| 51 | + # TODO: local.path(NODE_ENV).delete() |
| 52 | + python_env.run( |
| 53 | + 'nodeenv --jobs 4 {{prefix}}{0}'.format(NODE_ENV), |
| 54 | + ) |
| 55 | + |
| 56 | + with in_env(repo_cmd_runner) as node_env: |
| 57 | + node_env.run('cd {prefix} && npm install -g') |
49 | 58 |
|
50 | 59 |
|
51 | 60 | def run_hook(repo_cmd_runner, hook, file_args): |
|
0 commit comments