From e0dedf2e83fad25d80786bc7b38d4bcd3d629c2d Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Fri, 11 Jan 2019 19:48:05 +0100 Subject: [PATCH 1/2] make all print statements compatible with Python 3 --- easybuild/framework/easyconfig/tools.py | 6 +++--- easybuild/main.py | 10 +++++----- easybuild/scripts/add_header.py | 12 ++++++------ easybuild/scripts/fix_docs.py | 3 +-- easybuild/scripts/mk_tmpl_easyblock_for.py | 4 ++-- easybuild/scripts/prep_for_release.py | 18 +++++++++--------- easybuild/tools/github.py | 4 ++-- easybuild/tools/jenkins.py | 2 +- easybuild/tools/modules.py | 2 +- easybuild/tools/options.py | 4 ++-- easybuild/tools/robot.py | 2 +- 11 files changed, 33 insertions(+), 34 deletions(-) diff --git a/easybuild/framework/easyconfig/tools.py b/easybuild/framework/easyconfig/tools.py index c8da6e9011..e87cc40142 100644 --- a/easybuild/framework/easyconfig/tools.py +++ b/easybuild/framework/easyconfig/tools.py @@ -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 @@ -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') diff --git a/easybuild/main.py b/easybuild/main.py index cc0506cd6f..7a8f80c174 100644 --- a/easybuild/main.py +++ b/easybuild/main.py @@ -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 = [ @@ -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) diff --git a/easybuild/scripts/add_header.py b/easybuild/scripts/add_header.py index 997f44a180..0ea71fac07 100644 --- a/easybuild/scripts/add_header.py +++ b/easybuild/scripts/add_header.py @@ -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 @@ -72,9 +72,9 @@ 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): """ @@ -82,7 +82,7 @@ def add_header(directory, header, skipreg, filenamereg, dirregex): 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 @@ -90,13 +90,13 @@ def add_header(directory, header, skipreg, filenamereg, dirregex): 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): diff --git a/easybuild/scripts/fix_docs.py b/easybuild/scripts/fix_docs.py index ecf0313ad8..90a9970ef4 100644 --- a/easybuild/scripts/fix_docs.py +++ b/easybuild/scripts/fix_docs.py @@ -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") @@ -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 diff --git a/easybuild/scripts/mk_tmpl_easyblock_for.py b/easybuild/scripts/mk_tmpl_easyblock_for.py index 7cf73fcbf6..1c04a77de1 100644 --- a/easybuild/scripts/mk_tmpl_easyblock_for.py +++ b/easybuild/scripts/mk_tmpl_easyblock_for.py @@ -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") @@ -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): diff --git a/easybuild/scripts/prep_for_release.py b/easybuild/scripts/prep_for_release.py index 36134997bf..44ec91a8b7 100644 --- a/easybuild/scripts/prep_for_release.py +++ b/easybuild/scripts/prep_for_release.py @@ -113,8 +113,8 @@ 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, @@ -122,7 +122,7 @@ def check_version(easybuild_version, last_version_git_tag): last_version_git_tag)) return False else: - print "Version checks passed." + print("Version checks passed.") return True @@ -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)) @@ -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 @@ -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 = [] @@ -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)) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index 2ca5e36234..52b66489cb 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -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)) diff --git a/easybuild/tools/jenkins.py b/easybuild/tools/jenkins.py index fdae43c641..1bfbf1822d 100644 --- a/easybuild/tools/jenkins.py +++ b/easybuild/tools/jenkins.py @@ -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) diff --git a/easybuild/tools/modules.py b/easybuild/tools/modules.py index f50e7ac79c..49d973a044 100644 --- a/easybuild/tools/modules.py +++ b/easybuild/tools/modules.py @@ -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) diff --git a/easybuild/tools/options.py b/easybuild/tools/options.py index cad0209fc4..5c0fa05ccd 100644 --- a/easybuild/tools/options.py +++ b/easybuild/tools/options.py @@ -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): @@ -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) diff --git a/easybuild/tools/robot.py b/easybuild/tools/robot.py index 17b3f8f3a4..0ffba0d733 100644 --- a/easybuild/tools/robot.py +++ b/easybuild/tools/robot.py @@ -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)) From ce263ab55b6f4acfc66cfe16ba46f4c3782284c7 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Fri, 11 Jan 2019 21:29:10 +0100 Subject: [PATCH 2/2] fix robot tests after unused modules_tool import was removed in easybuild/framework/easyconfig/tools.py --- test/framework/robot.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/framework/robot.py b/test/framework/robot.py index 3caae76210..5b6f929d07 100644 --- a/test/framework/robot.py +++ b/test/framework/robot.py @@ -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 @@ -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) @@ -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}" @@ -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: