Skip to content
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

Python script PEP8 style guide space formatting and minor Python source cleanup #68947

Merged
merged 14 commits into from
Feb 12, 2020
Merged
9 changes: 4 additions & 5 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _download(path, url, probably_big, verbose, exception):
option = "-s"
run(["curl", option,
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
"--retry", "3", "-Sf", "-o", path, url],
verbose=verbose,
exception=exception)
Expand Down Expand Up @@ -332,7 +332,6 @@ def __init__(self):
self.use_vendored_sources = ''
self.verbose = False


def download_stage0(self):
"""Fetch the build system for Rust, written in Rust

Expand All @@ -351,7 +350,7 @@ def support_xz():
try:
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_path = temp_file.name
with tarfile.open(temp_path, "w:xz") as tar:
with tarfile.open(temp_path, "w:xz"):
pass
return True
except tarfile.CompressionError:
Expand Down Expand Up @@ -825,7 +824,7 @@ def check_vendored_status(self):
if not os.path.exists(vendor_dir):
print('error: vendoring required, but vendor directory does not exist.')
print(' Run `cargo vendor` without sudo to initialize the '
'vendor directory.')
'vendor directory.')
raise Exception("{} not found".format(vendor_dir))

if self.use_vendored_sources:
Expand All @@ -839,7 +838,7 @@ def check_vendored_status(self):
"\n"
"[source.vendored-sources]\n"
"directory = '{}/vendor'\n"
.format(self.rust_root))
.format(self.rust_root))
else:
if os.path.exists('.cargo'):
shutil.rmtree('.cargo')
Expand Down
11 changes: 6 additions & 5 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,12 @@ def set(key, value):


def is_number(value):
try:
float(value)
return True
except ValueError:
return False
try:
float(value)
return True
except ValueError:
return False


# Here we walk through the constructed configuration we have from the parsed
# command line arguments. We then apply each piece of configuration by
Expand Down
6 changes: 3 additions & 3 deletions src/ci/cpu-usage-over-time.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ def idle_since(self, prev):
print('unknown platform', sys.platform)
sys.exit(1)

cur_state = State();
cur_state = State()
print("Time,Idle")
while True:
time.sleep(1);
next_state = State();
time.sleep(1)
next_state = State()
now = datetime.datetime.utcnow().isoformat()
idle = next_state.idle_since(cur_state)
print("%s,%s" % (now, idle))
Expand Down
6 changes: 4 additions & 2 deletions src/etc/debugger_pretty_printers_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def __classify_struct(self):
# REGULAR STRUCT
return TYPE_KIND_REGULAR_STRUCT


def __classify_union(self):
assert self.get_dwarf_type_kind() == DWARF_TYPE_CODE_UNION

Expand All @@ -233,7 +232,6 @@ def __classify_union(self):
else:
return TYPE_KIND_REGULAR_UNION


def __conforms_to_field_layout(self, expected_fields):
actual_fields = self.get_fields()
actual_field_count = len(actual_fields)
Expand Down Expand Up @@ -363,6 +361,7 @@ def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val):
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
return (tail, head, data_ptr, capacity)


def extract_length_and_ptr_from_slice(slice_val):
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)
Expand All @@ -376,8 +375,10 @@ def extract_length_and_ptr_from_slice(slice_val):
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
return (length, data_ptr)


UNQUALIFIED_TYPE_MARKERS = frozenset(["(", "[", "&", "*"])


def extract_type_name(qualified_type_name):
"""Extracts the type name from a fully qualified path"""
if qualified_type_name[0] in UNQUALIFIED_TYPE_MARKERS:
Expand All @@ -393,6 +394,7 @@ def extract_type_name(qualified_type_name):
else:
return qualified_type_name[index + 2:]


try:
compat_str = unicode # Python 2
except NameError:
Expand Down
2 changes: 1 addition & 1 deletion src/etc/dec2flt_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
even larger, and it's already uncomfortably large (6 KiB).
"""
from __future__ import print_function
import sys
from math import ceil, log
from fractions import Fraction
from collections import namedtuple
Expand Down Expand Up @@ -82,6 +81,7 @@ def error(f, e, z):
ulp_err = abs_err / Fraction(2) ** z.exp
return float(ulp_err)


