Skip to content

Commit a42bd14

Browse files
committed
Merge pull request #655 from practicalswift/python-cleanups
Cleanups of various Python scripts
2 parents 5ce5a5e + bc6f6f4 commit a42bd14

15 files changed

+18
-33
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# All configuration values have a default; values that are commented out
1111
# serve to show the default.
1212

13-
import sys, os
13+
import sys
1414

1515
# If extensions (or modules to document with autodoc) are in another directory,
1616
# add these directories to sys.path here. If the directory is relative to the

test/Driver/Dependencies/Inputs/fake-build-for-bitcode.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from __future__ import print_function
77

88
import os
9-
import shutil
109
import sys
1110

1211
assert sys.argv[1] == '-frontend'

test/Driver/Dependencies/Inputs/fake-build-whole-module.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from __future__ import print_function
66

77
import os
8-
import shutil
98
import sys
109

1110
assert sys.argv[1] == '-frontend'

test/Driver/Dependencies/Inputs/modify-non-primary-files.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from __future__ import print_function
77

88
import os
9-
import shutil
109
import sys
1110

1211
assert sys.argv[1] == '-frontend'

utils/GYBUnicodeDataUtils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def create_tables(self):
248248
# maximum Unicode code point value is not 2^21-1 (0x1fffff), it is
249249
# 0x10ffff.
250250
self.supp_first_level_index_max = \
251-
0x10ffff >> (self.supp_second_level_index_bits + \
251+
0x10ffff >> (self.supp_second_level_index_bits +
252252
self.supp_data_offset_bits)
253253

254254
# A mapping from BMP first-level index to BMP data block index.

utils/SwiftBuildSupport.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def _get_preset_options_impl(config, substitutions, preset_name):
155155
# Split on newlines and filter out empty lines.
156156
mixins = filter(None, [m.strip() for m in a.splitlines()])
157157
for mixin in mixins:
158-
(base_build_script_opts, \
159-
base_build_script_impl_opts, \
158+
(base_build_script_opts,
159+
base_build_script_impl_opts,
160160
base_missing_opts) = \
161161
_get_preset_options_impl(config, substitutions, mixin)
162162
build_script_opts += base_build_script_opts
@@ -187,8 +187,8 @@ def get_preset_options(substitutions, preset_file_names, preset_name):
187187
print_with_argv0("preset '" + preset_name + "' not found")
188188
sys.exit(1)
189189
if missing_opts:
190-
print_with_argv0("missing option(s) for preset '" + preset_name + \
191-
"': " + ", ".join(missing_opts))
190+
print_with_argv0("missing option(s) for preset '" + preset_name +
191+
"': " + ", ".join(missing_opts))
192192
sys.exit(1)
193193

194194
return build_script_opts + [ "--" ] + build_script_impl_opts

utils/apply-fixit-edits.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from __future__ import print_function
1616

17-
import subprocess
1817
import json
1918
import argparse
2019
import sys
@@ -31,7 +30,7 @@ def apply_edits(path):
3130
remap_files = find_remap_files(path)
3231
if not remap_files:
3332
print("No remap files found")
34-
return 1;
33+
return 1
3534

3635
edits_set = set()
3736
for remap_file in remap_files:
@@ -49,7 +48,7 @@ def apply_edits(path):
4948
edits_per_file = {}
5049
for ed in edits_set:
5150
fname = ed[0]
52-
if not edits_per_file.has_key(fname):
51+
if fname not in edits_per_file:
5352
edits_per_file[fname] = []
5453
edits_per_file[fname].append((ed[1], ed[2], ed[3]))
5554

utils/gyb.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ def tokenGenerator(self, baseTokens):
478478
elif kind == 'gybLines':
479479

480480
self.codeStartLine = self.posToLine(self.tokenMatch.start('gybLines'))
481-
codeStartPos = self.tokenMatch.end('_indent')
482481
indentation = self.tokenMatch.group('_indent')
483482

484483
# Strip off the leading indentation and %-sign

utils/line-directive

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22
#convert line numbers in error messages according to "line directive" comments
3-
import os
43
import sys
54
import re
65
import bisect

utils/pre-commit-benchmark

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import subprocess
1414
import sys
1515
import os
1616
import re
17-
import shutil
1817
import argparse
1918
from pipes import quote as shell_quote
2019

@@ -167,7 +166,7 @@ def parseFloat(word):
167166
try:
168167
return float(word)
169168
except:
170-
raise ScoreParserException("Expected float val, not "+word)
169+
raise Exception("Expected float val, not {}".format(word))
171170

172171
def getScores(fname):
173172
scores = {}
@@ -289,7 +288,7 @@ if __name__ == '__main__':
289288
action='append', help='Optimization levels to test')
290289
parser.add_argument(dest='baseline', nargs='?', metavar='tree-ish', default='origin/master',
291290
help='the baseline Git commit to compare with.')
292-
parser.add_argument(dest='build_script_args', nargs=argparse.REMAINDER, metavar='build-script-args', default=[]
291+
parser.add_argument(dest='build_script_args', nargs=argparse.REMAINDER, metavar='build-script-args', default=[],
293292
help='additional arguments to build script, e.g. -- --distcc --build-args=-j30')
294293
args = parser.parse_args()
295294

utils/pygments/swift.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44

5-
from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, this, do_insertions
5+
from pygments.lexer import RegexLexer, include, bygroups
66
from pygments.token import *
77

88
__all__ = ['SwiftLexer', 'SwiftConsoleLexer']

utils/sil-opt-verify-all-modules.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import glob
1818
import multiprocessing
1919
import os
20-
import shutil
2120
import subprocess
2221
import sys
2322
import tempfile
@@ -76,11 +75,6 @@ def get_verify_resource_dir_modules_commands(
7675
commands = []
7776
module_cache_dir = tempfile.mkdtemp(prefix="swift-testsuite-clang-module-cache")
7877
for (subdir, arch, triple) in known_platforms:
79-
platform_frameworks_dir = os.path.join(
80-
subprocess.check_output([
81-
'xcrun', '--toolchain', toolchain_name, '--show-sdk-platform-path'
82-
]).strip(),
83-
'Developer', 'Library', 'Frameworks')
8478
modules_dir = os.path.join(resource_dir, subdir, arch)
8579
print(modules_dir)
8680
modules = glob.glob(os.path.join(modules_dir, '*.swiftmodule'))

utils/swift-bench.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import subprocess
4040
import numpy
41-
import time
4241
import re
4342
import os
4443
import sys
@@ -299,7 +298,6 @@ def runBench(self, name):
299298
return
300299
samples = []
301300
self.log("Running bench: %s, numsamples: %d" % (name, numSamples), 2)
302-
output = ""
303301
for i in range(0,numSamples):
304302
try:
305303
r = self.runCommand([self.tests[name].binary, str(iterScale),

utils/update-checkout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def obtain_additional_swift_sources(opts = {'with_ssh': False}):
6868
with WorkingDirectory(SWIFT_SOURCE_ROOT):
6969
if not os.path.isdir(os.path.join(dir_name, ".git")):
7070
print("--- Cloning '" + dir_name + "' ---")
71-
if opts['with_ssh'] == True:
71+
if opts['with_ssh'] is True:
7272
remote = "[email protected]:" + repo + '.git'
7373
else:
7474
remote = "https://github.com/" + repo + '.git'

utils/viewcfg

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def main():
121121
newBlocks = { }
122122
for name, block in blocks.iteritems():
123123
for adjName in (block.preds + block.getSuccs()):
124-
if not adjName in blocks:
124+
if adjName not in blocks:
125125
newBlocks[adjName] = Block(adjName, None)
126126

127127
blocks = dict(blocks.items() + newBlocks.items())
@@ -132,7 +132,7 @@ def main():
132132
for name, block in blocks.iteritems():
133133
for predName in block.preds:
134134
predBlock = blocks[predName]
135-
if not name in predBlock.getSuccs():
135+
if name not in predBlock.getSuccs():
136136
predBlock.getSuccs().append(name)
137137

138138
# Write the output dot file.
@@ -143,16 +143,16 @@ def main():
143143
outFile.write('digraph "CFG" {\n')
144144
for name, block in blocks.iteritems():
145145
if block.content is not None:
146-
outFile.write("\tNode" + str(block.index) + \
146+
outFile.write("\tNode" + str(block.index) +
147147
" [shape=record,label=\"{" + block.content + "}\"];\n")
148148
else:
149-
outFile.write("\tNode" + str(block.index) + \
150-
" [shape=record,color=gray,fontcolor=gray,label=\"{" + \
149+
outFile.write("\tNode" + str(block.index) +
150+
" [shape=record,color=gray,fontcolor=gray,label=\"{" +
151151
block.name + "}\"];\n")
152152

153153
for succName in block.getSuccs():
154154
succBlock = blocks[succName]
155-
outFile.write("\tNode" + str(block.index) + " -> Node" + \
155+
outFile.write("\tNode" + str(block.index) + " -> Node" +
156156
str(succBlock.index) + ";\n")
157157

158158
outFile.write("}\n")

0 commit comments

Comments
 (0)