Skip to content

Commit

Permalink
Merge pull request #2715 from boegel/print_py3
Browse files Browse the repository at this point in the history
make all print statements compatible with Python 3
  • Loading branch information
wpoely86 authored Jan 12, 2019
2 parents d26f245 + ce263ab commit fbcab5c
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 38 deletions.
6 changes: 3 additions & 3 deletions easybuild/framework/easyconfig/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
from easybuild.tools.environment import restore_env
from easybuild.tools.filetools import find_easyconfigs, is_patch_file, read_file, resolve_path, which, write_file
from easybuild.tools.github import fetch_easyconfigs_from_pr, download_repo
from easybuild.tools.modules import modules_tool
from easybuild.tools.multidiff import multidiff
from easybuild.tools.ordereddict import OrderedDict
from easybuild.tools.toolchain import DUMMY_TOOLCHAIN_NAME
Expand Down Expand Up @@ -204,16 +203,17 @@ def mk_node_name(spec):
# build directed graph
dgr = digraph()
dgr.add_nodes(all_nodes)
edge_attrs = [('style', 'dotted'), ('color', 'blue'), ('arrowhead', 'diamond')]
for spec in specs:
for dep in spec['ec'].all_dependencies:
dgr.add_edge((spec['module'], dep))
if dep in spec['ec'].build_dependencies:
dgr.add_edge_attributes((spec['module'], dep), attrs=[('style','dotted'), ('color','blue'), ('arrowhead','diamond')])
dgr.add_edge_attributes((spec['module'], dep), attrs=edge_attrs)

_dep_graph_dump(dgr, filename)

if not build_option('silent'):
print "Wrote dependency graph for %d easyconfigs to %s" % (len(specs), filename)
print("Wrote dependency graph for %d easyconfigs to %s" % (len(specs), filename))


@only_if_module_is_available('pygraph.readwrite.dot', pkgname='python-graph-dot')
Expand Down
10 changes: 5 additions & 5 deletions easybuild/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,20 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):
close_pr(options.close_pr, reasons=options.close_pr_msg)

elif options.list_prs:
print list_prs(options.list_prs)
print(list_prs(options.list_prs))

elif options.merge_pr:
merge_pr(options.merge_pr)

elif options.review_pr:
print review_pr(pr=options.review_pr, colored=use_color(options.color))
print(review_pr(pr=options.review_pr, colored=use_color(options.color)))

elif options.list_installed_software:
detailed = options.list_installed_software == 'detailed'
print list_software(output_format=options.output_format, detailed=detailed, only_installed=True)
print(list_software(output_format=options.output_format, detailed=detailed, only_installed=True))

elif options.list_software:
print list_software(output_format=options.output_format, detailed=options.list_software == 'detailed')
print(list_software(output_format=options.output_format, detailed=options.list_software == 'detailed'))

# non-verbose cleanup after handling GitHub integration stuff or printing terse info
early_stop_options = [
Expand Down Expand Up @@ -373,7 +373,7 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None):
new_pr(categorized_paths, ordered_ecs, title=options.pr_title, descr=options.pr_descr,
commit_msg=options.pr_commit_msg)
elif options.preview_pr:
print review_pr(paths=determined_paths, colored=use_color(options.color))
print(review_pr(paths=determined_paths, colored=use_color(options.color)))
else:
update_pr(options.update_pr, categorized_paths, ordered_ecs, commit_msg=options.pr_commit_msg)

Expand Down
12 changes: 6 additions & 6 deletions easybuild/scripts/add_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def write_header(filename, header, skip=None):
inpt = inpt[1:]

if skip and inpt and skip.match(''.join(inpt)): # skip matches, so skip this file
print "Skip regexp '%s' matches in %s, so skipping this file." % (skip.pattern, filename)
print("Skip regexp '%s' matches in %s, so skipping this file." % (skip.pattern, filename))
return

output.extend(header) # add the header
Expand All @@ -72,31 +72,31 @@ def write_header(filename, header, skip=None):
f = open(filename, 'w')
f.writelines(output)
f.close()
print "added header to %s" % filename
print("added header to %s" % filename)
except IOError as err:
print "something went wrong trying to add header to %s: %s" % (filename, err)
print("something went wrong trying to add header to %s: %s" % (filename, err))

