Skip to content

Commit 7de2e6d

Browse files
committed
Auto merge of #34020 - Stebalien:py-cleanup, r=alexcrichton
Avoid repeated string concatenation in python While performance isn't really critical here, IMO, format strings are more readable. /end nit
2 parents 1ceaa86 + cde72b0 commit 7de2e6d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/bootstrap/bootstrap.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get(url, path, verbose=False):
3030
download(sha_path, sha_url, verbose)
3131
download(temp_path, url, verbose)
3232
verify(temp_path, sha_path, verbose)
33-
print("moving " + temp_path + " to " + path)
33+
print("moving {} to {}".format(temp_path, path))
3434
shutil.move(temp_path, path)
3535
finally:
3636
delete_if_present(sha_path)
@@ -44,7 +44,7 @@ def delete_if_present(path):
4444

4545

4646
def download(path, url, verbose):
47-
print("downloading " + url + " to " + path)
47+
print("downloading {} to {}".format(url, path))
4848
# see http://serverfault.com/questions/301128/how-to-download
4949
if sys.platform == 'win32':
5050
run(["PowerShell.exe", "/nologo", "-Command",
@@ -133,32 +133,32 @@ def download_stage0(self):
133133
if os.path.exists(self.bin_root()):
134134
shutil.rmtree(self.bin_root())
135135
channel = self.stage0_rustc_channel()
136-
filename = "rust-std-" + channel + "-" + self.build + ".tar.gz"
136+
filename = "rust-std-{}-{}.tar.gz".format(channel, self.build)
137137
url = "https://static.rust-lang.org/dist/" + self.stage0_rustc_date()
138138
tarball = os.path.join(rustc_cache, filename)
139139
if not os.path.exists(tarball):
140-
get(url + "/" + filename, tarball, verbose=self.verbose)
140+
get("{}/{}".format(url, filename), tarball, verbose=self.verbose)
141141
unpack(tarball, self.bin_root(),
142142
match="rust-std-" + self.build,
143143
verbose=self.verbose)
144144

145-
filename = "rustc-" + channel + "-" + self.build + ".tar.gz"
145+
filename = "rustc-{}-{}.tar.gz".format(channel, self.build)
146146
url = "https://static.rust-lang.org/dist/" + self.stage0_rustc_date()
147147
tarball = os.path.join(rustc_cache, filename)
148148
if not os.path.exists(tarball):
149-
get(url + "/" + filename, tarball, verbose=self.verbose)
149+
get("{}/{}".format(url, filename), tarball, verbose=self.verbose)
150150
unpack(tarball, self.bin_root(), match="rustc", verbose=self.verbose)
151151
with open(self.rustc_stamp(), 'w') as f:
152152
f.write(self.stage0_rustc_date())
153153

154154
if self.cargo().startswith(self.bin_root()) and \
155155
(not os.path.exists(self.cargo()) or self.cargo_out_of_date()):
156156
channel = self.stage0_cargo_channel()
157-
filename = "cargo-" + channel + "-" + self.build + ".tar.gz"
157+
filename = "cargo-{}-{}.tar.gz".format(channel, self.build)
158158
url = "https://static.rust-lang.org/cargo-dist/" + self.stage0_cargo_date()
159159
tarball = os.path.join(cargo_cache, filename)
160160
if not os.path.exists(tarball):
161-
get(url + "/" + filename, tarball, verbose=self.verbose)
161+
get("{}/{}".format(url, filename), tarball, verbose=self.verbose)
162162
unpack(tarball, self.bin_root(), match="cargo", verbose=self.verbose)
163163
with open(self.cargo_stamp(), 'w') as f:
164164
f.write(self.stage0_cargo_date())
@@ -335,7 +335,7 @@ def build_triple(self):
335335
raise ValueError(err)
336336
sys.exit(err)
337337

338-
return cputype + '-' + ostype
338+
return "{}-{}".format(cputype, ostype)
339339

340340
def main():
341341
parser = argparse.ArgumentParser(description='Build rust')

0 commit comments

Comments
 (0)