Simplify build dependencies

python-commentjson is not packaged in Fedora, and python-json5 has a
long build dependency chain.  Since they are only used as a fallback to
built-in json because some of the test fixtures are commented (which
should in no way reflect the capabilities of resolvelib itself), simply
removing the comments allow the tests to pass without commentjson/json5.
This commit is contained in:
Yaakov Selkowitz 2023-11-07 08:41:24 -05:00 committed by Miro Hrončok
parent 946485a0d3
commit b71185e83c
2 changed files with 71 additions and 5 deletions

View File

@ -6,12 +6,15 @@ Name: python-%{pypi_name}
Version: 1.0.1
%global tag %{version}
%forgemeta
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Resolve abstract dependencies into concrete ones
License: ISC
URL: %{forgeurl}
Source: %{forgesource}
# Avoid commentjson/json5 build dependency just for a couple tests
Patch: %{url}/pull/141.patch#/remove-commentjson-dep.patch
BuildArch: noarch
BuildRequires: python3-devel
@ -34,10 +37,7 @@ Summary: %{summary}
%prep
%autosetup %{forgesetupargs}
# Use already packaged json5 instead of commentjson
sed -i 's|commentjson|json5|' \
setup.cfg tests/functional/cocoapods/test_resolvers_cocoapods.py
%autosetup %{forgesetupargs} -p1
%generate_buildrequires
@ -62,6 +62,9 @@ sed -i 's|commentjson|json5|' \
%changelog
* Tue Nov 07 2023 Yaakov Selkowitz <yselkowi@redhat.com> - 1.0.1-2
- Simplify build dependencies
* Fri Oct 20 2023 Maxwell G <maxwell@gtmx.me> - 1.0.1-1
- Update to 1.0.1.

View File

@ -0,0 +1,63 @@
From 3e50054d836b655b0868520bae8b85a3c18967ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Wed, 8 Nov 2023 17:12:16 +0100
Subject: [PATCH] Replace the commentjson test dependency with re.sub
While at it, only open the json files once.
Co-authored-by: Maxwell G <maxwell@gtmx.me>
---
setup.cfg | 1 -
.../cocoapods/test_resolvers_cocoapods.py | 19 +++++++++++--------
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/setup.cfg b/setup.cfg
index 5eddf2f..e080991 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -44,7 +44,6 @@ lint =
isort
types-requests
test =
- commentjson
packaging
pytest
release =
diff --git a/tests/functional/cocoapods/test_resolvers_cocoapods.py b/tests/functional/cocoapods/test_resolvers_cocoapods.py
index 12dff46..f54e27d 100644
--- a/tests/functional/cocoapods/test_resolvers_cocoapods.py
+++ b/tests/functional/cocoapods/test_resolvers_cocoapods.py
@@ -5,7 +5,6 @@
import re
import string
-import commentjson # type: ignore
import pytest
from resolvelib import AbstractProvider, ResolutionImpossible, Resolver
@@ -124,14 +123,18 @@ def _version_in_specset(version, specset):
def _safe_json_load(filename):
- # Some fixtures has comments so the stdlib implementation doesn't work.
- # We only use commentjson if we absolutely need to because it's SLOW.
- try:
- with open(filename) as f:
+ # Some fixtures have comments so they are not valid json.
+ # We could use commentjson/json5 to load them,
+ # but it's easier to strip the comments.
+ # We only do it when json.load() fails to avoid unnecessary loading
+ # all the json files to strings.
+ with open(filename) as f:
+ try:
data = json.load(f)
- except ValueError:
- with open(filename) as f:
- data = commentjson.load(f)
+ except ValueError:
+ f.seek(0)
+ strippedjson = re.sub(r"//.*$", "", f.read(), flags=re.MULTILINE)
+ data = json.loads(strippedjson)
return data