Skip to content

Commit 134cc9b

Browse files
Migrate from Python2 to Python3 (#681)
* update runner.py with Python3 support * update project.py to python3 and rename file * use proper python3 enum class * update common.py to python3 * update all scripts to only import python3 modules and run with python3 binary * use context managers for file handling * fix input prompt within reproduce.py * fix dictionary items() calls * fix byte encoding to process pipe
1 parent a08aecd commit 134cc9b

13 files changed

+105
-120
lines changed

build_incremental.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# ===--- build_incremental.py ---------------------------------------------===
33
#
44
# This source file is part of the Swift.org open source project
@@ -18,7 +18,7 @@
1818
import sys
1919

2020
import common
21-
import project_future
21+
import project
2222

2323

2424
def parse_args():
@@ -31,7 +31,10 @@ def parse_args():
3131
def main():
3232
"""Execute specified indexed project actions."""
3333
args = parse_args()
34-
index = json.loads(open(args.projects).read())
34+
35+
with open(args.projects) as projects:
36+
index = json.loads(projects.read())
37+
3538
result = project.ProjectListBuilder(
3639
args.include_repos,
3740
args.exclude_repos,

builder.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# ===--- builder.py -------------------------------------------------------===
33
#
44
# This source file is part of the Swift.org open source project
@@ -18,7 +18,7 @@
1818
import sys
1919

2020
import common
21-
import project_future
21+
import project
2222

2323

2424
def parse_args():
@@ -31,7 +31,10 @@ def parse_args():
3131
def main():
3232
"""Execute specified indexed project actions."""
3333
args = parse_args()
34-
index = json.loads(open(args.projects).read())
34+
35+
with open(args.projects) as projects:
36+
index = json.loads(projects.read())
37+
3538
result = project.ProjectListBuilder(
3639
args.include_repos,
3740
args.exclude_repos,

checkout

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# ===--- checkout --------------------------------------------------------===
33
#
44
# This source file is part of the Swift.org open source project
@@ -19,7 +19,7 @@ import argparse
1919
import sys
2020

2121
import common
22-
import project_future
22+
import project
2323

2424

2525
def parse_args():
@@ -44,7 +44,10 @@ def main():
4444
"""Clone and checkout pinned commits for indexed projects."""
4545
os.chdir(os.path.dirname(__file__))
4646
args = parse_args()
47-
index = json.loads(open(args.projects).read())
47+
48+
with open(args.projects) as projects:
49+
index = json.loads(projects.read())
50+
4851
root_path = common.private_workspace('project_cache')
4952
total_repos = 0
5053

@@ -59,7 +62,7 @@ def main():
5962
continue
6063
total_repos += 1
6164
for compatible_swift in repo['compatibility']:
62-
project_future.checkout(root_path, repo, compatible_swift['commit'])
65+
project.checkout(root_path, repo, compatible_swift['commit'])
6366
common.debug_print('='*40)
6467
common.debug_print('Repository Summary:')
6568
common.debug_print(' Total: %s' % total_repos)

cleanup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# ===--- cleanup ----------------------------------------------------------===
33
#
44
# This source file is part of the Swift.org open source project

common.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# ===--- common.py --------------------------------------------------------===
33
#
44
# This source file is part of the Swift.org open source project
@@ -12,7 +12,6 @@
1212
# ===----------------------------------------------------------------------===
1313

1414
"""A library containing common utility functionality."""
15-
from __future__ import print_function
1615

1716
import multiprocessing
1817
import os
@@ -23,11 +22,6 @@
2322
import sys
2423
import shlex
2524

26-
try:
27-
basestring # Python 2
28-
except NameError:
29-
basestring = str # Python 3
30-
3125
DEFAULT_EXECUTE_TIMEOUT = 10*60
3226

3327
branches = {
@@ -264,7 +258,7 @@ def clone_repos():
264258
], stdin=subprocess.PIPE)
265259

266260
for repo in repos:
267-
process0.stdin.write(repo)
261+
process0.stdin.write(repo.encode('utf-8'))
268262

269263
process0.stdin.close()
270264

@@ -392,7 +386,7 @@ def check_execute_output(command, timeout=None,
392386
with Timeout(timeout):
393387
output = subprocess.check_output(
394388
command, stderr=stderr, **kwargs
395-
)
389+
).decode('utf-8')
396390
except subprocess.CalledProcessError as e:
397391
debug_print(e, stderr=stderr)
398392
raise
@@ -553,7 +547,7 @@ def popen(*args, **kwargs):
553547

554548

555549
def call(c):
556-
if isinstance(c, basestring):
550+
if isinstance(c, str):
557551
c = shlex.split(c)
558552
formatted = [x.format(**os.environ) for x in c]
559553
shell_debug_print(c)

0 commit comments

Comments
 (0)