Skip to content

Commit

Permalink
Deprecate WebClient and Client.web_client
Browse files Browse the repository at this point in the history
The `WebClient` class and `Client.web_client` attribute were replaced by
the `_ComputeWebClient` class and `Client._compute_web_client` attribute,
respectively. The former will remain for backward compatibility.
  • Loading branch information
rjmello committed Dec 9, 2024
1 parent cba72ed commit 2bad74b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Deprecated
^^^^^^^^^^

- The ``WebClient`` class and ``Client.web_client`` attribute have been deprecated.
Please use the ``ComputeClient``, ``ComputeClientV2``, and ``ComputeClientV3``
classes from the `Globus Python SDK <https://globus-sdk-python.readthedocs.io/en/stable/services/compute.html>`_
to interact directly with the Globus Compute API.
22 changes: 20 additions & 2 deletions compute_sdk/globus_compute_sdk/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(
elif login_manager:
self.login_manager = login_manager
self.auth_client = login_manager.get_auth_client()
self.web_client = self.login_manager.get_web_client(
self._web_client = self.login_manager.get_web_client(
base_url=self.web_service_address
)
self._compute_web_client = _ComputeWebClient(
Expand All @@ -126,7 +126,11 @@ def __init__(
else:
self.app = app if app else get_globus_app(environment=environment)
self.auth_client = ComputeAuthClient(app=self.app)
self.web_client = WebClient(base_url=self.web_service_address, app=self.app)
self._web_client = WebClient(
base_url=self.web_service_address,
app=self.app,
_deprecation_warning=False,
)
self._compute_web_client = _ComputeWebClient(
base_url=self.web_service_address, app=self.app
)
Expand All @@ -141,6 +145,20 @@ def __init__(
if do_version_check:
self.version_check()

@property
def web_client(self):
warnings.warn(
"The 'Client.web_client' attribute is deprecated"
" and will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)
return self._web_client

@web_client.setter
def web_client(self, val: WebClient):
self._web_client = val

def version_check(self, endpoint_version: str | None = None) -> None:
"""Check this client version meets the service's minimum supported version.
Expand Down
16 changes: 12 additions & 4 deletions compute_sdk/globus_compute_sdk/sdk/web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from globus_compute_sdk.sdk.utils.uuid_like import UUID_LIKE_T
from globus_compute_sdk.serialize import ComputeSerializer
from globus_compute_sdk.version import __version__
from globus_sdk import GlobusAPIError, GlobusApp, Scope

from .auth.scopes import ComputeScopes

Expand Down Expand Up @@ -104,20 +103,29 @@ class WebClient(globus_sdk.BaseClient):
# it does not have any other effects
service_name: str = "funcx"
# use the Globus Compute-specific error class
error_class = GlobusAPIError
error_class = globus_sdk.GlobusAPIError

scopes = ComputeScopes
default_scope_requirements = [Scope(ComputeScopes.all)]
default_scope_requirements = [globus_sdk.Scope(ComputeScopes.all)]

def __init__(
self,
*,
environment: t.Optional[str] = None,
base_url: t.Optional[str] = None,
app: t.Optional[GlobusApp] = None,
app: t.Optional[globus_sdk.GlobusApp] = None,
app_name: t.Optional[str] = None,
_deprecation_warning: bool = True,
**kwargs,
):
if _deprecation_warning:
warnings.warn(
"The 'WebClient' class is deprecated."
" Please use globus_sdk.ComputeClient instead.",
category=DeprecationWarning,
stacklevel=2,
)

if base_url is None:
base_url = get_web_service_url(environment)
base_url = remove_url_path(base_url)
Expand Down
16 changes: 13 additions & 3 deletions compute_sdk/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ def gcc():
do_version_check=False,
login_manager=mock.Mock(spec=LoginManager),
)
_gcc._compute_web_client = mock.Mock(spec=_ComputeWebClient)
_gcc._compute_web_client.v2 = mock.Mock(spec=ComputeClientV2)
_gcc._compute_web_client.v3 = mock.Mock(spec=ComputeClientV3)
_gcc._compute_web_client = mock.Mock(
spec=_ComputeWebClient,
v2=mock.Mock(spec=ComputeClientV2),
v3=mock.Mock(spec=ComputeClientV3),
)

yield _gcc

Expand Down Expand Up @@ -759,3 +761,11 @@ def test_client_logout_with_login_manager():
client = gc.Client(do_version_check=False, login_manager=mock_lm)
client.logout()
assert mock_lm.logout.called


def test_web_client_deprecated():
gcc = gc.Client(do_version_check=False)
with pytest.warns(DeprecationWarning) as record:
assert gcc.web_client, "Client.web_client needed for backward compatibility"
msg = "'Client.web_client' attribute is deprecated"
assert any(msg in str(r.message) for r in record)
7 changes: 7 additions & 0 deletions compute_sdk/tests/unit/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def client():
return WebClient(base_url=_BASE_URL, transport_params={"max_retries": 0})


def test_web_client_deprecated():
with pytest.warns(DeprecationWarning) as record:
WebClient(base_url="blah")
msg = "'WebClient' class is deprecated"
assert any(msg in str(r.message) for r in record)


def test_web_client_can_set_explicit_base_url():
c1 = WebClient(base_url="https://foo.example.com/")
c2 = WebClient(base_url="https://bar.example.com/")
Expand Down

0 comments on commit 2bad74b

Please sign in to comment.