Skip to content

Commit 433d70c

Browse files
committed
Auto merge of #33141 - tshepang:python-love, r=brson
some Python nits and fixes
2 parents ad5fbaf + a422b7e commit 433d70c

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/bootstrap/bootstrap.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ def run(args, verbose=False):
108108

109109
def stage0_data(rust_root):
110110
nightlies = os.path.join(rust_root, "src/stage0.txt")
111+
data = {}
111112
with open(nightlies, 'r') as nightlies:
112-
data = {}
113-
for line in nightlies.read().split("\n"):
113+
for line in nightlies:
114+
line = line.rstrip() # Strip newline character, '\n'
114115
if line.startswith("#") or line == '':
115116
continue
116117
a, b = line.split(": ", 1)
117118
data[a] = b
118-
return data
119+
return data
119120

120121
class RustBuild:
121122
def download_stage0(self):
@@ -246,7 +247,7 @@ def build_bootstrap(self):
246247
env)
247248

248249
def run(self, args, env):
249-
proc = subprocess.Popen(args, env = env)
250+
proc = subprocess.Popen(args, env=env)
250251
ret = proc.wait()
251252
if ret != 0:
252253
sys.exit(ret)
@@ -261,20 +262,19 @@ def build_triple(self):
261262
try:
262263
ostype = subprocess.check_output(['uname', '-s']).strip()
263264
cputype = subprocess.check_output(['uname', '-m']).strip()
264-
except FileNotFoundError:
265+
except subprocess.CalledProcessError:
265266
if sys.platform == 'win32':
266267
return 'x86_64-pc-windows-msvc'
267-
else:
268-
err = "uname not found"
269-
if self.verbose:
270-
raise Exception(err)
271-
sys.exit(err)
268+
err = "uname not found"
269+
if self.verbose:
270+
raise Exception(err)
271+
sys.exit(err)
272272

273273
# Darwin's `uname -s` lies and always returns i386. We have to use
274274
# sysctl instead.
275275
if ostype == 'Darwin' and cputype == 'i686':
276276
sysctl = subprocess.check_output(['sysctl', 'hw.optional.x86_64'])
277-
if sysctl.contains(': 1'):
277+
if ': 1' in sysctl:
278278
cputype = 'x86_64'
279279

280280
# The goal here is to come up with the same triple as LLVM would,

src/etc/get-stage0.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@
1111
# except according to those terms.
1212

1313
import os
14-
import shutil
1514
import sys
16-
import tarfile
1715

1816
path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../bootstrap"))
1917
sys.path.append(path)
2018

2119
import bootstrap
2220

23-
def main(argv):
21+
def main(triple):
2422
src_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
25-
triple = argv[1]
2623
data = bootstrap.stage0_data(src_root)
2724

2825
channel, date = data['rustc'].split('-', 1)
@@ -31,9 +28,8 @@ def main(argv):
3128
if not os.path.exists(dl_dir):
3229
os.makedirs(dl_dir)
3330

34-
filename_base = 'rustc-' + channel + '-' + triple
35-
filename = filename_base + '.tar.gz'
36-
url = 'https://static.rust-lang.org/dist/' + date + '/' + filename
31+
filename = 'rustc-{}-{}.tar.gz'.format(channel, triple)
32+
url = 'https://static.rust-lang.org/dist/{}/{}'.format(date, filename)
3733
dst = dl_dir + '/' + filename
3834
if os.path.exists(dst):
3935
os.unlink(dst)
@@ -49,4 +45,4 @@ def main(argv):
4945
bootstrap.unpack(dst, stage0_dst, match='rustc', verbose=True)
5046

5147
if __name__ == '__main__':
52-
main(sys.argv)
48+
main(sys.argv[1])

0 commit comments

Comments
 (0)