diff --git a/script/actions_utils/coverage_report_format.py b/script/actions_utils/coverage_report_format.py index 443ea1f95..a0609b876 100755 --- a/script/actions_utils/coverage_report_format.py +++ b/script/actions_utils/coverage_report_format.py @@ -12,7 +12,7 @@ def main(args): diff_cover_content = None - with open(diff_cover_file_path, "r") as f: + with open(diff_cover_file_path, "r", encoding="utf-8") as f: diff_cover_content = f.readlines() with open(diff_cover_file_path, "w", encoding="utf-8") as f: diff --git a/script/nbmake_utils/notebook_sanitize.py b/script/nbmake_utils/notebook_sanitize.py index 4dc48b6b7..c26ee33f5 100644 --- a/script/nbmake_utils/notebook_sanitize.py +++ b/script/nbmake_utils/notebook_sanitize.py @@ -1,9 +1,11 @@ +"""Sanitizer for Jupyter notebooks.""" import argparse import json from pathlib import Path def main(): + """Sanitize""" parser = argparse.ArgumentParser(description="Sanitizer for Jupyter Notebooks") parser.add_argument("base", type=str, help="directory which contains the notebooks") @@ -15,16 +17,16 @@ def main(): notebooks = base.glob("*.ipynb") for notebook in notebooks: - with open(notebook, "r") as f: + with open(notebook, "r", encoding="utf-8") as f: content = json.load(f) if args.check: if len(content["metadata"]) != 0: print("Notebooks are not sanitized. Please run `make conformance`.") - exit(1) + raise ValueError else: content["metadata"] = {} - with open(notebook, "w", newline="\n") as f: + with open(notebook, "w", newline="\n", encoding="utf-8") as f: json.dump(content, f, indent=1, ensure_ascii=False) f.write("\n") diff --git a/script/progress_tracker_utils/extract_machine_info.py b/script/progress_tracker_utils/extract_machine_info.py index ea05b8025..c8bd4e5df 100644 --- a/script/progress_tracker_utils/extract_machine_info.py +++ b/script/progress_tracker_utils/extract_machine_info.py @@ -1,3 +1,4 @@ +"""Extract some info about the host machine.""" import json import os import platform @@ -9,6 +10,7 @@ import psutil def main(): + """Extract some info about the host machine.""" dotenv.load_dotenv() properties = [] @@ -43,7 +45,7 @@ def main(): id_ = urllib.parse.quote_plus(id_) machine = {"id": id_, "name": name, "properties": properties} - with open(".benchmarks/machine.json", "w") as f: + with open(".benchmarks/machine.json", "w", encoding="utf-8") as f: json.dump(machine, f, indent=2, ensure_ascii=False) diff --git a/script/progress_tracker_utils/measure.py b/script/progress_tracker_utils/measure.py index e263f4a12..1b6116a13 100644 --- a/script/progress_tracker_utils/measure.py +++ b/script/progress_tracker_utils/measure.py @@ -1,3 +1,4 @@ +"""Measurement script for the progress tracker""" import argparse import json import os @@ -99,7 +100,7 @@ def identify_metrics(script, lines, metrics): def create_modified_script(script_without_extension, lines, metrics): """Create a modified version of the script which can be used to perform measurements""" - with open(f"{script_without_extension}.measure.py", "w") as f: + with open(f"{script_without_extension}.measure.py", "w", encoding="utf-8") as f: # Import must-have libraries f.write("import json\n") f.write("import time\n") @@ -181,6 +182,7 @@ def perform_measurements(script, script_without_extension, target_id, metrics, s process = subprocess.run( ["python", f"{script_without_extension}.measure.py"], capture_output=True, + check=True, ) # Print sample information @@ -203,7 +205,7 @@ def perform_measurements(script, script_without_extension, target_id, metrics, s break # Read the measurements and delete the temporary file - with open(f"{script_without_extension}.measurements") as f: + with open(f"{script_without_extension}.measurements", encoding="utf-8") as f: results = json.load(f) os.unlink(f"{script_without_extension}.measurements") @@ -237,6 +239,7 @@ def perform_measurements(script, script_without_extension, target_id, metrics, s def main(): + """Measurement script for the progress tracker""" parser = argparse.ArgumentParser(description="Measurement script for the progress tracker") parser.add_argument("base", type=str, help="directory which contains the benchmarks") @@ -248,7 +251,7 @@ def main(): base = pathlib.Path(args.base) samples = args.samples - with open(".benchmarks/machine.json", "r") as f: + with open(".benchmarks/machine.json", "r", encoding="utf-8") as f: machine = json.load(f) result = {"machine": machine, "metrics": {}, "targets": {}} @@ -257,7 +260,7 @@ def main(): # Process each script under the base directory for script in filter(lambda script: not str(scripts[0]).endswith("measure.py"), scripts): # Read the script line by line - with open(script, "r") as f: + with open(script, "r", encoding="utf-8") as f: lines = f.readlines() # Find the first non-empty line @@ -309,7 +312,7 @@ def main(): perform_measurements(script, script_without_extension, target_id, metrics, samples, result) # Dump the latest results to the output file - with open(".benchmarks/findings.json", "w") as f: + with open(".benchmarks/findings.json", "w", encoding="utf-8") as f: json.dump(result, f, indent=2, ensure_ascii=False) # Delete the modified script if the user doesn't care