Newer versions of Pylint warn about this.
log.info(f"SHA256 summing {path}")
check = Path(f"{path}.sha256")
- with open(check, "wt") as f:
+ with open(check, "wt", encoding="utf-8") as f:
with open(path, "rb") as data:
f.write(f"{hashlib.sha256(data.read()).hexdigest()} {path}\n")
return check
# echo some useful things for debugging
log.info(f"os.uname(): {os.uname()}")
if Path("/etc/os-release").exists():
- with open("/etc/os-release") as f:
+ with open("/etc/os-release", "rt", encoding="utf-8") as f:
log.info("/etc/os-release:")
for i, line in enumerate(f, 1):
log.info(f" {i}: {line[:-1]}")
# retrieve version name left by prior CI tasks
log.info("reading GRAPHVIZ_VERSION")
- with open("GRAPHVIZ_VERSION") as f:
+ with open("GRAPHVIZ_VERSION", "rt", encoding="utf-8") as f:
gv_version = f.read().strip()
log.info(f"GRAPHVIZ_VERSION == {gv_version}")
# output JSON data for the website
log.info(f"dumping {webdata} to graphviz-{options.version}.json")
- with open(f"graphviz-{options.version}.json", "wt") as f:
+ with open(f"graphviz-{options.version}.json", "wt", encoding="utf-8") as f:
json.dump(webdata, f, indent=2)
return 0
platform = f"{os_id.capitalize()} {os_version_id}"
if platform not in platforms:
platforms.append(platform)
- with open(filename, "rt") as fp:
+ with open(filename, "rt", encoding="utf-8") as fp:
for line in fp.readlines():
item = [item.strip() for item in line.split(":")]
if len(item) == 2:
src = Path(tmp) / "input.dot"
# write our test input to a file
- with open(src, "wt") as f:
+ with open(src, "wt", encoding="utf-8") as f:
g.serialize(f)
# process this graph
returncode = 0 if filecmp.cmp(TMPFILE1, TMPFILE2) else -1
elif F == "svg":
- with open(FILE1) as f:
+ with open(FILE1, "rt", encoding="utf-8") as f:
a = re.sub(r"^<!--.*-->$", "", f.read(), flags=re.MULTILINE)
- with open(FILE2) as f:
+ with open(FILE2, "rt", encoding="utf-8") as f:
b = re.sub(r"^<!--.*-->$", "", f.read(), flags=re.MULTILINE)
returncode = 0 if a.strip() == b.strip() else -1
elif F == "png":
[DIFFIMG, FILE1, FILE2, os.path.join(OUTHTML, f"dif_{OUTFILE}")],
)
if returncode != 0:
- with open(os.path.join(OUTHTML, "index.html"), mode="a") as fd:
+ with open(os.path.join(OUTHTML, "index.html"), "at", encoding="utf-8") as fd:
fd.write("<p>\n")
shutil.copyfile(FILE2, os.path.join(OUTHTML, f"old_{OUTFILE}"))
fd.write(f'<img src="old_{OUTFILE}" width="192" height="192">\n')
else:
os.unlink(os.path.join(OUTHTML, f"dif_{OUTFILE}"))
else:
- with open(FILE2) as a:
- with open(FILE1) as b:
+ with open(FILE2, "rt", encoding="utf-8") as a:
+ with open(FILE1, "rt", encoding="utf-8") as b:
returncode = 0 if a.read().strip() == b.read().strip() else -1
if returncode != 0:
print(f"Test {testname}:{subtest_index} : == Failed == {OUTFILE}", file=sys.stderr)
if GRAPH == "=":
INFILE = os.path.join(GRAPHDIR, f"{TESTNAME}.gv")
elif GRAPH.startswith("graph") or GRAPH.startswith("digraph"):
- with open(TMPINFILE, mode="w") as fd:
+ with open(TMPINFILE, mode="wt", encoding="utf-8") as fd:
fd.write(GRAPH)
INFILE = TMPINFILE
elif os.path.splitext(GRAPH)[1] == ".gv":
# sys.exit(1)
-f3 = open(TESTFILE)
+f3 = open(TESTFILE, "rt", encoding="utf-8")
while True:
TEST = readTest()
if TEST is None:
with tempfile.TemporaryDirectory() as tmp:
# write a dummy config.h to allow standalone compilation
- with open(Path(tmp) / "config.h", "wt") as _:
+ with open(Path(tmp) / "config.h", "wt", encoding="utf-8") as _:
pass
# compile the stub to something we can run
import gv # pylint: disable=import-error
-modules = open("/proc/modules", "r").readlines()
+modules = open("/proc/modules", "rt", encoding="utf-8").readlines()
G = gv.digraph("G")
N = gv.protonode(G)
subprocess.check_call(["diffimg", ref, output])
else:
fail = False
- with open(ref, 'rt') as a:
- with open(output, 'rt') as b:
+ with open(ref, "rt", encoding="utf-8") as a:
+ with open(output, "rt", encoding="utf-8") as b:
for line in difflib.unified_diff(a.read(), b.read(),
fromfile=str(ref),
tofile=str(output)):
print(f"Failure: {filename} - No reference file present.")
return False
- with open(filename_reference) as reference_file:
- with open(filename_output) as output_file:
+ with open(filename_reference, "rt", encoding="utf-8") as reference_file:
+ with open(filename_output, "rt", encoding="utf-8") as output_file:
reference = reference_file.readlines()
output = output_file.readlines()
diff_generator = difflib.context_diff(output, reference,
print(line)
# Store diff in file
- with open(f"difference/{str(filename)}", "w") as diff_file:
+ with open(f"difference/{str(filename)}", "wt",
+ encoding="utf-8") as diff_file:
diff_file.writelines(diff)
print(f"Failure: {filename} - Generated file does not match reference file.")
# Remove the number in "Generated by graphviz version <number>"
# to able to compare the output to the reference. This version
# number is different for every Graphviz compilation.
- file = open(output_file, "r")
+ file = open(output_file, "rt", encoding="utf-8")
lines = file.readlines()
file.close()
- file = open(output_file, "w")
+ file = open(output_file, "wt", encoding="utf-8")
for line in lines:
if "<!-- Generated by graphviz version " in line:
file.write("<!-- Generated by graphviz version\n")
# Remove the number in "Generated by graphviz version <number>"
# to able to compare the output to the reference. This version
# number is different for every Graphviz compilation.
- file = open(output_file, "r")
+ file = open(output_file, "rt", encoding="utf-8")
lines = file.readlines()
file.close()
- file = open(output_file, "w")
+ file = open(output_file, "wt", encoding="utf-8")
for line in lines:
if "<!-- Generated by graphviz version " in line:
file.write("<!-- Generated by graphviz version\n")