Skip to content

Commit

Permalink
Merge pull request #141 from hroncok/nocmmments
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Apr 3, 2024
2 parents a062162 + e607014 commit 87c9d7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ lint =
isort
types-requests
test =
commentjson
packaging
pytest
release =
Expand Down
17 changes: 9 additions & 8 deletions tests/functional/cocoapods/test_resolvers_cocoapods.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import re
import string

import commentjson # type: ignore
import pytest

from resolvelib import AbstractProvider, ResolutionImpossible, Resolver
Expand Down Expand Up @@ -124,14 +123,16 @@ 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 strip them if first parse fails.
# We only do this in case of failure to avoid loading all JSON files to
# strings before parsing.
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


Expand Down

0 comments on commit 87c9d7b

Please sign in to comment.