Skip to content

Commit

Permalink
[Python] Make flake8 linting pass without errors/warning (w/ default …
Browse files Browse the repository at this point in the history
…rules)
  • Loading branch information
practicalswift committed Mar 13, 2016
1 parent ee3e7a5 commit 1edb62d
Show file tree
Hide file tree
Showing 24 changed files with 104 additions and 89 deletions.
1 change: 0 additions & 1 deletion .pep8
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[flake8]
filename = *.py,Benchmark_Driver,Benchmark_DTrace.in,Benchmark_GuardMalloc.in,Benchmark_RuntimeLeaksRunner.in,build-script,gyb,line-directive,ns-html2rst,recursive-lipo,rth,submit-benchmark-results,update-checkout,viewcfg
max-line-length = 80
4 changes: 2 additions & 2 deletions benchmark/scripts/Benchmark_DTrace.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# ===--- Benchmark_DTrace.in ----------------------------------------------===//
# ===--- Benchmark_DTrace.in ---------------------------------------------===//
#
# This source file is part of the Swift.org open source project
#
Expand All @@ -10,7 +10,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===//
# ===---------------------------------------------------------------------===//

import argparse
import os
Expand Down
12 changes: 6 additions & 6 deletions benchmark/scripts/Benchmark_Driver
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# ===--- Benchmark_Driver -------------------------------------------------===//
# ===--- Benchmark_Driver ------------------------------------------------===//
#
# This source file is part of the Swift.org open source project
#
Expand All @@ -11,7 +11,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===//
# ===---------------------------------------------------------------------===//

import argparse
import datetime
Expand Down Expand Up @@ -109,10 +109,10 @@ def instrument_test(driver_path, test, num_samples):
avg_test_output[i] = int(round(avg_test_output[i] /
float(len(test_outputs))))
avg_test_output[num_samples_index] = num_samples
avg_test_output[min_index] = min(test_outputs,
key=lambda x: int(x[min_index]))[min_index]
avg_test_output[max_index] = max(test_outputs,
key=lambda x: int(x[max_index]))[max_index]
avg_test_output[min_index] = min(
test_outputs, key=lambda x: int(x[min_index]))[min_index]
avg_test_output[max_index] = max(
test_outputs, key=lambda x: int(x[max_index]))[max_index]
avg_test_output = map(str, avg_test_output)

return avg_test_output
Expand Down
4 changes: 2 additions & 2 deletions benchmark/scripts/Benchmark_GuardMalloc.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# ===--- Benchmark_GuardMalloc.in -----------------------------------------===//
# ===--- Benchmark_GuardMalloc.in ----------------------------------------===//
#
# This source file is part of the Swift.org open source project
#
Expand All @@ -10,7 +10,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===//
# ===---------------------------------------------------------------------===//

import os
import subprocess
Expand Down
8 changes: 4 additions & 4 deletions benchmark/scripts/Benchmark_RuntimeLeaksRunner.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# ===--- Benchmark_RuntimeLeaksRunner.in ----------------------------------===//
# ===--- Benchmark_RuntimeLeaksRunner.in ---------------------------------===//
#
# This source file is part of the Swift.org open source project
#
Expand All @@ -10,7 +10,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===//
# ===---------------------------------------------------------------------===//

import json
import os
Expand All @@ -26,8 +26,8 @@ import perf_test_driver # noqa (E402 module level import not at top of file)
XFAIL_LIST = [
]

# Global objective-c classes created by various frameworks. We do not care about
# these.
# Global objective-c classes created by various frameworks. We do not care
# about these.
IGNORABLE_GLOBAL_OBJC_CLASSES = set([
'__NSPlaceholderDate',
'NSCache',
Expand Down
7 changes: 4 additions & 3 deletions benchmark/scripts/compare_perf_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# ===--- compare_perf_tests.py --------------------------------------------===//
# ===--- compare_perf_tests.py -------------------------------------------===//
#
# This source file is part of the Swift.org open source project
#
Expand All @@ -11,7 +11,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===//
# ===---------------------------------------------------------------------===//

# e.g.
# repeat.sh 3 tot/bin/Benchmark_Driver run -o -O > tot.O.times
Expand Down Expand Up @@ -136,7 +136,8 @@ def compare_scores(key, score1, worstsample1, score2, worstsample2, runs, num):

if bestscore1 != 0 and bestscore2 != 0:
print(("%+.1f%%" %
(((float(bestscore2) / bestscore1) - 1) * 100)).rjust(9), end="")
(((float(bestscore2) / bestscore1) - 1) * 100)).rjust(9),
end="")
if ShowSpeedup:
Num, Den = float(bestscore2), float(bestscore1)
if IsTime:
Expand Down
4 changes: 2 additions & 2 deletions benchmark/scripts/generate_harness/generate_harness.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# ===--- generate_harness.py ----------------------------------------------===//
# ===--- generate_harness.py ---------------------------------------------===//
#
# This source file is part of the Swift.org open source project
#
Expand All @@ -10,7 +10,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===//
# ===---------------------------------------------------------------------===//

