From 44c28c8c16ac64370ec500286e3fe04d45c5ccc8 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 7 Aug 2023 10:08:32 -0700 Subject: [PATCH] autopep8: Update with changes to make autopep8 -a -a -a happy --- devices/org.osbuild.lvm2.lv | 2 +- osbuild/loop.py | 4 ++-- osbuild/main_cli.py | 9 +++++-- osbuild/meta.py | 4 ++-- osbuild/util/fscache.py | 4 ++-- osbuild/util/jsoncomm.py | 4 ++-- osbuild/util/lorax.py | 4 ++-- osbuild/util/lvm2.py | 6 ++--- stages/org.osbuild.authconfig | 2 +- stages/org.osbuild.bootiso.mono | 2 +- stages/org.osbuild.dnf.config | 2 +- stages/org.osbuild.ostree.preptree | 6 +++-- stages/org.osbuild.parted | 4 ++-- stages/org.osbuild.rpm | 2 +- stages/org.osbuild.sgdisk | 2 +- stages/org.osbuild.systemd.unit | 2 +- test/initrd.py | 4 ++-- test/mod/test_loop.py | 2 +- test/mod/test_meta.py | 4 ++-- test/mod/test_objectstore.py | 6 ++--- test/mod/test_util_fscache.py | 38 +++++++++++++++--------------- test/mod/test_util_lvm2.py | 2 +- test/run/test_mount.py | 2 +- test/run/test_sources.py | 2 +- test/run/test_stages.py | 2 +- tools/osbuild-mpp | 4 ++-- 26 files changed, 66 insertions(+), 59 deletions(-) diff --git a/devices/org.osbuild.lvm2.lv b/devices/org.osbuild.lvm2.lv index 26f3e76d..2f8fe4f4 100755 --- a/devices/org.osbuild.lvm2.lv +++ b/devices/org.osbuild.lvm2.lv @@ -127,7 +127,7 @@ class LVService(devices.DeviceService): if res.returncode == 5: if count == 10: raise RuntimeError("Could not find parent device") - time.sleep(1*count) + time.sleep(1 * count) count += 1 continue diff --git a/osbuild/loop.py b/osbuild/loop.py index a0f5e811..a9345279 100644 --- a/osbuild/loop.py +++ b/osbuild/loop.py @@ -57,7 +57,7 @@ class LoopConfig(ctypes.Structure): ('fd', ctypes.c_uint32), ('block_size', ctypes.c_uint32), ('info', LoopInfo), - ('__reserved', ctypes.c_uint64*8), + ('__reserved', ctypes.c_uint64 * 8), ] @@ -652,7 +652,7 @@ class LoopControl: if callable(setup): try: setup(lo) - except: + except BaseException: lo.close() raise diff --git a/osbuild/main_cli.py b/osbuild/main_cli.py index 031a584f..29a23286 100644 --- a/osbuild/main_cli.py +++ b/osbuild/main_cli.py @@ -69,8 +69,13 @@ def parse_arguments(sys_argv): help="directory containing stages, assemblers, and the osbuild library") parser.add_argument("--cache-max-size", metavar="SIZE", type=parse_size, default=None, help="maximum size of the cache (bytes) or 'unlimited' for no restriction") - parser.add_argument("--checkpoint", metavar="ID", action="append", type=str, default=None, - help="stage to commit to the object store during build (can be passed multiple times), accepts globs") + parser.add_argument( + "--checkpoint", + metavar="ID", + action="append", + type=str, + default=None, + help="stage to commit to the object store during build (can be passed multiple times), accepts globs") parser.add_argument("--export", metavar="ID", action="append", type=str, default=[], help="object to export, can be passed multiple times") parser.add_argument("--json", action="store_true", diff --git a/osbuild/meta.py b/osbuild/meta.py index fb23d73e..12cecb02 100644 --- a/osbuild/meta.py +++ b/osbuild/meta.py @@ -519,11 +519,11 @@ class RunnerInfo: while i > 0 and name[i].isdigit(): i -= 1 - vstr = name[i+1:] + vstr = name[i + 1:] if vstr: version = int(vstr) - return name[:i+1], version + return name[:i + 1], version class Index: diff --git a/osbuild/util/fscache.py b/osbuild/util/fscache.py index e99ae87d..29b3ce90 100644 --- a/osbuild/util/fscache.py +++ b/osbuild/util/fscache.py @@ -575,7 +575,7 @@ class FsCache(contextlib.AbstractContextManager, os.PathLike): raise return (name, lockfd) - except: + except BaseException: # On error, we might have already created the directory or even # linked the lock-file. Try unlinking both, but ignore errors if # they do not exist. Due to using UUIDs as names we cannot conflict @@ -703,7 +703,7 @@ class FsCache(contextlib.AbstractContextManager, os.PathLike): self._active = True return self - except: + except BaseException: self.__exit__(None, None, None) raise diff --git a/osbuild/util/jsoncomm.py b/osbuild/util/jsoncomm.py index 6f892202..e31a49ca 100644 --- a/osbuild/util/jsoncomm.py +++ b/osbuild/util/jsoncomm.py @@ -216,7 +216,7 @@ class Socket(contextlib.AbstractContextManager): # default destination for send operations. if connect_to is not None: sock.connect(os.fspath(connect_to)) - except: + except BaseException: if sock is not None: sock.close() raise @@ -255,7 +255,7 @@ class Socket(contextlib.AbstractContextManager): sock.bind(os.fspath(bind_to)) unlink = os.open(os.path.join(".", path[0]), os.O_CLOEXEC | os.O_PATH) sock.setblocking(False) - except: + except BaseException: if unlink is not None: os.close(unlink) if sock is not None: diff --git a/osbuild/util/lorax.py b/osbuild/util/lorax.py index abd767cf..4fa97267 100644 --- a/osbuild/util/lorax.py +++ b/osbuild/util/lorax.py @@ -177,9 +177,9 @@ def brace_expand(s): result = [] right = s.find('}') left = s[:right].rfind('{') - prefix, choices, suffix = s[:left], s[left+1:right], s[right+1:] + prefix, choices, suffix = s[:left], s[left + 1:right], s[right + 1:] for choice in choices.split(','): - result.extend(brace_expand(prefix+choice+suffix)) + result.extend(brace_expand(prefix + choice + suffix)) return result diff --git a/osbuild/util/lvm2.py b/osbuild/util/lvm2.py index 05677230..5386e0bd 100644 --- a/osbuild/util/lvm2.py +++ b/osbuild/util/lvm2.py @@ -286,7 +286,7 @@ class MDAHeader(Header): "magic": "16s", # int8_t[16] // Allows to scan for metadata "version": "L", # uint32_t "start": "Q", # uint64_t // Absolute start byte of itself - "size": "Q" # uint64_t // Size of metadata area + "size": "Q" # uint64_t // Size of metadata area }) # followed by a null termiated list of type `RawLocN` @@ -419,7 +419,7 @@ class Metadata: r"\]": " ]", r'"': ' " ', r"[=,]": "", - r"\s+": " ", + r"\s+": " ", r"\0$": "", } @@ -537,7 +537,7 @@ class Disk: try: self._init_headers() - except: # pylint: disable=broad-except + except BaseException: # pylint: disable=broad-except self.fp.close() raise diff --git a/stages/org.osbuild.authconfig b/stages/org.osbuild.authconfig index fc7536f6..b56ff7cb 100755 --- a/stages/org.osbuild.authconfig +++ b/stages/org.osbuild.authconfig @@ -25,7 +25,7 @@ SCHEMA = """ def main(tree): cmd = [ "/usr/sbin/chroot", tree, - "/usr/sbin/authconfig", "--nostart", "--updateall" + "/usr/sbin/authconfig", "--nostart", "--updateall" ] subprocess.run(cmd, check=True) diff --git a/stages/org.osbuild.bootiso.mono b/stages/org.osbuild.bootiso.mono index e0289f6b..52e6d626 100755 --- a/stages/org.osbuild.bootiso.mono +++ b/stages/org.osbuild.bootiso.mono @@ -408,7 +408,7 @@ def main(inputs, root, options, workdir, loop_client): liveos = os.path.join(liveos_work, "LiveOS") os.makedirs(liveos) - rootfs_size = rootfs.get("size", 3072) * 1024*1024 + rootfs_size = rootfs.get("size", 3072) * 1024 * 1024 compression = rootfs.get("compression", {}) rootfs = os.path.join(liveos, "rootfs.img") diff --git a/stages/org.osbuild.dnf.config b/stages/org.osbuild.dnf.config index 0ef28a5c..a3de2154 100755 --- a/stages/org.osbuild.dnf.config +++ b/stages/org.osbuild.dnf.config @@ -142,7 +142,7 @@ def make_dnf_config(tree, config_options): for section, items in config_options.items(): make_section(dnf_config, section, items) - with open(dnf_config_path, "w", encoding="utf8") as f: + with open(dnf_config_path, "w", encoding="utf8") as f: os.fchmod(f.fileno(), 0o644) dnf_config.write(f) diff --git a/stages/org.osbuild.ostree.preptree b/stages/org.osbuild.ostree.preptree index 45243002..97cc3cac 100755 --- a/stages/org.osbuild.ostree.preptree +++ b/stages/org.osbuild.ostree.preptree @@ -67,9 +67,11 @@ SCHEMA = """ """ -# Corresponds to https://github.com/coreos/rpm-ostree/blob/7b9a20b20ecd5a2ceb11ca9edf86984dc3065183/rust/src/composepost.rs#L58 +# Corresponds to +# https://github.com/coreos/rpm-ostree/blob/7b9a20b20ecd5a2ceb11ca9edf86984dc3065183/rust/src/composepost.rs#L58 TOPLEVEL_DIRS = ["dev", "proc", "run", "sys", "sysroot", "var"] -# Corresponds to https://github.com/coreos/rpm-ostree/blob/7b9a20b20ecd5a2ceb11ca9edf86984dc3065183/rust/src/composepost.rs#L123 +# Corresponds to +# https://github.com/coreos/rpm-ostree/blob/7b9a20b20ecd5a2ceb11ca9edf86984dc3065183/rust/src/composepost.rs#L123 TOPLEVEL_LINKS = { "home": "var/home", "media": "run/media", diff --git a/stages/org.osbuild.parted b/stages/org.osbuild.parted index 03e38ace..8bf88dce 100755 --- a/stages/org.osbuild.parted +++ b/stages/org.osbuild.parted @@ -129,10 +129,10 @@ class PartitionTable: ] if p.bootable: - commands += ["set", str(i+1), "boot", "on"] + commands += ["set", str(i + 1), "boot", "on"] if p.type: - commands += ["set", str(i+1), p.type, "on"] + commands += ["set", str(i + 1), p.type, "on"] subprocess.run(["parted", "-a", "none", "-s", target, "--"] + commands, diff --git a/stages/org.osbuild.rpm b/stages/org.osbuild.rpm index 359a5604..24828a60 100755 --- a/stages/org.osbuild.rpm +++ b/stages/org.osbuild.rpm @@ -347,7 +347,7 @@ def main(tree, inputs, options): ] with tempfile.NamedTemporaryFile(prefix="manifest.", mode='w') as manifest: - manifest.writelines(c+'\n' for c in packages) + manifest.writelines(c + '\n' for c in packages) manifest.flush() subprocess.run([ "rpm", diff --git a/stages/org.osbuild.sgdisk b/stages/org.osbuild.sgdisk index 13d96968..e11e0119 100755 --- a/stages/org.osbuild.sgdisk +++ b/stages/org.osbuild.sgdisk @@ -129,7 +129,7 @@ class PartitionTable: command += ["-U", self.uuid] for i, part in enumerate(self.partitions): - idx = i+1 # partitions are 1-indexed + idx = i + 1 # partitions are 1-indexed # format is 'partnum:start:end' size = "0" diff --git a/stages/org.osbuild.systemd.unit b/stages/org.osbuild.systemd.unit index d290fec5..8ccf5b30 100755 --- a/stages/org.osbuild.systemd.unit +++ b/stages/org.osbuild.systemd.unit @@ -62,7 +62,7 @@ def main(tree, options): cfg = options["config"] # ensure the unit name + ".d" does not exceed maximum filename length - if len(unit+".d") > 255: + if len(unit + ".d") > 255: raise ValueError(f"Error: the {unit} unit drop-in directory exceeds the maximum filename length.") unit_dropins_dir = f"{tree}/usr/lib/systemd/system/{unit}.d" diff --git a/test/initrd.py b/test/initrd.py index 8d6a3e76..0d18e8b5 100644 --- a/test/initrd.py +++ b/test/initrd.py @@ -10,7 +10,7 @@ def skipcpio(fd): pos = 0 while True: os.lseek(fd, pos, os.SEEK_SET) - data = os.read(fd, 2*cpio_len) + data = os.read(fd, 2 * cpio_len) if data == b'': # end of file, cpio_end not found, cat it all pos = 0 @@ -24,7 +24,7 @@ def skipcpio(fd): if pos == 0: return pos # skip zeros - n = 2*cpio_len + n = 2 * cpio_len while True: data = os.read(fd, n) if data == b'': diff --git a/test/mod/test_loop.py b/test/mod/test_loop.py index 99d58078..9422114d 100644 --- a/test/mod/test_loop.py +++ b/test/mod/test_loop.py @@ -158,7 +158,7 @@ def test_clear_fd_wait(tempdir): thread.start() barrier.wait() - lo.clear_fd_wait(f.fileno(), 4*delay_time, delay_time/10) + lo.clear_fd_wait(f.fileno(), 4 * delay_time, delay_time / 10) # no timeout exception has occurred and thus the device # must not be be bound to the original file anymore diff --git a/test/mod/test_meta.py b/test/mod/test_meta.py index 93c809bb..2c715d46 100644 --- a/test/mod/test_meta.py +++ b/test/mod/test_meta.py @@ -85,12 +85,12 @@ def test_runner_detection(tempdir): }, "rhel": { "base": 90, - "versions": [91, 92, 93], + "versions": [91, 92, 93], "check": {94: 93}, }, "future": { "base": 100, - "versions": [101, 102, 103], + "versions": [101, 102, 103], "check": {110: 103}, } } diff --git a/test/mod/test_objectstore.py b/test/mod/test_objectstore.py index 9caf9e2f..174b9873 100644 --- a/test/mod/test_objectstore.py +++ b/test/mod/test_objectstore.py @@ -38,7 +38,7 @@ def store_fixture(): def test_basic(object_store): - object_store.maximum_size = 1024*1024*1024 + object_store.maximum_size = 1024 * 1024 * 1024 # No objects or references should be in the store assert len(os.listdir(object_store.objects)) == 0 @@ -85,7 +85,7 @@ def test_basic(object_store): def test_cleanup(tmpdir): with objectstore.ObjectStore(tmpdir) as object_store: - object_store.maximum_size = 1024*1024*1024 + object_store.maximum_size = 1024 * 1024 * 1024 stage = os.path.join(object_store, "stage") tree = object_store.new("a") @@ -156,7 +156,7 @@ def test_metadata(tmpdir): # use tmpdir fixture from here on with objectstore.ObjectStore(tmpdir) as store: - store.maximum_size = 1024*1024*1024 + store.maximum_size = 1024 * 1024 * 1024 obj = store.new("a") p = Path(obj, "A") p.touch() diff --git a/test/mod/test_util_fscache.py b/test/mod/test_util_fscache.py index b81b00d5..b73e3f2c 100644 --- a/test/mod/test_util_fscache.py +++ b/test/mod/test_util_fscache.py @@ -56,13 +56,13 @@ def test_pathlike(tmpdir): dir_str: str = os.fspath(tmpdir) cache1 = fscache.FsCache("osbuild-test-appid", dir_str) assert os.fspath(cache1) == tmpdir - assert os.path.join(cache1, "foobar") == os.path.join(tmpdir, "foobar") + assert os.path.join(cache1, "foobar") == os.path.join(tmpdir, "foobar") # Test with a wrapper-type as argument dir_pathlike: Wrapper = Wrapper(os.fspath(tmpdir)) cache2 = fscache.FsCache("osbuild-test-appid", dir_pathlike) assert os.fspath(cache2) == tmpdir - assert os.path.join(cache2, "foobar") == os.path.join(tmpdir, "foobar") + assert os.path.join(cache2, "foobar") == os.path.join(tmpdir, "foobar") def test_path(tmpdir): @@ -235,19 +235,19 @@ def test_cache_info(tmpdir): cache.info = fscache.FsCacheInfo(maximum_size=1024) assert cache.info.maximum_size == 1024 assert cache.info.creation_boot_id is None - cache.info = fscache.FsCacheInfo(creation_boot_id="0"*32) + cache.info = fscache.FsCacheInfo(creation_boot_id="0" * 32) assert cache.info.maximum_size == 1024 - assert cache.info.creation_boot_id == "0"*32 - cache.info = fscache.FsCacheInfo(maximum_size=2048, creation_boot_id="1"*32) + assert cache.info.creation_boot_id == "0" * 32 + cache.info = fscache.FsCacheInfo(maximum_size=2048, creation_boot_id="1" * 32) assert cache.info.maximum_size == 2048 - assert cache.info.creation_boot_id == "1"*32 + assert cache.info.creation_boot_id == "1" * 32 assert not fscache.FsCacheInfo().to_json() - assert fscache.FsCacheInfo(creation_boot_id="0"*32).to_json() == { - "creation-boot-id": "0"*32, + assert fscache.FsCacheInfo(creation_boot_id="0" * 32).to_json() == { + "creation-boot-id": "0" * 32, } - assert fscache.FsCacheInfo(creation_boot_id="0"*32, maximum_size=1024).to_json() == { - "creation-boot-id": "0"*32, + assert fscache.FsCacheInfo(creation_boot_id="0" * 32, maximum_size=1024).to_json() == { + "creation-boot-id": "0" * 32, "maximum-size": 1024, } @@ -255,21 +255,21 @@ def test_cache_info(tmpdir): assert fscache.FsCacheInfo.from_json(None) == fscache.FsCacheInfo() assert fscache.FsCacheInfo.from_json("foobar") == fscache.FsCacheInfo() assert fscache.FsCacheInfo.from_json({ - "creation-boot-id": "0"*32, - }) == fscache.FsCacheInfo(creation_boot_id="0"*32) + "creation-boot-id": "0" * 32, + }) == fscache.FsCacheInfo(creation_boot_id="0" * 32) assert fscache.FsCacheInfo.from_json({ - "creation-boot-id": "0"*32, + "creation-boot-id": "0" * 32, "maximum-size": 1024, - }) == fscache.FsCacheInfo(creation_boot_id="0"*32, maximum_size=1024) + }) == fscache.FsCacheInfo(creation_boot_id="0" * 32, maximum_size=1024) assert fscache.FsCacheInfo.from_json({ - "creation-boot-id": "0"*32, + "creation-boot-id": "0" * 32, "maximum-size": 1024, - }) == fscache.FsCacheInfo(creation_boot_id="0"*32, maximum_size=1024) + }) == fscache.FsCacheInfo(creation_boot_id="0" * 32, maximum_size=1024) assert fscache.FsCacheInfo.from_json({ - "creation-boot-id": "0"*32, + "creation-boot-id": "0" * 32, "unknown0": "foobar", "unknown1": ["foo", "bar"], - }) == fscache.FsCacheInfo(creation_boot_id="0"*32) + }) == fscache.FsCacheInfo(creation_boot_id="0" * 32) def test_store(tmpdir): @@ -317,7 +317,7 @@ def test_store_tree(tmpdir): cache.store_tree("foobar", "invalid/dir") with cache: - cache.info = cache.info._replace(maximum_size=1024*1024*1024) + cache.info = cache.info._replace(maximum_size=1024 * 1024 * 1024) with pytest.raises(ValueError): cache.store_tree("", "invalid/dir") diff --git a/test/mod/test_util_lvm2.py b/test/mod/test_util_lvm2.py index ca57b0cd..6ed549b7 100644 --- a/test/mod/test_util_lvm2.py +++ b/test/mod/test_util_lvm2.py @@ -156,7 +156,7 @@ def test_rename_vg_group(tempdir): vg = find_vg(vgs, new_name) if vg: break - time.sleep(0.250 * (i+1)) + time.sleep(0.250 * (i + 1)) if not vg: raise RuntimeError(f"Could not find vg {new_name}") finally: diff --git a/test/run/test_mount.py b/test/run/test_mount.py index 939add64..c5ed72d8 100755 --- a/test/run/test_mount.py +++ b/test/run/test_mount.py @@ -73,7 +73,7 @@ def create_image(tmpdir): env = os.environ.copy() env["PYTHONPATH"] = os.curdir subprocess.run( - [os.path.join(os.curdir, "stages", "org.osbuild.mkfs.fat")], + [os.path.join(os.curdir, "stages", "org.osbuild.mkfs.fat")], env=env, check=True, stdout=sys.stdout, diff --git a/test/run/test_sources.py b/test/run/test_sources.py index 97841006..37fbe57b 100644 --- a/test/run/test_sources.py +++ b/test/run/test_sources.py @@ -66,7 +66,7 @@ def can_setup_netns() -> bool: try: with netns(): return True - except: # pylint: disable=bare-except + except BaseException: # pylint: disable=bare-except return False diff --git a/test/run/test_stages.py b/test/run/test_stages.py index 7125b658..49447bf4 100644 --- a/test/run/test_stages.py +++ b/test/run/test_stages.py @@ -77,7 +77,7 @@ def mapping_is_subset(subset, other): """ if isinstance(subset, Mapping) and isinstance(other, Mapping): for key, value in subset.items(): - if not key in other: + if key not in other: return False other_value = other[key] diff --git a/tools/osbuild-mpp b/tools/osbuild-mpp index e80ff686..2e2cb8ee 100755 --- a/tools/osbuild-mpp +++ b/tools/osbuild-mpp @@ -590,7 +590,7 @@ LocalFileSigLevel = Optional pkginfo = self._pacman("-Sii", "--sysroot", self._cachedir, pkg["name"]) pkgdata = self.parse_pkg_info(pkginfo) p = PkgInfo( - "sha256:"+pkgdata["SHA-256 Sum"], + "sha256:" + pkgdata["SHA-256 Sum"], pkg["name"], pkg["version"], pkgdata["Architecture"], @@ -644,7 +644,7 @@ class DepSolver: if not result.scheme: path = basedir.joinpath(baseurl) return path.resolve().as_uri() - except: # pylint: disable=bare-except + except BaseException: # pylint: disable=bare-except pass return baseurl