Skip to content

Commit 8d545ad

Browse files
committed
rust: Remove TOOLCHAIN_FROM_VERSION mapping
1 parent 9abf0d2 commit 8d545ad

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

pre_commit/languages/rust.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
from pre_commit.util import win_exe
2727

2828
ENVIRONMENT_DIR = 'rustenv'
29-
TOOLCHAIN_FROM_VERSION = {
30-
'system': None,
31-
C.DEFAULT: 'stable',
32-
}
3329

3430
health_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+
5161
def _envdir(prefix: Prefix, version: str) -> str:
5262
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
5363
return prefix.path(directory)
5464

5565

5666
def 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

Comments
 (0)