Skip to content

Commit

Permalink
Properly python lint remaining files
Browse files Browse the repository at this point in the history
  • Loading branch information
hughbe committed Mar 23, 2017
1 parent c34aa68 commit 8671854
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 33 deletions.
2 changes: 2 additions & 0 deletions benchmark/scripts/Benchmark_DTrace.in
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class DTraceBenchmarkDriver(perf_test_driver.BenchmarkDriver):

return DTraceResult(test_name, 0, results, self.csv_output)


SWIFT_BIN_DIR = os.path.dirname(os.path.abspath(__file__))


Expand All @@ -123,6 +124,7 @@ def parse_args():
dest='csv_output')
return parser.parse_args()


if __name__ == "__main__":
args = parse_args()
g = DTraceBenchmarkDriver(SWIFT_BIN_DIR, XFAIL_LIST, args.csv_output)
Expand Down
1 change: 1 addition & 0 deletions benchmark/scripts/Benchmark_Driver
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,6 @@ def main():
args.optimization = sorted(list(set(args.optimization)))
return args.func(args)


if __name__ == '__main__':
exit(main())
1 change: 1 addition & 0 deletions benchmark/scripts/Benchmark_GuardMalloc.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class GuardMallocBenchmarkDriver(perf_test_driver.BenchmarkDriver):
stdout=open('/dev/null', 'w'))
return GuardMallocResult(test_name, status)


SWIFT_BIN_DIR = os.path.dirname(os.path.abspath(__file__))

if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions benchmark/scripts/Benchmark_RuntimeLeaksRunner.in
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class LeaksRunnerBenchmarkDriver(perf_test_driver.BenchmarkDriver):
return LeaksRunnerResult(test_name)
return LeaksRunnerResult(test_name, total_count2 - total_count1)


SWIFT_BIN_DIR = os.path.dirname(os.path.abspath(__file__))


Expand All @@ -134,6 +135,7 @@ def parse_args():
parser.add_argument('-num-iters', type=int, default=2)
return parser.parse_args()


