Cleanup with ruff check (#1182)

* Implement improvements suggested by ruff check.

* Add ruff check to CI.
This commit is contained in:
Felix Fontein
2025-10-28 06:58:15 +01:00
committed by GitHub
parent 3bade286f8
commit dbc7b0ec18
40 changed files with 247 additions and 232 deletions
@@ -36,15 +36,14 @@ def write_imitation_archive(
def write_imitation_archive_with_manifest(
file_name: str, manifest: list[dict[str, t.Any]]
) -> None:
with tarfile.open(file_name, "w") as tf:
with TemporaryFile() as f:
f.write(json.dumps(manifest).encode("utf-8"))
with tarfile.open(file_name, "w") as tf, TemporaryFile() as f:
f.write(json.dumps(manifest).encode("utf-8"))
ti = tarfile.TarInfo("manifest.json")
ti.size = f.tell()
ti = tarfile.TarInfo("manifest.json")
ti.size = f.tell()
f.seek(0)
tf.addfile(ti, f)
f.seek(0)
tf.addfile(ti, f)
def write_irrelevant_tar(file_name: str) -> None:
@@ -55,12 +54,11 @@ def write_irrelevant_tar(file_name: str) -> None:
:type file_name: str
"""
with tarfile.open(file_name, "w") as tf:
with TemporaryFile() as f:
f.write("Hello, world.".encode("utf-8"))
with tarfile.open(file_name, "w") as tf, TemporaryFile() as f:
f.write("Hello, world.".encode("utf-8"))
ti = tarfile.TarInfo("hi.txt")
ti.size = f.tell()
ti = tarfile.TarInfo("hi.txt")
ti.size = f.tell()
f.seek(0)
tf.addfile(ti, f)
f.seek(0)
tf.addfile(ti, f)