Skip to content

Commit

Permalink
Use a protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonwatts committed Dec 31, 2024
1 parent 802fb42 commit ed9f9f2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
],
"python.analysis.typeCheckingMode": "basic",
"python.testing.pytestArgs": [
"--cov=servicex",
"tests"
],
"python.testing.unittestEnabled": false,
Expand Down
7 changes: 6 additions & 1 deletion servicex/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Endpoint(BaseModel):
endpoint: str
name: str
token: Optional[str] = ""
# TODO: don't know how to use ServiceXAdapterProtocol here as pydantic can't handle it
adapter: Optional[object] = None


g_registered_endpoints: List[Endpoint] = []
Expand Down Expand Up @@ -155,8 +157,11 @@ def register_endpoint(cls, ep: Endpoint):
'''Store this endpoint registration
Args:
ep (Endpoint): The endpoint to store
ep: Endpoint object to register
'''
# TODO: This requires exposing Endpoint
# There is no check in this setup that the adaptor is a valid ServiceXAdapterProtocol
# because I couldn't figure out how to make pydantic handle a protocol object.
global g_registered_endpoints
g_registered_endpoints.append(ep)

Expand Down
31 changes: 31 additions & 0 deletions servicex/protocols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import List, Protocol

from servicex.models import CachedDataset, TransformRequest, TransformStatus


class ServiceXAdapterProtocol(Protocol):
async def get_transforms(self) -> List[TransformStatus]:
...

def get_code_generators(self):
...

async def get_datasets(
self, did_finder=None, show_deleted=False
) -> List[CachedDataset]:
...

async def get_dataset(self, dataset_id=None) -> CachedDataset:
...

async def delete_dataset(self, dataset_id=None) -> bool:
...

async def delete_transform(self, transform_id=None):
...

async def submit_transform(self, transform_request: TransformRequest) -> str:
...

async def get_transform_status(self, request_id: str) -> TransformStatus:
...
21 changes: 21 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,24 @@ def test_config_register(tempdir):
# Make sure we get back what we expect
ep = endpoints["servicex-cern"]
assert ep.endpoint == "https://servicex.cern.ch"


@patch("servicex.configuration.tempfile.gettempdir", return_value="./mytemp")
def test_config_register_adaptor(tempdir):
'Make sure we can do this with an adaptor'
class MyAdaptor:
pass

Configuration.register_endpoint(
Endpoint(
name="my-adaptor",
adapter=MyAdaptor,
endpoint="",
)
)

os.environ["UserName"] = "p_higgs"
c = Configuration.read(config_path="tests/example_config.yaml")
endpoints = c.endpoint_dict()
assert len(endpoints) == 4
assert "my-adaptor" in endpoints

0 comments on commit ed9f9f2

Please sign in to comment.