diff --git a/assemblers/org.osbuild.oci-archive b/assemblers/org.osbuild.oci-archive index 1662587d..77262e8e 100755 --- a/assemblers/org.osbuild.oci-archive +++ b/assemblers/org.osbuild.oci-archive @@ -230,7 +230,7 @@ def create_oci_dir(tree, output_dir, options): config["rootfs"]["diff_ids"] = [digest] manifest["layers"].append(info) - ## write config + # write config info = blobs_add_json(blobs, config, "config") manifest["config"] = info diff --git a/assemblers/org.osbuild.rawfs b/assemblers/org.osbuild.rawfs index fd4f1c97..9d4b3506 100755 --- a/assemblers/org.osbuild.rawfs +++ b/assemblers/org.osbuild.rawfs @@ -56,6 +56,7 @@ SCHEMA = """ } """ + @contextlib.contextmanager def mount(source, dest, *options): os.makedirs(dest, 0o755, True) diff --git a/osbuild/pipeline.py b/osbuild/pipeline.py index 1e5f0788..fec08dc3 100644 --- a/osbuild/pipeline.py +++ b/osbuild/pipeline.py @@ -373,7 +373,7 @@ class Manifest: def add_pipeline( self, name: str, runner: Optional[str], build: Optional[str] = None, source_epoch: Optional[int] = None - ) -> Pipeline: + ) -> Pipeline: pipeline = Pipeline(name, runner, build, source_epoch) if name in self.pipelines: raise ValueError(f"Name {name} already exists") diff --git a/osbuild/util/ostree.py b/osbuild/util/ostree.py index 6e108fd1..75dcc661 100644 --- a/osbuild/util/ostree.py +++ b/osbuild/util/ostree.py @@ -175,12 +175,13 @@ class PasswdLike: class can parse the the list, manipulate it, and export it to file again. """ + def __init__(self): """Initialize an empty PasswdLike object""" self.db = dict() @classmethod - def from_file(cls, path: PathLike, allow_missing_file: bool=False): + def from_file(cls, path: PathLike, allow_missing_file: bool = False): """Initialize a PasswdLike object from an existing file""" ret = cls() if allow_missing_file: @@ -191,7 +192,7 @@ class PasswdLike: ret.db = cls._passwd_lines_to_dict(p.readlines()) return ret - def merge_with_file(self, path: PathLike, allow_missing_file: bool=False): + def merge_with_file(self, path: PathLike, allow_missing_file: bool = False): """Extend the database with entries from another file""" if allow_missing_file: if not os.path.isfile(path): diff --git a/osbuild/util/path.py b/osbuild/util/path.py index 8d73a0c2..0988b5a0 100644 --- a/osbuild/util/path.py +++ b/osbuild/util/path.py @@ -1,6 +1,7 @@ """Path handling utility functions""" import os + def in_tree(path: str, tree: str, must_exist: bool = False) -> bool: """Return whether the canonical location of 'path' is under 'tree'. If 'must_exist' is True, the file must also exist for the check to succeed. diff --git a/runners/org.osbuild.rhel81 b/runners/org.osbuild.rhel81 index 925326e3..5312a00e 100755 --- a/runners/org.osbuild.rhel81 +++ b/runners/org.osbuild.rhel81 @@ -71,6 +71,7 @@ def python_alternatives(): except FileExistsError: pass + if __name__ == "__main__": with osbuild.api.exception_handler(): ldconfig() diff --git a/stages/org.osbuild.bootiso.mono b/stages/org.osbuild.bootiso.mono index f1fdd394..daa99b3e 100755 --- a/stages/org.osbuild.bootiso.mono +++ b/stages/org.osbuild.bootiso.mono @@ -208,7 +208,7 @@ def make_efi(efi, info, root, loop_client): efidir = os.path.join(root, "EFI", "BOOT") os.makedirs(efidir) - #arch related data + # arch related data for arch in arches: arch = arch.lower() targets = [ @@ -382,7 +382,7 @@ def main(inputs, root, options, workdir, loop_client): "cmdline": cmdline } - #install the kernel + # install the kernel kerneldir = pxedir kernel_input = inputs.get("kernel", inputs["rootfs"]) kernel_tree = kernel_input["path"] diff --git a/stages/org.osbuild.firewall b/stages/org.osbuild.firewall index 544373ce..aa5f2942 100755 --- a/stages/org.osbuild.firewall +++ b/stages/org.osbuild.firewall @@ -88,10 +88,10 @@ def main(tree, options): subprocess.run(["chroot", tree, "firewall-offline-cmd"] + - list(map(lambda x: f"--port={x}", ports)) + - list(map(lambda x: f"--service={x}", enabled_services)) + - list(map(lambda x: f"--remove-service={x}", disabled_services)), - check=True) + list(map(lambda x: f"--port={x}", ports)) + + list(map(lambda x: f"--service={x}", enabled_services)) + + list(map(lambda x: f"--remove-service={x}", disabled_services)), + check=True) return 0 diff --git a/stages/org.osbuild.locale b/stages/org.osbuild.locale index 7da0888e..58b1bd89 100755 --- a/stages/org.osbuild.locale +++ b/stages/org.osbuild.locale @@ -29,6 +29,7 @@ SCHEMA = """ } """ + def main(tree, options): language = options["language"] diff --git a/stages/org.osbuild.nginx.conf b/stages/org.osbuild.nginx.conf index 6e48aefa..5dbf682b 100755 --- a/stages/org.osbuild.nginx.conf +++ b/stages/org.osbuild.nginx.conf @@ -48,6 +48,7 @@ SCHEMA_2 = r""" } """ + def main(tree, options): path = options.get("path", "etc/nginx/nginx.conf").lstrip("/") diff --git a/stages/org.osbuild.oscap.remediation b/stages/org.osbuild.oscap.remediation index f94e5c4b..b68f3592 100755 --- a/stages/org.osbuild.oscap.remediation +++ b/stages/org.osbuild.oscap.remediation @@ -93,6 +93,7 @@ SCHEMA = """ XML_RESULTS = "eval_remediate_results.xml" HTML_REPORT = "eval_remediate_report.html" + def main(tree, options): # required vars config = options["config"] @@ -108,9 +109,9 @@ def main(tree, options): # run openscap in chroot on the image tree cmd = [ - "/usr/sbin/chroot", tree, - "/usr/bin/oscap", "xccdf", "eval", - "--remediate", "--profile", profile + "/usr/sbin/chroot", tree, + "/usr/bin/oscap", "xccdf", "eval", + "--remediate", "--profile", profile ] if data_dir is not None: diff --git a/stages/org.osbuild.sysconfig b/stages/org.osbuild.sysconfig index 5b137da3..185fd9e1 100755 --- a/stages/org.osbuild.sysconfig +++ b/stages/org.osbuild.sysconfig @@ -227,7 +227,7 @@ def configure_network_scripts_ifcfg(tree, network_scripts_ifcfg_options): else: # schema does not currently allow any additional properties but it may at some point raise ValueError(f"Error: unknown property {option} specified for sysconfig network-scripts/ifcfg " - "config.") + "config.") if lines: with open(f"{tree}/etc/sysconfig/network-scripts/ifcfg-{ifname}", 'w') as ifcfg_file: diff --git a/stages/org.osbuild.tuned b/stages/org.osbuild.tuned index c0f4bc7e..0bfb2d2c 100755 --- a/stages/org.osbuild.tuned +++ b/stages/org.osbuild.tuned @@ -38,6 +38,7 @@ class TunedProfilesDB: Class for loading available TuneD profiles from the given filesystem tree and checking if a profile with particular name exists. """ + def __init__(self, tree): self._available_profiles = self._load_available_profiles(tree) diff --git a/test/mod/test_api.py b/test/mod/test_api.py index 7ce85536..c21f4d93 100644 --- a/test/mod/test_api.py +++ b/test/mod/test_api.py @@ -13,6 +13,7 @@ from osbuild.util import jsoncomm class APITester(osbuild.api.BaseAPI): """Records the number of messages and if it got cleaned up""" + def __init__(self, sockaddr): super().__init__(sockaddr) self.clean = False @@ -33,6 +34,7 @@ class APITester(osbuild.api.BaseAPI): class TestAPI(unittest.TestCase): """Check API infrastructure""" + def setUp(self): self.tmp = tempfile.TemporaryDirectory() diff --git a/test/mod/test_fmt_v1.py b/test/mod/test_fmt_v1.py index ef0104ca..aefc7b2f 100644 --- a/test/mod/test_fmt_v1.py +++ b/test/mod/test_fmt_v1.py @@ -160,7 +160,6 @@ class TestFormatV1(unittest.TestCase): self.assertEqual(pl.runner, runner) check_stage(have, want) - def test_describe(self): index = osbuild.meta.Index(os.curdir) @@ -412,9 +411,9 @@ class TestFormatV1(unittest.TestCase): self.assertEqual(res.valid, False) self.assertEqual(len(res), 2) lst = res[".pipeline.stages[0].options"] - self.assertEqual(len(lst), 1) # missing rootfs + self.assertEqual(len(lst), 1) # missing rootfs lst = res[".pipeline.stages[0].options.uefi"] - self.assertEqual(len(lst), 1) # missing "osname" + self.assertEqual(len(lst), 1) # missing "osname" assembler_check = { "pipeline": { @@ -431,6 +430,6 @@ class TestFormatV1(unittest.TestCase): self.assertEqual(res.valid, False) self.assertEqual(len(res), 2) lst = res[".pipeline.assembler.options"] - self.assertEqual(len(lst), 1) # missing "filename" + self.assertEqual(len(lst), 1) # missing "filename" lst = res[".pipeline.assembler.options.compression"] - self.assertEqual(len(lst), 1) # wrong compression method + self.assertEqual(len(lst), 1) # wrong compression method diff --git a/test/mod/test_objectstore.py b/test/mod/test_objectstore.py index c52c7d99..4063fa10 100644 --- a/test/mod/test_objectstore.py +++ b/test/mod/test_objectstore.py @@ -122,7 +122,7 @@ class TestObjectStore(unittest.TestCase): with object_store.new() as tree: path = tree.write() with tree.write() as path, \ - open(os.path.join(path, "data"), "w") as f: + open(os.path.join(path, "data"), "w") as f: f.write(data) st = os.fstat(f.fileno()) data_inode = st.st_ino diff --git a/test/mod/test_util_lorax.py b/test/mod/test_util_lorax.py index 8521948b..ad1df2a2 100644 --- a/test/mod/test_util_lorax.py +++ b/test/mod/test_util_lorax.py @@ -35,7 +35,6 @@ class TestUtilLorax(test.TestBase): if not os.path.exists(target): self.fail(f"Path {target} does not exists") - def test_script(self): with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp: root = os.path.join(tmp, "root") @@ -81,7 +80,6 @@ class TestUtilLorax(test.TestBase): data = f.read().strip() self.assertEqual(data, "osbuild-42") - def test_script_errors(self): with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp: root = os.path.join(tmp, "root") diff --git a/test/mod/test_util_path.py b/test/mod/test_util_path.py index 537b0375..c9efcb6a 100644 --- a/test/mod/test_util_path.py +++ b/test/mod/test_util_path.py @@ -5,6 +5,7 @@ import os from osbuild.util import path + def test_in_tree(): cases = { ("/tmp/file", "/tmp", False): True, # Simple, non-existent diff --git a/test/mod/test_util_rhsm.py b/test/mod/test_util_rhsm.py index f89fab06..72d88f11 100644 --- a/test/mod/test_util_rhsm.py +++ b/test/mod/test_util_rhsm.py @@ -6,7 +6,7 @@ from io import StringIO from osbuild.util.rhsm import Subscriptions -REPO_FILE="""[jpp] +REPO_FILE = """[jpp] name = Red Hat JBoss Portal baseurl = https://cdn.redhat.com/1.0/$basearch/os enabled = 0 @@ -66,7 +66,7 @@ def test_from_host_system(): raise e - assert test_case["success"] # Verify this test case should pass + assert test_case["success"] # Verify this test case should pass assert secrets["ssl_ca_cert"] == "/etc/rhsm/ca/redhat-uep.pem" assert secrets["ssl_client_key"] == f'/etc/pki/entitlement/{test_case["key"]}-key.pem' assert secrets["ssl_client_cert"] == f'/etc/pki/entitlement/{test_case["key"]}.pem' diff --git a/test/run/test_stages.py b/test/run/test_stages.py index 0bf67d0d..3edcc41f 100644 --- a/test/run/test_stages.py +++ b/test/run/test_stages.py @@ -314,8 +314,8 @@ class TestStages(test.TestBase): for image_name, test_data in checks.items(): with self.osbuild as osb, tempfile.TemporaryDirectory(dir="/var/tmp") as outdir: osb.compile_file(os.path.join(testdir, "qemu.json"), - exports=[image_name], - output_dir=outdir) + exports=[image_name], + output_dir=outdir) tree = os.path.join(outdir, image_name) ip = os.path.join(tree, image_name) @@ -331,8 +331,8 @@ class TestStages(test.TestBase): qemu_img_out = json.loads(qemu_img_run.stdout) self.assertTrue(mapping_is_subset(test_data, qemu_img_out), - f"Test data is not a subset of the qemu-img output: {test_data} not <= {qemu_img_run.stdout}" - ) + ("Test data is not a subset of the qemu-img output: " + f"{test_data} not <= {qemu_img_run.stdout}")) # cache the downloaded data for the files source osb.copy_source_data(self.store, "org.osbuild.files")