HEADER = """
//! Tables of approximations of powers of ten.
//! DO NOT MODIFY: Generated by `src/etc/dec2flt_table.py`
Expand Down
43 changes: 23 additions & 20 deletions src/etc/gdb_rust_pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
if sys.version_info[0] >= 3:
xrange = range

rust_enabled = 'set language rust' in gdb.execute('complete set language ru', to_string = True)
rust_enabled = 'set language rust' in gdb.execute('complete set language ru', to_string=True)

# The btree pretty-printers fail in a confusing way unless
# https://sourceware.org/bugzilla/show_bug.cgi?id=21763 is fixed.
Expand All @@ -21,9 +21,10 @@
if int(_match.group(1)) > 8 or (int(_match.group(1)) == 8 and int(_match.group(2)) >= 1):
gdb_81 = True

#===============================================================================
# ===============================================================================
# GDB Pretty Printing Module for Rust
#===============================================================================
# ===============================================================================


class GdbType(rustpp.Type):

Expand Down Expand Up @@ -133,39 +134,39 @@ def rust_pretty_printer_lookup_function(gdb_val):

if type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT:
return RustStructPrinter(val,
omit_first_field = False,
omit_type_name = False,
is_tuple_like = False)
omit_first_field=False,
omit_type_name=False,
is_tuple_like=False)

if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
return RustStructPrinter(val,
omit_first_field = True,
omit_type_name = False,
is_tuple_like = False)
omit_first_field=True,
omit_type_name=False,
is_tuple_like=False)

if type_kind == rustpp.TYPE_KIND_STR_SLICE:
return RustStringSlicePrinter(val)

if type_kind == rustpp.TYPE_KIND_TUPLE:
return RustStructPrinter(val,
omit_first_field = False,
omit_type_name = True,
is_tuple_like = True)
omit_first_field=False,
omit_type_name=True,
is_tuple_like=True)

if type_kind == rustpp.TYPE_KIND_TUPLE_STRUCT:
return RustStructPrinter(val,
omit_first_field = False,
omit_type_name = False,
is_tuple_like = True)
omit_first_field=False,
omit_type_name=False,
is_tuple_like=True)

if type_kind == rustpp.TYPE_KIND_CSTYLE_VARIANT:
return RustCStyleVariantPrinter(val.get_child_at_index(0))

if type_kind == rustpp.TYPE_KIND_TUPLE_VARIANT:
return RustStructPrinter(val,
omit_first_field = True,
omit_type_name = False,
is_tuple_like = True)
omit_first_field=True,
omit_type_name=False,
is_tuple_like=True)

if type_kind == rustpp.TYPE_KIND_SINGLETON_ENUM:
variant = get_field_at_index(gdb_val, 0)
Expand All @@ -189,9 +190,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
return None


#=------------------------------------------------------------------------------
# =------------------------------------------------------------------------------
# Pretty Printer Classes
#=------------------------------------------------------------------------------
# =------------------------------------------------------------------------------
class RustEmptyPrinter(object):
def __init__(self, val):
self.__val = val
Expand Down Expand Up @@ -355,6 +356,7 @@ def children_of_node(boxed_node, height, want_values):
else:
yield keys[i]['value']['value']


class RustStdBTreeSetPrinter(object):
def __init__(self, val):
self.__val = val
Expand Down Expand Up @@ -429,6 +431,7 @@ def to_string(self):
def display_hint(self):
return "string"


class RustCStyleVariantPrinter(object):
def __init__(self, val):
assert val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_ENUM
Expand Down
15 changes: 9 additions & 6 deletions src/etc/generate-deriving-span-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
sample usage: src/etc/generate-deriving-span-tests.py
"""

import os, stat
import os
import stat

TEST_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '../test/ui/derives/'))
Expand Down Expand Up @@ -56,15 +57,17 @@

ENUM_TUPLE, ENUM_STRUCT, STRUCT_FIELDS, STRUCT_TUPLE = range(4)


def create_test_case(type, trait, super_traits, error_count):
string = [ENUM_STRING, ENUM_STRUCT_VARIANT_STRING, STRUCT_STRING, STRUCT_TUPLE_STRING][type]
all_traits = ','.join([trait] + super_traits)
super_traits = ','.join(super_traits)
error_deriving = '#[derive(%s)]' % super_traits if super_traits else ''

errors = '\n'.join('//~%s ERROR' % ('^' * n) for n in range(error_count))
code = string.format(traits = all_traits, errors = errors)
return TEMPLATE.format(error_deriving=error_deriving, code = code)
code = string.format(traits=all_traits, errors=errors)
return TEMPLATE.format(error_deriving=error_deriving, code=code)


def write_file(name, string):
test_file = os.path.join(TEST_DIR, 'derives-span-%s.rs' % name)
Expand All @@ -86,10 +89,10 @@ def write_file(name, string):

traits = {
'Default': (STRUCT, [], 1),
'FromPrimitive': (0, [], 0), # only works for C-like enums
'FromPrimitive': (0, [], 0), # only works for C-like enums

'Decodable': (0, [], 0), # FIXME: quoting gives horrible spans
'Encodable': (0, [], 0), # FIXME: quoting gives horrible spans
'Decodable': (0, [], 0), # FIXME: quoting gives horrible spans
'Encodable': (0, [], 0), # FIXME: quoting gives horrible spans
}

for (trait, supers, errs) in [('Clone', [], 1),
Expand Down
1 change: 0 additions & 1 deletion src/etc/generate-keyword-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import sys
import os
import datetime
import stat


Expand Down
Loading