MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / install_rust_with_toolchain

Function install_rust_with_toolchain

pre_commit/languages/rust.py:83–110  ·  view source on GitHub ↗
(toolchain: str, envdir: str)

Source from the content-addressed store, hash-verified

81
82
83def install_rust_with_toolchain(toolchain: str, envdir: str) -> None:
84 with tempfile.TemporaryDirectory() as rustup_dir:
85 with envcontext((('CARGO_HOME', envdir), ('RUSTUP_HOME', rustup_dir))):
86 # acquire `rustup` if not present
87 if parse_shebang.find_executable('rustup') is None:
88 # We did not detect rustup and need to download it first.
89 if sys.platform == 'win32': # pragma: win32 cover
90 url = 'https://win.rustup.rs/x86_64'
91 else: # pragma: win32 no cover
92 url = 'https://sh.rustup.rs'
93
94 resp = urllib.request.urlopen(url)
95
96 rustup_init = os.path.join(rustup_dir, win_exe('rustup-init'))
97 with open(rustup_init, 'wb') as f:
98 shutil.copyfileobj(resp, f)
99 make_executable(rustup_init)
100
101 # install rustup into `$CARGO_HOME/bin`
102 cmd_output_b(
103 rustup_init, '-y', '--quiet', '--no-modify-path',
104 '--default-toolchain', 'none',
105 )
106
107 cmd_output_b(
108 'rustup', 'toolchain', 'install', '--no-self-update',
109 toolchain,
110 )
111
112
113def install_environment(

Callers 1

install_environmentFunction · 0.85

Calls 4

envcontextFunction · 0.90
win_exeFunction · 0.90
make_executableFunction · 0.90
cmd_output_bFunction · 0.90

Tested by

no test coverage detected