-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1078 from rjmello/compute-client-function-methods
Add ComputeClient methods to manage functions
- Loading branch information
Showing
12 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
changelog.d/20241008_214456_30907815+rjmello_compute_client_function_methods.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Added | ||
~~~~~ | ||
|
||
- Added ``ComputeClient.register_function()`` and ``ComputeClient.delete_function()`` | ||
methods. (:pr:`NUMBER`) | ||
|
||
- Added ``ComputeFunctionDocument`` and ``ComputeFunctionMetadata`` data classes for | ||
use with the ``ComputeClient.register_function()`` method. (:pr:`NUMBER`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from globus_sdk._testing.models import RegisteredResponse, ResponseSet | ||
|
||
from ._common import FUNCTION_ID | ||
|
||
RESPONSES = ResponseSet( | ||
metadata={"function_id": FUNCTION_ID}, | ||
default=RegisteredResponse( | ||
service="compute", | ||
path=f"/v2/functions/{FUNCTION_ID}", | ||
method="DELETE", | ||
json={"result": 302}, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from globus_sdk._testing.models import RegisteredResponse, ResponseSet | ||
|
||
from ._common import FUNCTION_CODE, FUNCTION_ID, FUNCTION_NAME | ||
|
||
RESPONSES = ResponseSet( | ||
metadata={ | ||
"function_id": FUNCTION_ID, | ||
"function_name": FUNCTION_NAME, | ||
"function_code": FUNCTION_CODE, | ||
}, | ||
default=RegisteredResponse( | ||
service="compute", | ||
path="/v2/functions", | ||
method="POST", | ||
json={"function_uuid": FUNCTION_ID}, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
from .client import ComputeClient | ||
from .data import ComputeFunctionDocument, ComputeFunctionMetadata | ||
from .errors import ComputeAPIError | ||
|
||
__all__ = ( | ||
"ComputeAPIError", | ||
"ComputeClient", | ||
"ComputeFunctionDocument", | ||
"ComputeFunctionMetadata", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from __future__ import annotations | ||
|
||
from globus_sdk import utils | ||
from globus_sdk._types import UUIDLike | ||
from globus_sdk.utils import MISSING, MissingType | ||
|
||
|
||
class ComputeFunctionMetadata(utils.PayloadWrapper): | ||
"""A wrapper for function metadata. | ||
:param python_version: The Python version used to serialize the function. | ||
:param sdk_version: The Globus Compute SDK version used to serialize the function. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
*, | ||
python_version: str | MissingType = MISSING, | ||
sdk_version: str | MissingType = MISSING, | ||
): | ||
super().__init__() | ||
self["python_version"] = python_version | ||
self["sdk_version"] = sdk_version | ||
|
||
|
||
class ComputeFunctionDocument(utils.PayloadWrapper): | ||
"""A function registration document. | ||
:param function_name: The name of the function. | ||
:param function_code: The serialized function source code. | ||
:param description: The description of the function. | ||
:param metadata: The metadata of the function. | ||
:param group: Restrict function access to members of this Globus group. | ||
:param public: Indicates whether the function is public. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
*, | ||
function_name: str, | ||
function_code: str, | ||
description: str | MissingType = MISSING, | ||
metadata: ComputeFunctionMetadata | MissingType = MISSING, | ||
group: UUIDLike | MissingType = MISSING, | ||
public: bool = False, | ||
): | ||
super().__init__() | ||
self["function_name"] = function_name | ||
self["function_code"] = function_code | ||
self["description"] = description | ||
self["metadata"] = metadata | ||
self["group"] = group | ||
self["public"] = public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import globus_sdk | ||
from globus_sdk._testing import load_response | ||
|
||
|
||
def test_delete_function(compute_client: globus_sdk.ComputeClient): | ||
meta = load_response(compute_client.delete_function).metadata | ||
res = compute_client.delete_function(function_id=meta["function_id"]) | ||
assert res.http_status == 200 | ||
assert res.data == {"result": 302} |
13 changes: 13 additions & 0 deletions
13
tests/functional/services/compute/test_register_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import globus_sdk | ||
from globus_sdk._testing import load_response | ||
from globus_sdk.services.compute import ComputeFunctionDocument | ||
|
||
|
||
def test_register_function(compute_client: globus_sdk.ComputeClient): | ||
meta = load_response(compute_client.register_function).metadata | ||
function_doc = ComputeFunctionDocument( | ||
function_name=meta["function_name"], function_code=meta["function_code"] | ||
) | ||
res = compute_client.register_function(function_doc) | ||
assert res.http_status == 200 | ||
assert res.data["function_uuid"] == meta["function_id"] |