# Generate CMakeLists.txt and utils/main.swift from templates.

Expand Down
4 changes: 2 additions & 2 deletions benchmark/scripts/perf_test_driver/perf_test_driver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# ===--- perf_test_driver.py ----------------------------------------------===//
# ===--- perf_test_driver.py ---------------------------------------------===//
#
# This source file is part of the Swift.org open source project
#
Expand All @@ -10,7 +10,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===//
# ===---------------------------------------------------------------------===//

import multiprocessing
import os
Expand Down
4 changes: 2 additions & 2 deletions benchmark/utils/convertToJSON.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# ===--- convertToJSON.py -------------------------------------------------===//
# ===--- convertToJSON.py ------------------------------------------------===//
#
# This source file is part of the Swift.org open source project
#
Expand All @@ -10,7 +10,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===//
# ===---------------------------------------------------------------------===//

# This script converts results from pre-commit benchmark tests to JSON.
# Usage: PrecommitBench_O | convertToJSON.py
Expand Down
13 changes: 8 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#
# Swift documentation build configuration file.
#
# This file is execfile()d with the current directory set to its containing dir.
# This file is execfile()d with the current directory set to its containing
# dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
Expand All @@ -23,8 +24,8 @@
# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.intersphinx', 'sphinx.ext.todo']

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -66,7 +67,8 @@
# directories to ignore when looking for source files.
exclude_patterns = ['_build']

