11from __future__ import annotations
22
33import contextlib
4- import os
4+ import os . path
55from typing import Generator
66from typing import Sequence
77
88from pre_commit .envcontext import envcontext
99from pre_commit .envcontext import PatchesT
1010from pre_commit .envcontext import Var
11+ from pre_commit .errors import FatalError
1112from pre_commit .languages import helpers
1213from pre_commit .parse_shebang import find_executable
1314from pre_commit .prefix import Prefix
@@ -23,9 +24,8 @@ def install_environment(
2324 prefix : Prefix ,
2425 version : str ,
2526 additional_dependencies : Sequence [str ],
26- ) -> None : # pragma: win32 no cover
27+ ) -> None :
2728 helpers .assert_version_default ('coursier' , version )
28- helpers .assert_no_additional_deps ('coursier' , additional_dependencies )
2929
3030 # Support both possible executable names (either "cs" or "coursier")
3131 executable = find_executable ('cs' ) or find_executable ('coursier' )
@@ -37,29 +37,40 @@ def install_environment(
3737
3838 envdir = helpers .environment_dir (prefix , ENVIRONMENT_DIR , version )
3939 channel = prefix .path ('.pre-commit-channel' )
40- for app_descriptor in os .listdir (channel ):
41- _ , app_file = os .path .split (app_descriptor )
42- app , _ = os .path .splitext (app_file )
43- helpers .run_setup_cmd (
44- prefix ,
45- (
46- executable ,
47- 'install' ,
48- '--default-channels=false' ,
49- f'--channel={ channel } ' ,
50- app ,
51- f'--dir={ envdir } ' ,
52- ),
40+ if os .path .isdir (channel ):
41+ for app_descriptor in os .listdir (channel ):
42+ _ , app_file = os .path .split (app_descriptor )
43+ app , _ = os .path .splitext (app_file )
44+ helpers .run_setup_cmd (
45+ prefix ,
46+ (
47+ executable ,
48+ 'install' ,
49+ '--default-channels=false' ,
50+ '--channel' , channel ,
51+ '--dir' , envdir ,
52+ app ,
53+ ),
54+ )
55+ elif not additional_dependencies :
56+ raise FatalError (
57+ 'expected .pre-commit-channel dir or additional_dependencies' ,
5358 )
5459
60+ if additional_dependencies :
61+ install_cmd = (
62+ executable , 'install' , '--dir' , envdir , * additional_dependencies ,
63+ )
64+ helpers .run_setup_cmd (prefix , install_cmd )
65+
5566
56- def get_env_patch (target_dir : str ) -> PatchesT : # pragma: win32 no cover
67+ def get_env_patch (target_dir : str ) -> PatchesT :
5768 return (
5869 ('PATH' , (target_dir , os .pathsep , Var ('PATH' ))),
5970 )
6071
6172
62- @contextlib .contextmanager # pragma: win32 no cover
73+ @contextlib .contextmanager
6374def in_env (prefix : Prefix , version : str ) -> Generator [None , None , None ]:
6475 envdir = helpers .environment_dir (prefix , ENVIRONMENT_DIR , version )
6576 with envcontext (get_env_patch (envdir )):
0 commit comments