if __name__ == "__main__":
args = parse_args()
l = LeaksRunnerBenchmarkDriver(
Expand Down
1 change: 1 addition & 0 deletions docs/scripts/ns-html2rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ usage: nshtml2rst < NSString.html > NSString.rst

sys.stdout.write(rst)


if __name__ == '__main__':
run()
1 change: 1 addition & 0 deletions utils/80+-check
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def get_arguments():
in our line length count"""))
return parser.parse_args()


args = get_arguments()

found_violation = False
Expand Down
2 changes: 2 additions & 0 deletions utils/coverage/coverage-build-db
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def worker(args):
"""Parse coverage log at path `args[0]` and place in queue `args[1]`"""
args[1].put(parse_coverage_log(args[0]))


manager = multiprocessing.Manager()
result_queue = manager.Queue()
worker_queue = []
Expand Down Expand Up @@ -200,5 +201,6 @@ def main():

return 0


if __name__ == '__main__':
sys.exit(main())
1 change: 1 addition & 0 deletions utils/coverage/coverage-generate-data
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def main():
pool.map_async(demangle_coverage_data, coverage_log_files).get(9999999)
return 0


if __name__ == '__main__':
try:
sys.exit(main())
Expand Down
5 changes: 3 additions & 2 deletions utils/coverage/coverage-touch-tests
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def main():
args = parser.parse_args()

for path in [args.swift_dir, args.coverage_db]:
assert(os.path.exists(path), "Unable to find %s. Try absolute paths." %
path)
assert os.path.exists(path), "Unable to find %s. Try absolute" \
" paths." % path

console.setLevel(level=args.log.upper())
logging.debug(args)
Expand Down Expand Up @@ -160,6 +160,7 @@ def diff():
subprocess.call(['diff', '-U0', args.old_file, args.new_file])
return 0


if __name__ == '__main__':
if 'GIT_EXTERNAL_DIFF' in os.environ:
sys.exit(diff())
Expand Down
3 changes: 3 additions & 0 deletions utils/gyb.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def next_token(self):

_default_line_directive = '// ###sourceLocation'


class ExecutionContext(object):

"""State we pass around during execution of a template"""
Expand Down Expand Up @@ -746,6 +747,7 @@ def __str__(self, indent=''):
) + '\n' + indent + '}'
return s + self.format_children(indent)


def expand(filename, line_directive=_default_line_directive, **local_bindings):
r"""Return the contents of the givepn template file, executed with the given
local bindings.
Expand Down Expand Up @@ -777,6 +779,7 @@ def expand(filename, line_directive=_default_line_directive, **local_bindings):
return execute_template(
t, line_directive=line_directive, **local_bindings)


def parse_template(filename, text=None):
r"""Return an AST corresponding to the given template file.
Expand Down
76 changes: 47 additions & 29 deletions utils/round-trip-syntax-test
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ import tempfile

logging.basicConfig(format='%(message)s', level=logging.INFO)


class RoundTripTask(object):
def __init__(self, input_filename, action, swift_syntax_test, skip_bad_syntax):
def __init__(self, input_filename, action, swift_syntax_test,
skip_bad_syntax):
assert action == '-round-trip-parse' or action == '-round-trip-lex'
assert type(input_filename) == unicode
assert type(swift_syntax_test) == str
assert os.path.isfile(input_filename), "Input file {} is not accessible!".format(input_filename)
assert os.path.isfile(swift_syntax_test), "{} tool is not accessible!".format(swift_syntax_test)

assert os.path.isfile(input_filename), \
"Input file {} is not accessible!".format(input_filename)
assert os.path.isfile(swift_syntax_test), \
"{} tool is not accessible!".format(swift_syntax_test)
self.input_filename = input_filename
self.action = action
self.swift_syntax_test = swift_syntax_test
Expand All @@ -40,7 +45,8 @@ class RoundTripTask(object):
def diff(self):
logging.debug(' '.join(self.diff_command))
diff = subprocess.Popen(self.diff_command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = diff.communicate(self.stdout)
if diff.returncode != 0:
return stdout
Expand All @@ -55,7 +61,7 @@ class RoundTripTask(object):
self.stderr_file = tempfile.NamedTemporaryFile('w')

process = subprocess.Popen(command, stdout=self.output_file,
stderr=self.stderr_file)
stderr=self.stderr_file)
process.wait()
self.returncode = process.returncode

Expand All @@ -70,11 +76,14 @@ class RoundTripTask(object):
try:
if self.returncode != 0:
if self.skip_bad_syntax:
logging.warning('---===WARNING===--- Lex/parse had error diagnostics, so not diffing. Skipping this file due to -skip-bad-syntax.')
logging.warning('---===WARNING===--- Lex/parse had error'
' diagnostics, so not diffing. Skipping'
' this file due to -skip-bad-syntax.')
logging.error(' '.join(command))
return None
else:
logging.error('---===ERROR===--- Lex/parse had error diagnostics, so not diffing.')
logging.error('---===ERROR===--- Lex/parse had error'
' diagnostics, so not diffing.')
logging.error(' '.join(command))
logging.error(self.stdout)
logging.error(self.stderr)
Expand All @@ -86,6 +95,7 @@ class RoundTripTask(object):
diff = self.diff()
return diff


def swift_files_in_dir(d):
swift_files = []
for root, dirs, files in os.walk(d):
Expand All @@ -96,6 +106,7 @@ def swift_files_in_dir(d):
swift_files.append(abs_file)
return swift_files


def run_task(task):
try:
diff = task.run()
Expand All @@ -110,38 +121,41 @@ def run_task(task):
return True
return False


def main():
tool_description='''
tool_description = '''
Checks for round-trip lex/parse/print compatibility.
Swift's syntax representation should be "full-fidelity", meaning that there is
a perfect representation of what is in the source. When printing a syntax tree
to a file, that file should be identical to the file that was
originally parsed.
This driver invokes swift-syntax-test using -round-trip-lex and -round-trip-parse
on .swift files and .swift files in directories.
This driver invokes swift-syntax-test using -round-trip-lex and
-round-trip-parse on .swift files and .swift files in directories.
'''
parser = argparse.ArgumentParser(description=tool_description)
parser.add_argument('--directory', '-d', action='append',
dest='input_directories', default=[],
help='Add a directory, searching for .swift files within')
dest='input_directories', default=[],
help='Add a directory, searching for .swift files'
' within')
parser.add_argument('--file', '-f', action='append',
dest='individual_input_files', default=[],
help='Add an individual file to test')
dest='individual_input_files', default=[],
help='Add an individual file to test')
parser.add_argument('--swift-syntax-test', '-t', required=True,
dest='tool_path',
help='Absolute path to the swift-syntax-test tool')
dest='tool_path',
help='Absolute path to the swift-syntax-test tool')
parser.add_argument('--skip-bad-syntax',
action='store_true',
default=False,
help="Skip files that caused lex or parse diagnostics to be emitted")
action='store_true',
default=False,
help="Skip files that caused lex or parse diagnostics"
" to be emitted")

args = parser.parse_args()

dir_listings = [swift_files_in_dir(d) for d in args.input_directories]
all_input_files = [filename for dir_listing in dir_listings
for filename in dir_listing]
for filename in dir_listing]
all_input_files += args.individual_input_files
all_input_files = [f.decode('utf-8') for f in all_input_files]

Expand All @@ -150,16 +164,20 @@ on .swift files and .swift files in directories.
sys.exit(1)

if not os.path.isfile(args.tool_path):
raise RuntimeError("Couldn't find swift-syntax-test at {}".format(args.tool_path))

lex_tasks = [RoundTripTask(filename, '-round-trip-lex', args.tool_path, args.skip_bad_syntax)
for filename in all_input_files]
parse_tasks = [RoundTripTask(filename, '-round-trip-parse', args.tool_path, args.skip_bad_syntax)
for filename in all_input_files]

failed = reduce(lambda a,b: a and b,
map(run_task, lex_tasks + parse_tasks))
raise RuntimeError("Couldn't find swift-syntax-test at {}"
.format(args.tool_path))

lex_tasks = [RoundTripTask(filename, '-round-trip-lex', args.tool_path,
args.skip_bad_syntax)
for filename in all_input_files]
parse_tasks = [RoundTripTask(filename, '-round-trip-parse', args.tool_path,
args.skip_bad_syntax)
for filename in all_input_files]

failed = reduce(lambda a, b: a and b,
map(run_task, lex_tasks + parse_tasks))
sys.exit(1 if failed else 0)


if __name__ == '__main__':
main()
6 changes: 4 additions & 2 deletions utils/swift_build_support/tests/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def test_workspace(self):

class ComputeBuildSubdirTestCase(unittest.TestCase):

def create_basic_args(self, generator, variant, assertions, enable_asan=False):
def create_basic_args(self, generator, variant, assertions,
enable_asan=False):
return argparse.Namespace(
cmake_generator=generator,
cmark_build_variant=variant,
Expand Down Expand Up @@ -139,7 +140,8 @@ def test_all_combinations_are_unique(self):

def generate():
for c in productions:
args = argparse.Namespace(cmake_generator="Ninja", enable_asan=False)
args = argparse.Namespace(cmake_generator="Ninja",
enable_asan=False)
for key, val in zip(keys, c):
setattr(args, key, val)
yield compute_build_subdir(args)
Expand Down

0 comments on commit 8671854

Please sign in to comment.