From 3ac6d405b5f8daccef8e2c8b16979c37f139b8ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 19 Nov 2024 13:36:20 +0100 Subject: [PATCH] Fix pylint issue E0606: possibly-used-before-assignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix: assemblers/org.osbuild.qemu:310:36: E0606: Possibly using variable 'prep_type' before assignment (possibly-used-before-assignment) inputs/org.osbuild.tree:85:15: E0606: Possibly using variable 'path' before assignment (possibly-used-before-assignment) stages/org.osbuild.sfdisk:58:36: E0606: Possibly using variable 'prep_type' before assignment (possibly-used-before-assignment) stages/org.osbuild.systemd.unit:23:16: E0606: Possibly using variable 'unit_dropins_dir' before assignment (possibly-used-before-assignment) test/mod/test_meta.py:219:29: E0606: Possibly using variable 'schema_part' before assignment (possibly-used-before-assignment) Signed-off-by: Tomáš Hozza --- assemblers/org.osbuild.qemu | 2 ++ inputs/org.osbuild.tree | 1 + stages/org.osbuild.sfdisk | 2 ++ stages/org.osbuild.systemd.unit | 4 ++++ test/mod/test_meta.py | 1 + 5 files changed, 10 insertions(+) diff --git a/assemblers/org.osbuild.qemu b/assemblers/org.osbuild.qemu index 1d383892..f568f07d 100755 --- a/assemblers/org.osbuild.qemu +++ b/assemblers/org.osbuild.qemu @@ -305,6 +305,8 @@ class PartitionTable: prep_type = "41" elif self.label == "gpt": prep_type = "9E1A2D38-C612-4316-AA26-8B49521E5A8B" + else: + raise RuntimeError(f"Unknown partition table type: {self.label}") for part in self.partitions: if part.type.upper() == prep_type: diff --git a/inputs/org.osbuild.tree b/inputs/org.osbuild.tree index f954f309..8d456838 100755 --- a/inputs/org.osbuild.tree +++ b/inputs/org.osbuild.tree @@ -79,6 +79,7 @@ class TreeInput(inputs.InputService): # and we have exactly one reference, i.e. a pipeline id pid, _ = refs.popitem() + path = None if pid: path = store.read_tree_at(pid, target) diff --git a/stages/org.osbuild.sfdisk b/stages/org.osbuild.sfdisk index 188cdc88..a669ea7e 100755 --- a/stages/org.osbuild.sfdisk +++ b/stages/org.osbuild.sfdisk @@ -53,6 +53,8 @@ class PartitionTable: prep_type = "41" elif self.label == "gpt": prep_type = "9E1A2D38-C612-4316-AA26-8B49521E5A8B" + else: + raise RuntimeError(f"Unknown partition table type: {self.label}") for part in self.partitions: if part.type.upper() == prep_type: diff --git a/stages/org.osbuild.systemd.unit b/stages/org.osbuild.systemd.unit index c4512a7a..dd9f295b 100755 --- a/stages/org.osbuild.systemd.unit +++ b/stages/org.osbuild.systemd.unit @@ -20,6 +20,10 @@ def main(tree, options): unit_dropins_dir = f"{tree}/usr/lib/systemd/system/{unit}.d" elif unit_type == "global": unit_dropins_dir = f"{tree}/usr/lib/systemd/user/{unit}.d" + else: + print(f"Error: Unknown unit type: {unit_type}") + return 1 + os.makedirs(unit_dropins_dir, exist_ok=True) # We trick configparser into letting us write multiple instances of the same option by writing them as keys with no diff --git a/test/mod/test_meta.py b/test/mod/test_meta.py index 419199a6..9901e6db 100644 --- a/test/mod/test_meta.py +++ b/test/mod/test_meta.py @@ -206,6 +206,7 @@ def make_fake_meta_json(tmp_path, name, version, invalid=""): "not": "following schema" """ + # pylint: disable=possibly-used-before-assignment meta_json_path.write_text(""" { "summary": "some json summary",