@@ -28,45 +28,44 @@ def install_environment(
2828 helpers .assert_version_default ('coursier' , version )
2929
3030 # Support both possible executable names (either "cs" or "coursier")
31- executable = find_executable ('cs' ) or find_executable ('coursier' )
32- if executable is None :
31+ cs = find_executable ('cs' ) or find_executable ('coursier' )
32+ if cs is None :
3333 raise AssertionError (
3434 'pre-commit requires system-installed "cs" or "coursier" '
3535 'executables in the application search path' ,
3636 )
3737
3838 envdir = helpers .environment_dir (prefix , ENVIRONMENT_DIR , version )
39- channel = prefix .path ('.pre-commit-channel' )
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' ,
39+
40+ def _install (* opts : str ) -> None :
41+ assert cs is not None
42+ helpers .run_setup_cmd (prefix , (cs , 'fetch' , * opts ))
43+ helpers .run_setup_cmd (prefix , (cs , 'install' , '--dir' , envdir , * opts ))
44+
45+ with in_env (prefix , version ):
46+ channel = prefix .path ('.pre-commit-channel' )
47+ if os .path .isdir (channel ):
48+ for app_descriptor in os .listdir (channel ):
49+ _ , app_file = os .path .split (app_descriptor )
50+ app , _ = os .path .splitext (app_file )
51+ _install (
4952 '--default-channels=false' ,
5053 '--channel' , channel ,
51- '--dir' , envdir ,
5254 app ,
53- ),
55+ )
56+ elif not additional_dependencies :
57+ raise FatalError (
58+ 'expected .pre-commit-channel dir or additional_dependencies' ,
5459 )
55- elif not additional_dependencies :
56- raise FatalError (
57- 'expected .pre-commit-channel dir or additional_dependencies' ,
58- )
5960
60- if additional_dependencies :
61- install_cmd = (
62- executable , 'install' , '--dir' , envdir , * additional_dependencies ,
63- )
64- helpers .run_setup_cmd (prefix , install_cmd )
61+ if additional_dependencies :
62+ _install (* additional_dependencies )
6563
6664
6765def get_env_patch (target_dir : str ) -> PatchesT :
6866 return (
6967 ('PATH' , (target_dir , os .pathsep , Var ('PATH' ))),
68+ ('COURSIER_CACHE' , os .path .join (target_dir , '.cs-cache' )),
7069 )
7170
7271
0 commit comments