From 09b669e9a89d537100e1eb6ae713920aa7a091ba Mon Sep 17 00:00:00 2001 From: deajan Date: Sun, 15 Sep 2024 20:44:14 +0200 Subject: [PATCH] Linter fixes --- npbackup/gui/__main__.py | 6 +++--- npbackup/restic_wrapper/__init__.py | 12 +++++++----- npbackup/restic_wrapper/schema.py | 4 ++-- npbackup/runner_interface.py | 7 ++++--- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/npbackup/gui/__main__.py b/npbackup/gui/__main__.py index 8e3aed7..1cf52f7 100644 --- a/npbackup/gui/__main__.py +++ b/npbackup/gui/__main__.py @@ -58,7 +58,7 @@ from npbackup.path_helper import CURRENT_DIR from npbackup.__version__ import version_string from npbackup.__debug__ import _DEBUG from npbackup.restic_wrapper import ResticRunner -from npbackup.restic_wrapper import schema, MSGSPEC +from npbackup.restic_wrapper import schema, HAVE_MSGSPEC logger = getLogger() @@ -193,13 +193,13 @@ def _make_treedata_from_json(ls_result: List[dict]) -> sg.TreeData: """ treedata = sg.TreeData() count = 0 - if not MSGSPEC: + if not HAVE_MSGSPEC: logger.info( "Using basic json representation for data which is slow and memory hungry. Consider using a newer OS that supports Python 3.8+" ) for entry in ls_result: # Make sure we drop the prefix '/' so sg.TreeData does not get an empty root - if MSGSPEC: + if HAVE_MSGSPEC: entry.path = entry.path.lstrip("/") if os.name == "nt": # On windows, we need to make sure tree keys don't get duplicate because of lower/uppercase diff --git a/npbackup/restic_wrapper/__init__.py b/npbackup/restic_wrapper/__init__.py index 643c10a..40535d6 100644 --- a/npbackup/restic_wrapper/__init__.py +++ b/npbackup/restic_wrapper/__init__.py @@ -30,12 +30,12 @@ from npbackup.restic_wrapper import schema try: import msgspec - MSGSPEC = True + HAVE_MSGSPEC = True except ImportError: # We may not have msgspec on Python 3.7 import json - MSGSPEC = False + HAVE_MSGSPEC = False logger = getLogger() @@ -682,7 +682,7 @@ class ResticRunner: } if result: if output: - if MSGSPEC: + if HAVE_MSGSPEC: decoder = msgspec.json.Decoder() ls_decoder = msgspec.json.Decoder(schema.LsNode) is_first_line = True @@ -690,7 +690,7 @@ class ResticRunner: for line in output.split("\n"): if not line: continue - if MSGSPEC: + if HAVE_MSGSPEC: try: if ( not is_first_line @@ -710,6 +710,7 @@ class ResticRunner: js["result"] = False else: try: + # pylint: disable=E0601 (used-before-assignment) js["output"].append(json.loads(line)) except json.JSONDecodeError as exc: msg = f"JSON decode error: {exc} on content '{line}'" @@ -728,7 +729,7 @@ class ResticRunner: js["reason"] = msg self.write_logs(msg, level="error") if output: - if MSGSPEC: + if HAVE_MSGSPEC: try: js["output"] = msgspec.json.decode(output) except msgspec.DecodeError as exc: @@ -738,6 +739,7 @@ class ResticRunner: js["output"] = {"data": output} else: try: + # pylint: disable=E0601 (used-before-assignment) js["output"] = json.loads(output) except json.JSONDecodeError as exc: msg = f"JSON decode error: {exc} on output '{output}'" diff --git a/npbackup/restic_wrapper/schema.py b/npbackup/restic_wrapper/schema.py index 3c15d33..e9f78f2 100644 --- a/npbackup/restic_wrapper/schema.py +++ b/npbackup/restic_wrapper/schema.py @@ -17,7 +17,7 @@ try: from msgspec import Struct from enum import StrEnum - MSGSPEC = True + HAVE_MSGSPEC = True except ImportError: class Struct: @@ -29,7 +29,7 @@ except ImportError: class StrEnum: pass - MSGSPEC = False + HAVE_MSGSPEC = False class LsNodeType(StrEnum): diff --git a/npbackup/runner_interface.py b/npbackup/runner_interface.py index 2596cba..c298f3a 100644 --- a/npbackup/runner_interface.py +++ b/npbackup/runner_interface.py @@ -18,11 +18,11 @@ from logging import getLogger try: import msgspec.json - MSGSPEC = True + HAVE_MSGSPEC = True except ImportError: import json - MSGSPEC = False + HAVE_MSGSPEC = False import datetime from npbackup.core.runner import NPBackupRunner @@ -78,9 +78,10 @@ def entrypoint(*args, **kwargs): else: logger.error(f"Operation finished") else: - if MSGSPEC: + if HAVE_MSGSPEC: print(msgspec.json.encode(result)) else: + # pylint: disable=E0601 (used-before-assignment) print(json.dumps(result, default=serialize_datetime)) sys.exit(0)