]> TLD Linux GIT Repositories - packages/python3-resolvelib.git/blob - remove-commentjson-dep.patch
- new
[packages/python3-resolvelib.git] / remove-commentjson-dep.patch
1 From 3e50054d836b655b0868520bae8b85a3c18967ef Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
3 Date: Wed, 8 Nov 2023 17:12:16 +0100
4 Subject: [PATCH] Replace the commentjson test dependency with re.sub
5
6 While at it, only open the json files once.
7
8 Co-authored-by: Maxwell G <maxwell@gtmx.me>
9 ---
10  setup.cfg                                     |  1 -
11  .../cocoapods/test_resolvers_cocoapods.py     | 19 +++++++++++--------
12  2 files changed, 11 insertions(+), 9 deletions(-)
13
14 diff --git a/setup.cfg b/setup.cfg
15 index 5eddf2f..e080991 100644
16 --- a/setup.cfg
17 +++ b/setup.cfg
18 @@ -44,7 +44,6 @@ lint =
19         isort
20         types-requests
21  test =
22 -       commentjson
23         packaging
24         pytest
25  release =
26 diff --git a/tests/functional/cocoapods/test_resolvers_cocoapods.py b/tests/functional/cocoapods/test_resolvers_cocoapods.py
27 index 12dff46..f54e27d 100644
28 --- a/tests/functional/cocoapods/test_resolvers_cocoapods.py
29 +++ b/tests/functional/cocoapods/test_resolvers_cocoapods.py
30 @@ -5,7 +5,6 @@
31  import re
32  import string
33  
34 -import commentjson  # type: ignore
35  import pytest
36  
37  from resolvelib import AbstractProvider, ResolutionImpossible, Resolver
38 @@ -124,14 +123,18 @@ def _version_in_specset(version, specset):
39  
40  
41  def _safe_json_load(filename):
42 -    # Some fixtures has comments so the stdlib implementation doesn't work.
43 -    # We only use commentjson if we absolutely need to because it's SLOW.
44 -    try:
45 -        with open(filename) as f:
46 +    # Some fixtures have comments so they are not valid json.
47 +    # We could use commentjson/json5 to load them,
48 +    # but it's easier to strip the comments.
49 +    # We only do it when json.load() fails to avoid unnecessary loading
50 +    # all the json files to strings.
51 +    with open(filename) as f:
52 +        try:
53              data = json.load(f)
54 -    except ValueError:
55 -        with open(filename) as f:
56 -            data = commentjson.load(f)
57 +        except ValueError:
58 +            f.seek(0)
59 +            strippedjson = re.sub(r"//.*$", "", f.read(), flags=re.MULTILINE)
60 +            data = json.loads(strippedjson)
61      return data
62  
63