Skip to content

Commit add1553

Browse files
authored
Merge pull request #69 from InsightSoftwareConsortium/fix-python3-support
ENH: Add python3 compatibility
2 parents 2c2fc8c + 2c8f0d7 commit add1553

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

evaluate-itk-performance.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77
import socket
88
import json
99

10+
11+
def get_shell_output_as_string(commandlist):
12+
"""
13+
A wrapper function for getting shell values back as strings
14+
for both python2 and python3
15+
:param commandlist:
16+
:return: A newline stripped string object (i.e. not a byte object)
17+
"""
18+
if sys.version_info[0] < 3:
19+
return subprocess.check_output(commandlist).strip()
20+
else:
21+
# In python 3, subprocess.check_call returns byte string.
22+
# https://stackoverflow.com/questions/18244126/python3-subprocess-output/18244485
23+
return subprocess.getoutput(' '.join(commandlist)).strip()
24+
1025
class FullPaths(argparse.Action):
1126
"""Expand user- and relative-paths"""
1227
def __call__(self, parser, namespace, values, option_string=None):
@@ -107,14 +122,14 @@ def extract_itk_information(itk_src):
107122
information['ITK_MANUAL_BUILD_INFORMATION'] = dict()
108123
manual_build_info = information['ITK_MANUAL_BUILD_INFORMATION']
109124
os.chdir(itk_src)
110-
itk_git_sha = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
111-
manual_build_info['GIT_CONFIG_SHA1'] = itk_git_sha
112-
itk_git_date = subprocess.check_output(['git', 'show', '-s', '--format=%ci',
113-
'HEAD']).strip()
114-
manual_build_info['GIT_CONFIG_DATE'] = itk_git_date
115-
local_modifications = subprocess.check_output(['git', 'diff', '--shortstat',
116-
'HEAD'])
117-
manual_build_info['GIT_LOCAL_MODIFICATIONS'] = local_modifications
125+
itk_git_sha = get_shell_output_as_string(['git', 'rev-parse', 'HEAD'])
126+
manual_build_info['GIT_CONFIG_SHA1'] = str(itk_git_sha)
127+
itk_git_date = get_shell_output_as_string(['git', 'show', '-s', '--format=%ci',
128+
'HEAD'])
129+
manual_build_info['GIT_CONFIG_DATE'] = str(itk_git_date)
130+
local_modifications = get_shell_output_as_string(
131+
['git', 'diff', '--shortstat', 'HEAD'])
132+
manual_build_info['GIT_LOCAL_MODIFICATIONS'] = str(local_modifications)
118133
print(local_modifications)
119134
return information
120135

0 commit comments

Comments
 (0)