2626from pre_commit .util import win_exe
2727
2828ENVIRONMENT_DIR = 'rustenv'
29- TOOLCHAIN_FROM_VERSION = {
30- 'system' : None ,
31- C .DEFAULT : 'stable' ,
32- }
3329
3430health_check = helpers .basic_health_check
3531
@@ -48,19 +44,35 @@ def get_default_version() -> str:
4844 return C .DEFAULT
4945
5046
47+ def _rust_toolchain (language_version : str ) -> str :
48+ '''Transform the language version into a rust toolchain version.'''
49+ if language_version == 'system' :
50+ raise AssertionError (
51+ 'system rust install was requested, but pre-commit to set '
52+ 'a toolchain version -- this is probably a bug' ,
53+ )
54+
55+ if language_version == C .DEFAULT :
56+ return 'stable'
57+
58+ return language_version
59+
60+
5161def _envdir (prefix : Prefix , version : str ) -> str :
5262 directory = helpers .environment_dir (ENVIRONMENT_DIR , version )
5363 return prefix .path (directory )
5464
5565
5666def get_env_patch (target_dir : str , version : str ) -> PatchesT :
57- toolchain = TOOLCHAIN_FROM_VERSION .get (version , version )
5867 return (
5968 ('CARGO_HOME' , target_dir ),
6069 ('PATH' , (os .path .join (target_dir , 'bin' ), os .pathsep , Var ('PATH' ))),
6170 # Only set RUSTUP_TOOLCHAIN if we don't want use the system's default
6271 # toolchain
63- * ((('RUSTUP_TOOLCHAIN' , toolchain ),) if toolchain else ()),
72+ * (
73+ (('RUSTUP_TOOLCHAIN' , _rust_toolchain (version )),)
74+ if version != 'system' else ()
75+ ),
6476 )
6577
6678
@@ -171,9 +183,8 @@ def install_environment(
171183 packages_to_install .add ((package ,))
172184
173185 with in_env (prefix , version ):
174- toolchain = TOOLCHAIN_FROM_VERSION .get (version , version )
175- if toolchain is not None :
176- install_rust_with_toolchain (toolchain )
186+ if version != 'system' :
187+ install_rust_with_toolchain (_rust_toolchain (version ))
177188
178189 for args in packages_to_install :
179190 cmd_output_b (
0 commit comments