Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove factory syntax for subclients #222

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 37 additions & 85 deletions caveclient/annotationengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,116 +12,74 @@
SERVER_KEY = "ae_server_address"


def AnnotationClient(
server_address,
dataset_name=None,
aligned_volume_name=None,
auth_client=None,
api_version="latest",
verify=True,
max_retries=None,
pool_maxsize=None,
pool_block=None,
over_client=None,
) -> "AnnotationClientV2":
"""Factory for returning AnnotationClient
class AnnotationClient(ClientBase):
"""
Client for interacting with the annotation engine.

Parameters
----------
server_address : str
server_address to use to connect to (i.e. https://minniev1.microns-daf.com)
dataset_name : str
Name of the datastack.
aligned_volume_name : str
Name of the aligned volume to use.
auth_client : AuthClient or None, optional
Authentication client to use to connect to server. If None, do not use authentication.
Authentication client to use to connect to server. If None, do not use
authentication.
api_version : str or int (default: latest)
What version of the api to use, 0: Legacy client (i.e www.dynamicannotationframework.com)
2: new api version, (i.e. minniev1.microns-daf.com)
'latest': default to the most recent (current 2)
verify : str (default : True)
whether to verify https
Whether to verify https
max_retries : Int or None, optional
Set the number of retries per request, by default None. If None, defaults to requests package default.
Set the number of retries per request, by default None. If None, defaults to
requests package default.
pool_block : Bool or None, optional
If True, restricts pool of threads to max size, by default None. If None, defaults to requests package default.
If True, restricts pool of threads to max size, by default None. If None,
defaults to requests package default.
pool_maxsize : Int or None, optional
Sets the max number of threads in the pool, by default None. If None, defaults to requests package default.
Sets the max number of threads in the pool, by default None. If None, defaults
to requests package default.
over_client:
client to overwrite configuration with

Returns
-------
ClientBaseWithDatastack
List of datastack names for available datastacks on the annotation engine
Client to overwrite configuration with.
schema_client:
Client to use to get schema information. If None, uses the `over_client`'s
schema client.
"""

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,
annotation_common,
annotation_api_versions,
auth_header,
verify=verify,
)

AnnoClient = client_mapping[api_version]
if api_version > 1:
return AnnoClient(
server_address,
auth_header,
api_version,
endpoints,
SERVER_KEY,
aligned_volume_name,
verify=verify,
max_retries=max_retries,
pool_maxsize=pool_maxsize,
pool_block=pool_block,
over_client=over_client,
)
else:
return AnnoClient(
server_address,
auth_header,
api_version,
endpoints,
SERVER_KEY,
dataset_name,
verify=verify,
max_retries=max_retries,
pool_maxsize=pool_maxsize,
pool_block=pool_block,
over_client=over_client,
)


class AnnotationClientV2(ClientBase):
def __init__(
self,
server_address,
auth_header,
api_version,
endpoints,
server_name,
aligned_volume_name,
aligned_volume_name=None,
auth_client=None,
api_version="latest",
verify=True,
max_retries=None,
pool_maxsize=None,
pool_block=None,
over_client=None,
schema_client=None,
):
super(AnnotationClientV2, 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,
annotation_common,
annotation_api_versions,
auth_header,
verify=verify,
)

super(AnnotationClient, self).__init__(
server_address,
auth_header,
api_version,
endpoints,
server_name,
SERVER_KEY,
verify=verify,
max_retries=max_retries,
pool_maxsize=pool_maxsize,
Expand Down Expand Up @@ -857,9 +815,3 @@ def upload_staged_annotations(
staged_annos.annotation_list,
aligned_volume_name=aligned_volume_name,
)


client_mapping = {
2: AnnotationClientV2,
"latest": AnnotationClientV2,
}
5 changes: 4 additions & 1 deletion caveclient/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ def server_version(self) -> Optional[Version]:
"""The version of the service running on the remote server. Note that this
refers to the software running on the server and has nothing to do with the
version of the datastack itself."""
return self._server_version
if self._server_version is None and self._api_version is not None:
return Version(str(self._api_version))
else:
return self._server_version

@staticmethod
def raise_for_status(r, log_warning=True):
Expand Down
86 changes: 24 additions & 62 deletions caveclient/chunkedgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,77 +108,45 @@ def root_id_int_list_check(
return root_id


def ChunkedGraphClient(
server_address=None,
table_name=None,
auth_client=None,
api_version="latest",
timestamp=None,
verify=True,
max_retries=None,
pool_maxsize=None,
pool_block=None,
over_client=None,
) -> "ChunkedGraphClientV1":
if server_address is None:
server_address = default_global_server_address

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,
chunkedgraph_endpoints_common,
chunkedgraph_api_versions,
auth_header,
verify=verify,
)

ChunkedClient = client_mapping[api_version]
return ChunkedClient(
server_address,
auth_header,
api_version,
endpoints,
SERVER_KEY,
timestamp=timestamp,
table_name=table_name,
verify=verify,
max_retries=max_retries,
pool_maxsize=pool_maxsize,
pool_block=pool_block,
over_client=over_client,
)


class ChunkedGraphClientV1(ClientBase):
class ChunkedGraphClient(ClientBase):
"""ChunkedGraph Client for the v1 API"""

def __init__(
self,
server_address,
auth_header,
api_version,
endpoints,
server_key=SERVER_KEY,
timestamp=None,
server_address=None,
table_name=None,
auth_client=None,
api_version="latest",
timestamp=None,
verify=True,
max_retries=None,
pool_maxsize=None,
pool_block=None,
over_client=None,
):
super(ChunkedGraphClientV1, self).__init__(
if server_address is None:
server_address = default_global_server_address

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,
chunkedgraph_endpoints_common,
chunkedgraph_api_versions,
auth_header,
verify=verify,
)
super(ChunkedGraphClient, self).__init__(
server_address,
auth_header,
api_version,
endpoints,
server_key,
SERVER_KEY,
verify=verify,
max_retries=max_retries,
pool_maxsize=pool_maxsize,
Expand Down Expand Up @@ -1502,9 +1470,3 @@ def base_resolution(self):
3-long list of x/y/z voxel dimensions in nm
"""
return self.segmentation_info["scales"][0].get("resolution")


client_mapping = {
1: ChunkedGraphClientV1,
"latest": ChunkedGraphClientV1,
}
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,
}
Loading
Loading