Skip to content

Commit

Permalink
rust: Remove TOOLCHAIN_FROM_VERSION mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Oct 4, 2022
1 parent 9abf0d2 commit 8d545ad
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions pre_commit/languages/rust.py
Expand Up @@ -26,10 +26,6 @@
from pre_commit.util import win_exe

ENVIRONMENT_DIR = 'rustenv'
TOOLCHAIN_FROM_VERSION = {
'system': None,
C.DEFAULT: 'stable',
}

health_check = helpers.basic_health_check

Expand All @@ -48,19 +44,35 @@ def get_default_version() -> str:
return C.DEFAULT


def _rust_toolchain(language_version: str) -> str:
'''Transform the language version into a rust toolchain version.'''
if language_version == 'system':
raise AssertionError(
'system rust install was requested, but pre-commit to set '
'a toolchain version -- this is probably a bug',
)

if language_version == C.DEFAULT:
return 'stable'

return language_version


def _envdir(prefix: Prefix, version: str) -> str:
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
return prefix.path(directory)


def get_env_patch(target_dir: str, version: str) -> PatchesT:
toolchain = TOOLCHAIN_FROM_VERSION.get(version, version)
return (
('CARGO_HOME', target_dir),
('PATH', (os.path.join(target_dir, 'bin'), os.pathsep, Var('PATH'))),
# Only set RUSTUP_TOOLCHAIN if we don't want use the system's default
# toolchain
*((('RUSTUP_TOOLCHAIN', toolchain),) if toolchain else ()),
*(
(('RUSTUP_TOOLCHAIN', _rust_toolchain(version)),)
if version != 'system' else ()
),
)


Expand Down Expand Up @@ -171,9 +183,8 @@ def install_environment(
packages_to_install.add((package,))

with in_env(prefix, version):
toolchain = TOOLCHAIN_FROM_VERSION.get(version, version)
if toolchain is not None:
install_rust_with_toolchain(toolchain)
if version != 'system':
install_rust_with_toolchain(_rust_toolchain(version))

for args in packages_to_install:
cmd_output_b(
Expand Down

0 comments on commit 8d545ad

Please sign in to comment.