From c5a8d1b927dc4a5faf2f11597c1a9258641224fa Mon Sep 17 00:00:00 2001 From: CentOS CI Date: Oct 31 2019 20:07:16 +0000 Subject: Reformat python code with black Signed-off-by: CentOS CI --- diff --git a/tests/compare_defaults.py b/tests/compare_defaults.py index 5b1d9b9..742046b 100755 --- a/tests/compare_defaults.py +++ b/tests/compare_defaults.py @@ -6,36 +6,41 @@ import os import sys from gi.repository import GLib -gi.require_version('Modulemd', '2.0') + +gi.require_version("Modulemd", "2.0") from gi.repository import Modulemd + def print_failure(failure): print("Error: %s" % failure.get_gerror()) print("Offending YAML: \n%s" % failure.get_yaml()) + def unusable_baseline(): print("Baseline was unusable. Skipping test.") return os.EX_OK -def get_index_and_defaults (repo, filename, commit): + +def get_index_and_defaults(repo, filename, commit): try: - yaml = repo.git.show('%s:%s' % (commit, filename)) + yaml = repo.git.show("%s:%s" % (commit, filename)) except git.exc.GitCommandError as e: # This file didn't exist in the commit, so return # FileNotFoundError to skip checking it. - raise FileNotFoundError("{} does not exist at commit {}".format(filename, commit)) - + raise FileNotFoundError( + "{} does not exist at commit {}".format(filename, commit) + ) index = Modulemd.ModuleIndex.new() try: ret, failures = index.update_from_string(yaml, True) if ret != True: for failure in failures: - print_failure (failure) + print_failure(failure) raise IOError("Invalid modulemd-defaults document") except gi.repository.GLib.Error as e: - print ("Error: %s" % e) + print("Error: %s" % e) raise IOError("Invalid YAML document") module_names = index.get_module_names() @@ -50,6 +55,7 @@ def get_index_and_defaults (repo, filename, commit): return index, defaults + def main(): filename = sys.argv[1] baseline_commit = sys.argv[2] @@ -57,13 +63,13 @@ def main(): script_dir = os.path.dirname(os.path.realpath(__file__)) - repo = git.Repo(script_dir, - search_parent_directories=True) + repo = git.Repo(script_dir, search_parent_directories=True) # First get the defaults from the baseline commit try: - baseline_index, baseline_defaults = get_index_and_defaults ( - repo, filename, baseline_commit) + baseline_index, baseline_defaults = get_index_and_defaults( + repo, filename, baseline_commit + ) except FileNotFoundError as e: # The baseline file didn't exist, so there's no valid original # to compare to. Check it only with validate.py. @@ -78,11 +84,17 @@ def main(): try: updated_commit = updated_commit - updated_index, updated_defaults = get_index_and_defaults ( - repo, filename, updated_commit) + updated_index, updated_defaults = get_index_and_defaults( + repo, filename, updated_commit + ) except FileNotFoundError as e: # The PR is removing this file. Assume that this is acceptable - print("{} is being removed. Not performing any comparison tests.".format(filename), file=sys.stderr) + print( + "{} is being removed. Not performing any comparison tests.".format( + filename + ), + file=sys.stderr, + ) return os.EX_OK except IOError as e: # If we hit this, the patch is broken. @@ -90,10 +102,12 @@ def main(): return os.EX_DATAERR if updated_defaults.get_modified() <= baseline_defaults.get_modified(): - print ("%s has changed but the 'modified' field has not increased." % - filename) - print ("Baseline modified: {}".format(baseline_defaults.get_modified())) - print ("Updated modified: {}".format(updated_defaults.get_modified())) + print( + "%s has changed but the 'modified' field has not increased." + % filename + ) + print("Baseline modified: {}".format(baseline_defaults.get_modified())) + print("Updated modified: {}".format(updated_defaults.get_modified())) return os.EX_DATAERR # Confirm that these two sets of defaults merge cleanly @@ -104,11 +118,11 @@ def main(): try: merger.resolve() except gi.repository.GLib.Error as e: - print ("Merge Error: %s" % e, file=sys.stderr) + print("Merge Error: %s" % e, file=sys.stderr) return os.EX_DATAERR return os.EX_OK + if __name__ == "__main__": sys.exit(main()) - diff --git a/tests/validate.py b/tests/validate.py index 6abc13c..680d0c6 100755 --- a/tests/validate.py +++ b/tests/validate.py @@ -9,7 +9,8 @@ import logging from logging import error, info from gi.repository import GLib -gi.require_version('Modulemd', '2.0') + +gi.require_version("Modulemd", "2.0") from gi.repository import Modulemd # noqa logging.getLogger().setLevel(logging.INFO) @@ -18,9 +19,11 @@ logging.getLogger().setLevel(logging.INFO) def do_validate(filename): # Valid filenames must end in ".yaml" to be properly included by Pungi if not filename.endswith(".yaml"): - error("{} does not end with .yaml. It will not be included by " - "Pungi. If this file does not contain defaults, it should " - "be added to the tests/exclusions.txt file.".format(filename)) + error( + "{} does not end with .yaml. It will not be included by " + "Pungi. If this file does not contain defaults, it should " + "be added to the tests/exclusions.txt file.".format(filename) + ) return False, None # The files must parse correctly @@ -33,8 +36,11 @@ def do_validate(filename): if failures: for failure in failures: - error("Failed subdocument ({}): \n{}\n".format(failure.get_gerror().message, - failure.get_yaml())) + error( + "Failed subdocument ({}): \n{}\n".format( + failure.get_gerror().message, failure.get_yaml() + ) + ) return False, None # There must be exactly one object per file @@ -48,7 +54,11 @@ def do_validate(filename): defaults = module.get_defaults() if defaults is None: - error("No defaults document provided for {}".format(module.props.module_name)) + error( + "No defaults document provided for {}".format( + module.props.module_name + ) + ) return False, None # The files must not contain any streams @@ -57,18 +67,25 @@ def do_validate(filename): return False, None # Filenames must match their contents - expected_name = os.path.basename(filename).rsplit('.', maxsplit=1)[0] + expected_name = os.path.basename(filename).rsplit(".", maxsplit=1)[0] if expected_name != defaults.props.module_name: - error("Module name \"{}\" doesn't match filename \"{}.yaml\"".format( - defaults.props.module_name, expected_name)) + error( + 'Module name "{}" doesn\'t match filename "{}.yaml"'.format( + defaults.props.module_name, expected_name + ) + ) return False, None default_stream = defaults.get_default_stream() if default_stream: # Default streams must also appear in the profiles list if not defaults.get_default_profiles_for_stream(default_stream): - error("Stream '{}' is missing from the profiles for '{}'".format(default_stream, defaults.get_module_name())) + error( + "Stream '{}' is missing from the profiles for '{}'".format( + default_stream, defaults.get_module_name() + ) + ) return False, None # Modules in Fedora must not specify "Intents" @@ -87,8 +104,7 @@ def main(): script_dir = os.path.dirname(os.path.realpath(__file__)) # Get the repo we're running in - repo = git.Repo(script_dir, - search_parent_directories=True) + repo = git.Repo(script_dir, search_parent_directories=True) # Get the list of files in this repository files = [x for (x, y) in repo.index.entries.keys()] @@ -108,7 +124,7 @@ def main(): for file in files: excluded = False for excl in exclusions: - if (file.startswith(excl)): + if file.startswith(excl): excluded = True break if not excluded: @@ -120,8 +136,11 @@ def main(): try: merger.associate_index(idx, 0) except GLib.Error as e: - error("Could not merge {} with other defaults: {}".format( - file, e.message)) + error( + "Could not merge {} with other defaults: {}".format( + file, e.message + ) + ) result = os.EX_DATAERR if result == os.EX_DATAERR: @@ -139,8 +158,8 @@ def main(): if result == os.EX_OK: info("Merging all of the documents encountered no errors.") - return result + if __name__ == "__main__": sys.exit(main())