From bf9d20d042571afaf1f2e3eb65b59bfa8e622633 Mon Sep 17 00:00:00 2001 From: Reid Mello <30907815+rjmello@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:50:30 -0500 Subject: [PATCH] Deprecate `WebClient` and `Client.web_client` 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. --- ...llo_globus_sdk_compute_client_sc_36127.rst | 7 ++++++ compute_sdk/globus_compute_sdk/sdk/client.py | 22 +++++++++++++++++-- .../globus_compute_sdk/sdk/web_client.py | 16 ++++++++++---- compute_sdk/tests/unit/test_client.py | 16 +++++++++++--- compute_sdk/tests/unit/test_web_client.py | 7 ++++++ 5 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 changelog.d/20241209_143843_30907815+rjmello_globus_sdk_compute_client_sc_36127.rst diff --git a/changelog.d/20241209_143843_30907815+rjmello_globus_sdk_compute_client_sc_36127.rst b/changelog.d/20241209_143843_30907815+rjmello_globus_sdk_compute_client_sc_36127.rst new file mode 100644 index 000000000..973917e4e --- /dev/null +++ b/changelog.d/20241209_143843_30907815+rjmello_globus_sdk_compute_client_sc_36127.rst @@ -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 `_ + to interact directly with the Globus Compute API. diff --git a/compute_sdk/globus_compute_sdk/sdk/client.py b/compute_sdk/globus_compute_sdk/sdk/client.py index 776a57534..e307f99b6 100644 --- a/compute_sdk/globus_compute_sdk/sdk/client.py +++ b/compute_sdk/globus_compute_sdk/sdk/client.py @@ -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( @@ -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 ) @@ -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. diff --git a/compute_sdk/globus_compute_sdk/sdk/web_client.py b/compute_sdk/globus_compute_sdk/sdk/web_client.py index 549bc5770..555859222 100644 --- a/compute_sdk/globus_compute_sdk/sdk/web_client.py +++ b/compute_sdk/globus_compute_sdk/sdk/web_client.py @@ -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 @@ -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) diff --git a/compute_sdk/tests/unit/test_client.py b/compute_sdk/tests/unit/test_client.py index ab667deea..3c14f5c12 100644 --- a/compute_sdk/tests/unit/test_client.py +++ b/compute_sdk/tests/unit/test_client.py @@ -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 @@ -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) diff --git a/compute_sdk/tests/unit/test_web_client.py b/compute_sdk/tests/unit/test_web_client.py index 51d8a6905..d9e4066d8 100644 --- a/compute_sdk/tests/unit/test_web_client.py +++ b/compute_sdk/tests/unit/test_web_client.py @@ -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/")