def add_header(directory, header, skipreg, filenamereg, dirregex):
"""
recursively adds a header to all files in a dir
arguments: see module docstring
"""
listing = os.listdir(directory)
print "listing: %s " % listing
print("listing: %s " % listing)
# for each file/dir in this dir
for i in listing:
# get the full name, this way subsubdirs with the same name don't get ignored
fullfn = os.path.join(os.path.abspath(directory), i)
basefn = os.path.basename(fullfn)
if os.path.isdir(fullfn): # if dir, recursively go in
if (dirregex.match(basefn)):
print "going into %s" % fullfn
print("going into %s" % fullfn)
add_header(fullfn, header, skipreg, filenamereg, dirregex)
else:
if (filenamereg.match(basefn)): # if file matches file regex, write the header
write_header(fullfn, header, skipreg)
else:
print "Skipping file %s, doesn't match file regexp %s" % (fullfn, filenamereg.pattern)
print("Skipping file %s, doesn't match file regexp %s" % (fullfn, filenamereg.pattern))


def main(arguments):
Expand Down
3 changes: 1 addition & 2 deletions easybuild/scripts/fix_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import sys

from easybuild.tools.build_log import EasyBuildError
from vsc.utils.generaloption import simple_option

if not len(sys.argv) > 1:
raise EasyBuildError("Please include path to easybuild folder")
Expand All @@ -52,7 +51,7 @@
py_files.append(os.path.join(basename, fn))

for tmp in py_files:
print "Processing %s" % tmp
print("Processing %s" % tmp)
# exclude self
if os.path.basename(tmp) == os.path.basename(__file__):
continue
Expand Down
4 changes: 2 additions & 2 deletions easybuild/scripts/mk_tmpl_easyblock_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
sys.exit(1)

name = args[0]
print "Template easyblock for %s requested..." % name
print("Template easyblock for %s requested..." % name)

# check whether easyblock repository path is found
easyblocks_repo_path = os.path.join(options.path, "easybuild", "easyblocks")
Expand Down Expand Up @@ -221,7 +221,7 @@ def make_module_extra(self):
'parent': options.parent,
}

print "Writing template easyblock for %s to %s ..." % (name, easyblock_path)
print("Writing template easyblock for %s to %s ..." % (name, easyblock_path))
try:
dirpath = os.path.dirname(easyblock_path)
if not os.path.exists(dirpath):
Expand Down
18 changes: 9 additions & 9 deletions easybuild/scripts/prep_for_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ def get_last_git_version_tag(home):
def check_version(easybuild_version, last_version_git_tag):
"""Check whether version has been bumped."""

print "Current %s version: %s" % (easybuild_package, easybuild_version)
print "Last git version tag: %s " % last_version_git_tag
print("Current %s version: %s" % (easybuild_package, easybuild_version))
print("Last git version tag: %s " % last_version_git_tag)

if not easybuild_version == last_version_git_tag:
warning("Current %s version %s does not match last git version tag %s." % (easybuild_package,
easybuild_version,
last_version_git_tag))
return False
else:
print "Version checks passed."
print("Version checks passed.")

return True

Expand All @@ -141,7 +141,7 @@ def check_release_notes(home, easybuild_version):
ver_re = re.compile(r"^v%s\s\([A-Z][a-z]+\s[0-9]+[a-z]+\s[0-9]+\)$" % easybuild_version, re.M)

if ver_re.search(releasenotes):
print "Found entry in %s for version %s." % (fn, easybuild_version)
print("Found entry in %s for version %s." % (fn, easybuild_version))
return True
else:
warning("Could not find an entry for version %s in %s." % (easybuild_version, fn))
Expand Down Expand Up @@ -198,13 +198,13 @@ def check_clean_master_branch(home):
warning("Make sure you're on the master branch when running this script.")
ok = False
else:
print "On master branch, good."
print("On master branch, good.")

if not clean_re.search(git_status):
warning("There seems to be work present that's not committed yet, please make sure the master branch is clear!")
ok = False
else:
print "Current branch is clean, great work!"
print("Current branch is clean, great work!")

return ok

Expand Down Expand Up @@ -248,7 +248,7 @@ def check_easyblocks_for_environment(home):
easybuild_home = os.getcwd()
easybuild_package = os.path.basename(easybuild_home)

print "Found %s home: %s (current dir)" % (easybuild_package, easybuild_home)
print("Found %s home: %s (current dir)" % (easybuild_package, easybuild_home))

all_checks = []

Expand All @@ -269,9 +269,9 @@ def check_easyblocks_for_environment(home):
# only paths that don't have subdirs that start with '.'
dirname_re = re.compile(r"^((?!\.).)*$")

