Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg_resources is a deprecated API - replace with importlib.resources #975

Merged
Merged
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -48,7 +48,6 @@
# "urllib3>=2; python_version>='3.10'",
"keyring>=15,<23.5",
"deprecated>=1.2.4,<2.0",
"importlib-metadata<5.0",
]

# on Linux specify a cryptography dependency that will not
Expand Down
17 changes: 8 additions & 9 deletions synapseclient/__init__.py
Expand Up @@ -275,10 +275,10 @@


"""
import importlib.resources

import json

import pkg_resources
import requests # ensure user-agent is set to track Synapse Python client usage

from .activity import Activity
from .annotations import Annotations
Expand Down Expand Up @@ -307,9 +307,12 @@
from .team import Team, UserProfile, UserGroupHeader, TeamMember
from .wiki import Wiki

__version__ = json.load(pkg_resources.resource_stream(__name__, "synapsePythonClient"))[
"latestVersion"
]
# ref = importlib.resources.files(__name__).joinpath("synapsePythonClient")
# with ref.open("r") as fp:
# __version__ = json.load(fp)["latestVersion"]
# TODO: switch to the above after python 3.8 is deprecated
with importlib.resources.path(__name__, "synapsePythonClient") as ref:
__version__ = json.load(open(ref))["latestVersion"]

__all__ = [
# objects
Expand Down Expand Up @@ -353,10 +356,6 @@
"AUTHENTICATED_USERS",
]


# ensure user-agent is set to track Synapse Python client usage
import requests

USER_AGENT = {
"User-Agent": "synapseclient/%s %s"
% (__version__, requests.utils.default_user_agent())
Expand Down
18 changes: 10 additions & 8 deletions synapseclient/core/version_check.py
Expand Up @@ -15,13 +15,13 @@
.. automethod:: synapseclient.core.version_check.release_notes

"""
import importlib.resources
import re
import sys

import json
import pkg_resources
import re
import requests
import synapseclient
import sys


_VERSION_URL = "https://raw.githubusercontent.com/Sage-Bionetworks/synapsePythonClient/master/synapseclient/synapsePythonClient" # noqa
Expand Down Expand Up @@ -167,11 +167,13 @@ def _version_tuple(version, levels=2):

def _get_version_info(version_url=_VERSION_URL):
if version_url is None:
return json.loads(
pkg_resources.resource_string(
"synapseclient", "synapsePythonClient"
).decode()
)
# ref = importlib_resources.files("synapseclient").joinpath("synapsePythonClient")
# with ref.open("r") as fp:
# pkg_metadata = json.loads(fp.read())
# TODO: switch to the above after python 3.8 is deprecated
with importlib.resources.path(__name__, "synapsePythonClient") as ref:
pkg_metadata = json.load(ref)
return pkg_metadata
else:
headers = {"Accept": "application/json; charset=UTF-8"}
headers.update(synapseclient.USER_AGENT)
Expand Down