Skip to content

Commit

Permalink
Load JSON using importlib.resources
Browse files Browse the repository at this point in the history
This is a updated fix for pyupio#2308
and supersedes pyupio#2309

It uses importlib.resources which means dropping
support for python 3.6 and below
  • Loading branch information
efokschaner committed Feb 4, 2022
1 parent 5f89a3e commit c6aff83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
19 changes: 9 additions & 10 deletions data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from importlib.resources import read_text

__title__ = 'safety-db'
__version__ = '2021.7.17'
Expand All @@ -10,15 +11,13 @@
'INSECURE_FULL',
)

with open("data/insecure.json") as __f:
try:
INSECURE = json.loads(__f.read())
except ValueError as e:
INSECURE = []
try:
INSECURE = json.loads(read_text(__package__, "insecure.json"))
except ValueError as e:
INSECURE = []


with open("data/insecure_full.json") as __f:
try:
INSECURE_FULL = json.loads(__f.read())
except ValueError as e:
INSECURE_FULL = []
try:
INSECURE_FULL = json.loads(read_text(__package__, "insecure_full.json"))
except ValueError as e:
INSECURE_FULL = []
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
long_description=long_description,
long_description_content_type="text/markdown",
classifiers=[
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
Expand All @@ -54,4 +54,5 @@
install_requires=[],
tests_require=tests_require,
include_package_data=True,
python_requires='>=3.7',
)

0 comments on commit c6aff83

Please sign in to comment.