print "Checking for license header in all code files..."
print("Checking for license header in all code files...")
all_checks.append(check_license_headers(easybuild_home, license_header_re, filename_re, dirname_re))
print "Done!"
print("Done!")

# check for clean master branch
all_checks.append(check_clean_master_branch(easybuild_home))
Expand Down
4 changes: 2 additions & 2 deletions easybuild/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,8 @@ def det_patch_specs(patch_paths, file_info):
patch_specs.append((patch_path, soft_name))
else:
# fall back on scanning all eb files for patches
print "Matching easyconfig for %s not found on the first try:" % patch_path,
print "scanning all easyconfigs to determine where patch file belongs (this may take a while)..."
print("Matching easyconfig for %s not found on the first try:" % patch_path,)
print("scanning all easyconfigs to determine where patch file belongs (this may take a while)...")
soft_name = find_software_name_for_patch(patch_file)
if soft_name:
patch_specs.append((patch_path, soft_name))
Expand Down
2 changes: 1 addition & 1 deletion easybuild/tools/jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ def aggregate_xml_in_dirs(base_dir, output_filename):
except IOError as err:
raise EasyBuildError("Failed to write out XML file %s: %s", output_filename, err)

print "Aggregate regtest results written to %s" % output_filename
print("Aggregate regtest results written to %s" % output_filename)
2 changes: 1 addition & 1 deletion easybuild/tools/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ def run_module(self, *args, **kwargs):
tweak_fn = kwargs.get('tweak_stdout')
if tweak_fn is not None:
stdout = tweak_fn(stdout)
exec stdout
exec(stdout)
except Exception as err:
out = "stdout: %s, stderr: %s" % (stdout, stderr)
raise EasyBuildError("Changing environment as dictated by module failed: %s (%s)", err, out)
Expand Down
4 changes: 2 additions & 2 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def pretty_print_opts(opts_dict):
opt_val, loc = opts_dict[opt]
lines.append("{0:<{nwopt}} ({1:}) = {2:}".format(opt, loc, opt_val, nwopt=nwopt))

print '\n'.join(lines)
print('\n'.join(lines))


def use_color(colorize, stream=sys.stdout):
Expand Down Expand Up @@ -1040,7 +1040,7 @@ def _postprocess_list_avail(self):
if self.options.unittest_file:
self.log.info(msg)
else:
print msg
print(msg)

# cleanup tmpdir and exit
cleanup_and_exit(self.tmpdir)
Expand Down
2 changes: 1 addition & 1 deletion easybuild/tools/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,4 @@ def search_easyconfigs(query, short=False, filename_only=False, terse=False):
"Note: %d matching archived easyconfig(s) found, use --consider-archived-easyconfigs to see them" % cnt,
])

print '\n'.join(lines)
print('\n'.join(lines))
4 changes: 0 additions & 4 deletions test/framework/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from unittest import TextTestRunner

import easybuild.framework.easyconfig.easyconfig as ecec
import easybuild.framework.easyconfig.tools as ectools
import easybuild.tools.build_log
import easybuild.tools.robot as robot
from easybuild.framework.easyconfig.easyconfig import process_easyconfig, EasyConfig
Expand All @@ -64,7 +63,6 @@

ORIG_MODULES_TOOL = modules.modules_tool
ORIG_ECEC_MODULES_TOOL = ecec.modules_tool
ORIG_ECTOOLS_MODULES_TOOL = ectools.modules_tool
ORIG_MODULE_FUNCTION = os.environ.get('module', None)


Expand Down Expand Up @@ -103,7 +101,6 @@ def install_mock_module(self):
"""Install MockModule as modules tool."""
# replace Modules class with something we have control over
config.modules_tool = mock_module
ectools.modules_tool = mock_module
ecec.modules_tool = mock_module
robot.modules_tool = mock_module
os.environ['module'] = "() { eval `/bin/echo $*`\n}"
Expand All @@ -125,7 +122,6 @@ def tearDown(self):

# restore original modules tool, it may have been tampered with
config.modules_tool = ORIG_MODULES_TOOL
ectools.modules_tool = ORIG_ECTOOLS_MODULES_TOOL
ecec.modules_tool = ORIG_ECEC_MODULES_TOOL
if ORIG_MODULE_FUNCTION is None:
if 'module' in os.environ:
Expand Down

0 comments on commit fbcab5c

Please sign in to comment.