Skip to content

Commit

Permalink
Deprecate WebClient and Client.web_client
Browse files Browse the repository at this point in the history
All uses of 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 in place for backward
compatibility.
  • Loading branch information
rjmello committed Dec 10, 2024
1 parent 956fd05 commit bd5866e
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 13 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.
1 change: 1 addition & 0 deletions compute_endpoint/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def get_web_client(self, *, base_url: str | None = None) -> WebClient:
return WebClient(
base_url="https://compute.api.globus.org",
authorizer=globus_sdk.NullAuthorizer(),
_deprecation_warning=False,
)


Expand Down
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 @@ -129,7 +129,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 @@ -138,7 +138,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 @@ -153,6 +157,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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def get_web_client(
base_url=base_url,
app_name=app_name,
authorizer=self.authorizers[ComputeScopes.resource_server],
_deprecation_warning=False,
)

def ensure_logged_in(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,5 @@ def get_web_client(
base_url=base_url,
app_name=app_name,
authorizer=self._get_authorizer(ComputeScopes.resource_server),
_deprecation_warning=False,
)
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
6 changes: 5 additions & 1 deletion compute_sdk/tests/integration/test_web_client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def mocked_responses():
@pytest.fixture
def client():
# for the default test client, set a fake URL and disable retries
return WebClient(base_url="https://api.funcx", transport_params={"max_retries": 0})
return WebClient(
base_url="https://api.funcx",
transport_params={"max_retries": 0},
_deprecation_warning=False,
)


@pytest.mark.parametrize("http_status", [400, 500])
Expand Down
10 changes: 9 additions & 1 deletion compute_sdk/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ def test_client_handles_globus_app(
assert client.web_client is mock_web_client.return_value
assert client._compute_web_client is mock_compute_web_client.return_value
mock_web_client.assert_called_once_with(
base_url=client.web_service_address, app=mock_app
base_url=client.web_service_address, app=mock_app, _deprecation_warning=False
)
mock_compute_web_client.assert_called_once_with(
base_url=client.web_service_address, app=mock_app
Expand Down Expand Up @@ -768,3 +768,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)
19 changes: 15 additions & 4 deletions compute_sdk/tests/unit/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,23 @@ def mocked_responses():
@pytest.fixture
def client():
# for the default test client, set a fake URL and disable retries
return WebClient(base_url=_BASE_URL, transport_params={"max_retries": 0})
return WebClient(
base_url=_BASE_URL,
transport_params={"max_retries": 0},
_deprecation_warning=False,
)


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/")
c1 = WebClient(base_url="https://foo.example.com/", _deprecation_warning=False)
c2 = WebClient(base_url="https://bar.example.com/", _deprecation_warning=False)
assert c1.base_url == "https://foo.example.com/"
assert c2.base_url == "https://bar.example.com/"

Expand Down Expand Up @@ -64,7 +75,7 @@ def test_get_version_service_param(client, service_param):

@pytest.mark.parametrize("app_name", [None, str(uuid.uuid4())])
def test_app_name_value(app_name: str | None):
wc = WebClient(base_url=_BASE_URL, app_name=app_name)
wc = WebClient(base_url=_BASE_URL, app_name=app_name, _deprecation_warning=False)
if app_name is None:
assert wc.app_name == f"globus-compute-sdk-{__version__}"
else:
Expand Down
6 changes: 5 additions & 1 deletion smoke_tests/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ def get_auth_client(self) -> AuthClient:
return AuthClient(authorizer=auth_authorizer)

def get_web_client(self, *, base_url: str | None = None) -> WebClient:
return WebClient(base_url=base_url, authorizer=funcx_authorizer)
return WebClient(
base_url=base_url,
authorizer=funcx_authorizer,
_deprecation_warning=False,
)

login_manager = TestsuiteLoginManager()

Expand Down

0 comments on commit bd5866e

Please sign in to comment.