Skip to content

Migrate from Python2 to Python3 #681

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

Merged
merged 9 commits into from
Jul 27, 2022
9 changes: 6 additions & 3 deletions build_incremental.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# ===--- build_incremental.py ---------------------------------------------===
#
# This source file is part of the Swift.org open source project
Expand All @@ -18,7 +18,7 @@
import sys

import common
import project_future
import project


def parse_args():
Expand All @@ -31,7 +31,10 @@ def parse_args():
def main():
"""Execute specified indexed project actions."""
args = parse_args()
index = json.loads(open(args.projects).read())

with open(args.projects) as projects:
index = json.loads(projects.read())

result = project.ProjectListBuilder(
args.include_repos,
args.exclude_repos,
Expand Down
9 changes: 6 additions & 3 deletions builder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# ===--- builder.py -------------------------------------------------------===
#
# This source file is part of the Swift.org open source project
Expand All @@ -18,7 +18,7 @@
import sys

import common
import project_future
import project


def parse_args():
Expand All @@ -31,7 +31,10 @@ def parse_args():
def main():
"""Execute specified indexed project actions."""
args = parse_args()
index = json.loads(open(args.projects).read())

with open(args.projects) as projects:
index = json.loads(projects.read())

result = project.ProjectListBuilder(
args.include_repos,
args.exclude_repos,
Expand Down
11 changes: 7 additions & 4 deletions checkout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# ===--- checkout --------------------------------------------------------===
#
# This source file is part of the Swift.org open source project
Expand All @@ -19,7 +19,7 @@ import argparse
import sys

import common
import project_future
import project


def parse_args():
Expand All @@ -44,7 +44,10 @@ def main():
"""Clone and checkout pinned commits for indexed projects."""
os.chdir(os.path.dirname(__file__))
args = parse_args()
index = json.loads(open(args.projects).read())

with open(args.projects) as projects:
index = json.loads(projects.read())

root_path = common.private_workspace('project_cache')
total_repos = 0

Expand All @@ -59,7 +62,7 @@ def main():
continue
total_repos += 1
for compatible_swift in repo['compatibility']:
project_future.checkout(root_path, repo, compatible_swift['commit'])
project.checkout(root_path, repo, compatible_swift['commit'])
common.debug_print('='*40)
common.debug_print('Repository Summary:')
common.debug_print(' Total: %s' % total_repos)
Expand Down
2 changes: 1 addition & 1 deletion cleanup
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# ===--- cleanup ----------------------------------------------------------===
#
# This source file is part of the Swift.org open source project
Expand Down
12 changes: 3 additions & 9 deletions common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# ===--- common.py --------------------------------------------------------===
#
# This source file is part of the Swift.org open source project
Expand All @@ -12,7 +12,6 @@
# ===----------------------------------------------------------------------===

"""A library containing common utility functionality."""
from __future__ import print_function

import multiprocessing
import os
Expand All @@ -23,11 +22,6 @@
import sys
import shlex

try:
basestring # Python 2
except NameError:
basestring = str # Python 3

DEFAULT_EXECUTE_TIMEOUT = 10*60

branches = {
Expand Down Expand Up @@ -392,7 +386,7 @@ def check_execute_output(command, timeout=None,
with Timeout(timeout):
output = subprocess.check_output(
command, stderr=stderr, **kwargs
)
).decode('utf-8')
except subprocess.CalledProcessError as e:
debug_print(e, stderr=stderr)
raise
Expand Down Expand Up @@ -553,7 +547,7 @@ def popen(*args, **kwargs):


def call(c):
if isinstance(c, basestring):
if isinstance(c, str):
c = shlex.split(c)
formatted = [x.format(**os.environ) for x in c]
shell_debug_print(c)
Expand Down
Loading