# The reST default role (used for this markup: `text`) to use for all documents.
# The reST default role (used for this markup: `text`) to use for all
# documents.
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
Expand Down Expand Up @@ -190,7 +192,8 @@
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
# (source start file, target name, title, author, documentclass
# [howto/manual]).
latex_documents = [
('contents', 'Swift.tex', u'Swift Documentation',
u'LLVM project', 'manual'),
Expand Down
37 changes: 19 additions & 18 deletions utils/GYBUnicodeDataUtils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ===--- GYBUnicodeDataUtils.py -----------------------*- coding: utf-8 -*-===//
# ===--- GYBUnicodeDataUtils.py ----------------------*- coding: utf-8 -*-===//
#
# This source file is part of the Swift.org open source project
#
Expand Down Expand Up @@ -105,8 +105,8 @@ def __init__(self, grapheme_break_property_file_name):
for cp in range(0, 0x110000):
self.property_values[cp] = self.get_default_value()

for start_code_point, end_code_point, val in self.property_value_ranges:
for cp in range(start_code_point, end_code_point + 1):
for start_code_pt, end_code_pt, val in self.property_value_ranges:
for cp in range(start_code_pt, end_code_pt + 1):
self.property_values[cp] = val

def get_default_value(self):
Expand Down Expand Up @@ -320,7 +320,8 @@ def get_value(self, cp):
if cp <= 0xffff:
data_block_index = self.bmp_lookup[
self.get_bmp_first_level_index(cp)]
return self.bmp_data[data_block_index][self.get_bmp_data_offset(cp)]
return self.bmp_data[data_block_index][
self.get_bmp_data_offset(cp)]
else:
second_lookup_index = self.supp_lookup1[
self.get_supp_first_level_index(cp)]
Expand Down Expand Up @@ -552,14 +553,14 @@ def _convert_line(line):
pass
else:
code_point = int(token, 16)
# Tests from Unicode spec have isolated surrogates in them. Our
# segmentation algorithm works on UTF-8 sequences, so encoding a
# surrogate would produce an invalid code unit sequence.
# Instead of trying to emulate the maximal subpart algorithm for
# inserting U+FFFD in Python, we just replace every isolated
# surrogate with U+200B, which also has Grapheme_Cluster_Break
# equal to 'Control' and test separately that we handle
# ill-formed UTF-8 sequences.
# Tests from Unicode spec have isolated surrogates in them.
# Our segmentation algorithm works on UTF-8 sequences, so
# encoding a surrogate would produce an invalid code unit
# sequence. Instead of trying to emulate the maximal subpart
# algorithm for inserting U+FFFD in Python, we just replace
# every isolated surrogate with U+200B, which also has
# Grapheme_Cluster_Break equal to 'Control' and test
# separately that we handle ill-formed UTF-8 sequences.
if code_point >= 0xd800 and code_point <= 0xdfff:
code_point = 0x200b
code_point = (b'\U%(cp)08x' % {b'cp': code_point}).decode(
Expand Down Expand Up @@ -613,14 +614,14 @@ def _convert_line(line):
pass
else:
code_point = int(token, 16)
# Tests from Unicode spec have isolated surrogates in them. Our
# Tests from Unicode spec have isolated surrogates in them. Our
# segmentation algorithm works on UTF-16 sequences, so encoding
# a surrogate would produce an invalid code unit sequence.
# Instead of trying to emulate the maximal subpart algorithm for
# inserting U+FFFD in Python, we just replace every isolated
# surrogate with U+200B, which also has Grapheme_Cluster_Break
# equal to 'Control' and test separately that we handle
# ill-formed UTF-8 sequences.
# Instead of trying to emulate the maximal subpart algorithm
# for inserting U+FFFD in Python, we just replace every
# isolated surrogate with U+200B, which also has
# Grapheme_Cluster_Break equal to 'Control' and test separately
# that we handle ill-formed UTF-8 sequences.
if code_point >= 0xd800 and code_point <= 0xdfff:
code_point = 0x200b
test += [code_point]
Expand Down
2 changes: 1 addition & 1 deletion utils/SwiftIntTypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ===--- SwiftIntTypes.py -----------------------------*- coding: utf-8 -*-===//
# ===--- SwiftIntTypes.py ----------------------------*- coding: utf-8 -*-===//
#
# This source file is part of the Swift.org open source project
#
Expand Down
3 changes: 2 additions & 1 deletion utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ To use it, specify the '--preset=' argument:
[~/src/s]$ ./swift/utils/build-script --preset=ds
./swift/utils/build-script: using preset 'ds', which expands to
./swift/utils/build-script --release --debug-swift --debug-swift-stdlib --test
./swift/utils/build-script --release --debug-swift --debug-swift-stdlib \
--test
--build-subdir=ds --
...
Expand Down
2 changes: 1 addition & 1 deletion utils/cmpcodesize/cmpcodesize/compare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ====--- compare.py - Compare built products' sizes --*- coding: utf-8 -*-===//
# ====--- compare.py - Compare built products' sizes -*- coding: utf-8 -*-===//
#
# This source file is part of the Swift.org open source project
#
Expand Down
4 changes: 2 additions & 2 deletions utils/cmpcodesize/cmpcodesize/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def main():
Environment variables:
SWIFT_NEW_BUILDDIR The new build-dir
E.g. $HOME/swiftnew/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64
E.g. .../swiftnew/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64
SWIFT_OLD_BUILDDIR The old build-dir
E.g. $HOME/swiftold/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64
E.g. .../swiftold/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64
How to specify files:
1) No files:
Expand Down
10 changes: 6 additions & 4 deletions utils/gyb.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ def code_starts_with_dedent_keyword(source_lines):
False
>>> code_starts_with_dedent_keyword(split_lines('except ifSomethingElse:'))
True
>>> code_starts_with_dedent_keyword(split_lines('\n# comment\nelse: # yes'))
>>> code_starts_with_dedent_keyword(
split_lines('\n# comment\nelse: # yes'))
True
"""
token_text = None
Expand Down Expand Up @@ -449,7 +450,7 @@ def token_generator(self, base_tokens):
... '''% for x in [1, 2, 3]:
... % if x == 1:
... literal1
... % elif x > 1: # add an output line after this line to fix the bug
... % elif x > 1: # add an output line after this line to fix bug
... % if x == 2:
... literal2
... % end
Expand Down Expand Up @@ -544,7 +545,8 @@ def next_token(self):
class ExecutionContext(object):
"""State we pass around during execution of a template"""

def __init__(self, line_directive='// ###sourceLocation', **local_bindings):
def __init__(self, line_directive='// ###sourceLocation',
**local_bindings):
self.local_bindings = local_bindings
self.line_directive = line_directive
self.local_bindings['__context__'] = self
Expand Down Expand Up @@ -753,7 +755,7 @@ def parse_template(filename, text=None):
{
if x == 1:
__children__[0].execute(__context__)
elif x > 1: # add output line after this line to fix the bug
elif x > 1: # add output line after this line to fix bug
__children__[1].execute(__context__)
}
[
Expand Down
Loading

0 comments on commit 1edb62d

Please sign in to comment.