-
Notifications
You must be signed in to change notification settings - Fork 10
/
install_rust.py
49 lines (35 loc) · 1.31 KB
/
install_rust.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
sys.dont_write_bytecode = True
import os
import subprocess
import pathlib
import urllib
import urllib.request
def download_file(url, dest):
req = urllib.request.Request(url, method='GET')
resp = urllib.request.urlopen(req, timeout=120)
data = resp.read()
with open(dest, 'wb') as dest_file:
dest_file.write(data)
def cargo_path():
return pathlib.Path.home() / '.cargo' / 'bin'
def export_cargo_to_path():
"""Add ``cargo`` to the PATH, assuming it's installed."""
os.environ['PATH'] = str(cargo_path()) + os.pathsep + os.environ['PATH']
if sys.platform in ('linux', 'darwin'):
def install_rust():
if not cargo_path().exists():
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
download_file('https://sh.rustup.rs', 'rustup-init.sh')
subprocess.check_call(['sh', 'rustup-init.sh',
'-y', '--profile', 'minimal'])
elif sys.platform == 'win32':
def install_rust():
if not cargo_path().exists():
download_file('https://win.rustup.rs/x86_64', 'rustup-init.exe')
subprocess.check_call(['rustup-init.exe',
'-y', '--profile', 'minimal'])
else:
raise NotImplementedError(f'Unsupported platform: {sys.platform}')
if __name__ == '__main__':
install_rust()