Skip to content

some Python nits and fixes #33141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ def run(args, verbose=False):

def stage0_data(rust_root):
nightlies = os.path.join(rust_root, "src/stage0.txt")
data = {}
with open(nightlies, 'r') as nightlies:
data = {}
for line in nightlies.read().split("\n"):
for line in nightlies:
line = line.rstrip() # Strip newline character, '\n'
if line.startswith("#") or line == '':
continue
a, b = line.split(": ", 1)
data[a] = b
return data
return data
Copy link
Contributor

@Stebalien Stebalien Apr 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, you can do this with a single comprehension:

with open(nightlies, 'r') as nightlies:
    return dict(
        line.split(": ", 1)
        for line in nightlies
        if line.strip() and not line.startswith('#')
    )

However, this is obviously a matter of style (and your way is probably more readable to someone who doesn't do a lot of functional programming).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting approach. Looks elegant.


class RustBuild:
def download_stage0(self):
Expand Down Expand Up @@ -219,7 +220,7 @@ def build_bootstrap(self):
env)

def run(self, args, env):
proc = subprocess.Popen(args, env = env)
proc = subprocess.Popen(args, env=env)
ret = proc.wait()
if ret != 0:
sys.exit(ret)
Expand All @@ -234,20 +235,19 @@ def build_triple(self):
try:
ostype = subprocess.check_output(['uname', '-s']).strip()
cputype = subprocess.check_output(['uname', '-m']).strip()
except FileNotFoundError:
except subprocess.CalledProcessError:
if sys.platform == 'win32':
return 'x86_64-pc-windows-msvc'
else:
err = "uname not found"
if self.verbose:
raise Exception(err)
sys.exit(err)
err = "uname not found"
if self.verbose:
raise Exception(err)
sys.exit(err)

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

# The goal here is to come up with the same triple as LLVM would,
Expand Down
12 changes: 4 additions & 8 deletions src/etc/get-stage0.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@
# except according to those terms.

import os
import shutil
import sys
import tarfile

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

import bootstrap

def main(argv):
def main(triple):
src_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
triple = argv[1]
data = bootstrap.stage0_data(src_root)

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

filename_base = 'rustc-' + channel + '-' + triple
filename = filename_base + '.tar.gz'
url = 'https://static.rust-lang.org/dist/' + date + '/' + filename
filename = 'rustc-{}-{}.tar.gz'.format(channel, triple)
url = 'https://static.rust-lang.org/dist/{}/{}'.format(date, filename)
dst = dl_dir + '/' + filename
if not os.path.exists(dst):
bootstrap.get(url, dst)
Expand All @@ -48,4 +44,4 @@ def main(argv):
bootstrap.unpack(dst, stage0_dst, match='rustc', verbose=True)

if __name__ == '__main__':
main(sys.argv)
main(sys.argv[1])