Skip to content

Commit

Permalink
remove factory (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdpedigo authored Sep 11, 2024
1 parent 3a180ac commit 5700261
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 55 deletions.
74 changes: 21 additions & 53 deletions caveclient/emannotationschemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,38 @@

logger = logging.getLogger(__name__)

server_key = "emas_server_address"


def SchemaClient(
server_address=None,
auth_client=None,
api_version="latest",
max_retries=None,
pool_maxsize=None,
pool_block=None,
over_client=None,
) -> "SchemaClientLegacy":
if auth_client is None:
auth_client = AuthClient()

auth_header = auth_client.request_header
endpoints, api_version = _api_endpoints(
api_version,
server_key,
server_address,
schema_endpoints_common,
schema_api_versions,
auth_header,
)
SchemaClient = client_mapping[api_version]
return SchemaClient(
server_address=server_address,
auth_header=auth_header,
api_version=api_version,
endpoints=endpoints,
server_name=server_key,
max_retries=max_retries,
pool_maxsize=pool_maxsize,
pool_block=pool_block,
over_client=over_client,
)


class SchemaClientLegacy(ClientBase):
SERVER_KEY = "emas_server_address"


class SchemaClient(ClientBase):
def __init__(
self,
server_address,
auth_header,
api_version,
endpoints,
server_name,
server_address=None,
auth_client=None,
api_version="latest",
max_retries=None,
pool_maxsize=None,
pool_block=None,
over_client=None,
):
super(SchemaClientLegacy, self).__init__(
if auth_client is None:
auth_client = AuthClient()

auth_header = auth_client.request_header
endpoints, api_version = _api_endpoints(
api_version,
SERVER_KEY,
server_address,
schema_endpoints_common,
schema_api_versions,
auth_header,
)
super(SchemaClient, self).__init__(
server_address,
auth_header,
api_version,
endpoints,
server_name,
SERVER_KEY,
max_retries=max_retries,
pool_maxsize=pool_maxsize,
pool_block=pool_block,
Expand Down Expand Up @@ -148,10 +123,3 @@ def schema_definition_all(self) -> dict[str]:
'Client requested an schema service endpoint (see "schema_definition_all") not yet available on your deployment. Please talk to your admin about updating your deployment'
)
return None


client_mapping = {
1: SchemaClientLegacy,
2: SchemaClientLegacy,
"latest": SchemaClientLegacy,
}
4 changes: 2 additions & 2 deletions caveclient/frameworkclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .auth import AuthClient, default_token_file
from .chunkedgraph import ChunkedGraphClient
from .datastack_lookup import handle_server_address
from .emannotationschemas import SchemaClient, SchemaClientLegacy
from .emannotationschemas import SchemaClient
from .endpoints import default_global_server_address
from .infoservice import InfoServiceClient
from .jsonservice import JSONService, JSONServiceV1
Expand Down Expand Up @@ -288,7 +288,7 @@ def state(self) -> JSONServiceV1:
return self._state

@property
def schema(self) -> SchemaClientLegacy:
def schema(self) -> SchemaClient:
"""
A client for the EM Annotation Schemas service. See [client.schema](../client_api/schema.md)
for more information.
Expand Down

0 comments on commit 5700261

Please sign in to comment.