From cc994d7dca5b7920bb140269847734c62a409453 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Wed, 9 Aug 2023 10:39:07 +0200 Subject: [PATCH] rpmbuild: drop dependency on simplejson Relates: #2539 --- rpmbuild/copr-rpmbuild.spec | 2 -- rpmbuild/copr_rpmbuild/automation/rpm_results.py | 5 +++-- rpmbuild/copr_rpmbuild/automation/srpm_results.py | 5 +++-- rpmbuild/main.py | 13 ++++--------- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/rpmbuild/copr-rpmbuild.spec b/rpmbuild/copr-rpmbuild.spec index 72a4ed4d9..bd3d3ea2d 100644 --- a/rpmbuild/copr-rpmbuild.spec +++ b/rpmbuild/copr-rpmbuild.spec @@ -39,7 +39,6 @@ BuildRequires: %{python}-pytest BuildRequires: %{python_pfx}-munch BuildRequires: %{python}-requests BuildRequires: %{python_pfx}-jinja2 -BuildRequires: %{python_pfx}-simplejson BuildRequires: %{python_pfx}-specfile >= 0.19.0 BuildRequires: python3-backoff >= 1.9.0 @@ -57,7 +56,6 @@ Requires: %{python}-copr-common >= %copr_common_version Requires: %{python_pfx}-jinja2 Requires: %{python_pfx}-munch Requires: %{python}-requests -Requires: %{python_pfx}-simplejson Requires: %{python_pfx}-specfile >= 0.19.0 Requires: python3-backoff >= 1.9.0 diff --git a/rpmbuild/copr_rpmbuild/automation/rpm_results.py b/rpmbuild/copr_rpmbuild/automation/rpm_results.py index 77d7d7a89..60f26f059 100644 --- a/rpmbuild/copr_rpmbuild/automation/rpm_results.py +++ b/rpmbuild/copr_rpmbuild/automation/rpm_results.py @@ -2,8 +2,9 @@ Create `results.json` file """ +import json import os -import simplejson + from copr_rpmbuild.automation.base import AutomationTool from copr_rpmbuild.helpers import get_rpm_header @@ -28,7 +29,7 @@ def run(self): packages = {"packages": nevras} path = os.path.join(self.resultdir, "results.json") with open(path, "w") as dst: - simplejson.dump(packages, dst, indent=4) + json.dump(packages, dst, indent=4) def find_results_nevras_dicts(self): """ diff --git a/rpmbuild/copr_rpmbuild/automation/srpm_results.py b/rpmbuild/copr_rpmbuild/automation/srpm_results.py index be4d75741..2618008b8 100644 --- a/rpmbuild/copr_rpmbuild/automation/srpm_results.py +++ b/rpmbuild/copr_rpmbuild/automation/srpm_results.py @@ -2,8 +2,9 @@ Create `results.json` file for SRPM builds """ +import json import os -import simplejson + from copr_rpmbuild.automation.base import AutomationTool from copr_rpmbuild.helpers import ( get_rpm_header, @@ -32,7 +33,7 @@ def run(self): data = self.get_package_info() path = os.path.join(self.resultdir, "results.json") with open(path, "w", encoding="utf-8") as dst: - simplejson.dump(data, dst, indent=4) + json.dump(data, dst, indent=4) def get_package_info(self): """ diff --git a/rpmbuild/main.py b/rpmbuild/main.py index 84c90c90c..ad8749dea 100755 --- a/rpmbuild/main.py +++ b/rpmbuild/main.py @@ -13,11 +13,6 @@ import shlex import pkg_resources -try: - from simplejson.scanner import JSONDecodeError -except ImportError: - JSONDecodeError = Exception - from copr_common.request import SafeRequest, RequestError from copr_rpmbuild import providers from copr_rpmbuild.builders.mock import MockBuilder @@ -320,8 +315,8 @@ def get_vanilla_build_config(url): raise RuntimeError("No valid build_config at {0}".format(url)) return build_config - except JSONDecodeError: - raise RuntimeError("No valid build_config at {0}".format(url)) + except json.decoder.JSONDecodeError as ex: + raise RuntimeError("No valid build_config at {0}".format(url)) from ex def read_task_from_file(path): @@ -330,8 +325,8 @@ def read_task_from_file(path): return json.loads(f.read()) except OSError as ex: raise RuntimeError(ex) - except json.decoder.JSONDecodeError: - raise RuntimeError("No valid build_config at {0}".format(path)) + except json.decoder.JSONDecodeError as ex: + raise RuntimeError("No valid build_config at {0}".format(path)) from ex if __name__ == "__main__":