Skip to content

Commit

Permalink
Merge branch 'master' into semver
Browse files Browse the repository at this point in the history
  • Loading branch information
bdpedigo authored Mar 27, 2024
2 parents 471f741 + 2d1f1e6 commit fe76aa0
Show file tree
Hide file tree
Showing 26 changed files with 669 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 5.16.0
current_version = 5.18.0
commit = True
tag = True

Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint and Format
on:
push:
branches:
- master
pull_request:
branches: master
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allows other workflows to trigger this workflow
workflow_call:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with: # the --extend-select flag adds import sorting
args: check . --extend-select I
- uses: chartboost/ruff-action@v1
with:
args: format . --check
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# CAVEclient

![PyPI - Version](https://img.shields.io/pypi/v/CAVEclient)
[![build status](https://github.com/CAVEconnectome/CAVEclient/actions/workflows/daily.yml/badge.svg)](https://github.com/CAVEconnectome/CAVEclient/actions/workflows/daily.yml) [![Downloads](https://static.pepy.tech/badge/caveclient)](https://pepy.tech/project/caveclient)

CAVE is short for Connectome Annotation Versioning Engine. CAVE is a set of microservices
that provide a framework for storing and versioning connectomics data and large sets of
dynamic annotations, metadata, and segmentations. This repository supplies client-side
code to easily interact with the microservices in CAVE.

A full description of the Connectome Annotation Versioning Engine can be found [in this paper](https://www.biorxiv.org/content/10.1101/2023.07.26.550598v1).

## Installation

`CAVEclient` can be installed from PyPI:
Expand All @@ -15,4 +20,4 @@ pip install caveclient

## Documentation

You can find full documentation at [caveclient.readthedocs.io](https://caveclient.readthedocs.io/).
You can find full documentation at [caveconnectome.github.io/CAVEclient](https://caveconnectome.github.io/CAVEclient).
2 changes: 1 addition & 1 deletion caveclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "5.16.0"
__version__ = "5.18.0"

from .frameworkclient import CAVEclient

Expand Down
19 changes: 10 additions & 9 deletions caveclient/base.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import urllib
import requests
import datetime
import json
import logging

logger = logging.getLogger(__name__)
import urllib
import webbrowser

from .session_config import patch_session
import numpy as np
import datetime
import pandas as pd
import requests

from .session_config import patch_session

logger = logging.getLogger(__name__)


class BaseEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray) or isinstance(obj, pd.Series):
if isinstance(obj, (np.ndarray, pd.Series, pd.Index)):
return obj.tolist()
if isinstance(obj, set):
return list(obj)
Expand Down Expand Up @@ -105,7 +106,7 @@ def _check_authorization_redirect(response):
{first_url}
with the current auth configuration.\n
Read the documentation at
https://seung-lab.github.io/CAVEclient/tutorials/authentication/
https://caveconnectome.github.io/CAVEclient/tutorials/authentication/
or follow instructions under
client.auth.get_new_token() for how to set a valid API token.
after initializing a global client with
Expand Down Expand Up @@ -149,7 +150,7 @@ def _api_endpoints(
verify=verify,
)
avail_vs_server = set(avail_vs_server)
except:
except: # noqa: E722
avail_vs_server = None

avail_vs_client = set(endpoint_versions.keys())
Expand Down
5 changes: 3 additions & 2 deletions caveclient/chunkedgraph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PyChunkedgraph service python interface"""

import datetime
import json
import logging
Expand Down Expand Up @@ -852,6 +853,8 @@ def level2_chunk_graph(self, root_id, bounds=None) -> list:
url = self._endpoints["lvl2_graph"].format_map(endpoint_mapping)
response = self.session.get(url, params=query_d)

r = handle_response(response)

used_bounds = response.headers.get("Used-Bounds")
used_bounds = used_bounds == "true" or used_bounds == "True"
if bounds is not None and not used_bounds:
Expand All @@ -863,8 +866,6 @@ def level2_chunk_graph(self, root_id, bounds=None) -> list:
)
raise ValueError(warning)

r = handle_response(response)

return r["edge_graph"]

def remesh_level2_chunks(self, chunk_ids) -> None:
Expand Down
7 changes: 4 additions & 3 deletions caveclient/datastack_lookup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import json
from . import auth
import logging
import os

from . import auth

logger = logging.getLogger(__name__)

Expand All @@ -16,7 +17,7 @@ def read_map(filename=None):
with open(os.path.expanduser(filename), "r") as f:
data = json.load(f)
return data
except:
except: # noqa E722
return {}


Expand Down
58 changes: 55 additions & 3 deletions caveclient/emannotationschemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from __future__ import annotations

import logging

from requests import HTTPError

from .auth import AuthClient
from .base import ClientBase, _api_endpoints, handle_response
from .endpoints import schema_api_versions, schema_endpoints_common
from .auth import AuthClient

logger = logging.getLogger(__name__)

server_key = "emas_server_address"

Expand Down Expand Up @@ -65,7 +73,7 @@ def __init__(
over_client=over_client,
)

def get_schemas(self):
def get_schemas(self) -> list[str]:
"""Get the available schema types
Returns
Expand All @@ -78,7 +86,7 @@ def get_schemas(self):
response = self.session.get(url)
return handle_response(response)

def schema_definition(self, schema_type):
def schema_definition(self, schema_type: str) -> dict[str]:
"""Get the definition of a specified schema_type
Parameters
Expand All @@ -97,6 +105,50 @@ def schema_definition(self, schema_type):
response = self.session.get(url)
return handle_response(response)

def schema_definition_multi(self, schema_types: list[str]) -> dict:
"""Get the definition of multiple schema_types
Parameters
----------
schema_types : list
List of schema names
Returns
-------
dict
Dictionary of schema definitions. Keys are schema names, values are definitions.
"""
endpoint_mapping = self.default_url_mapping
url = self._endpoints["schema_definition_multi"].format_map(endpoint_mapping)
data = {"schema_names": ",".join(schema_types)}
response = self.session.post(url, params=data)
try:
return handle_response(response)
except HTTPError:
logger.warning(
'Client requested an schema service endpoint (see "schema_definition_multi") not yet available on your deployment. Please talk to your admin about updating your deployment'
)
return None

def schema_definition_all(self) -> dict[str]:
"""Get the definition of all schema_types
Returns
-------
dict
Dictionary of schema definitions. Keys are schema names, values are definitions.
"""
endpoint_mapping = self.default_url_mapping
url = self._endpoints["schema_definition_all"].format_map(endpoint_mapping)
response = self.session.get(url)
try:
return handle_response(response)
except HTTPError:
logger.warning(
'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,
Expand Down
2 changes: 2 additions & 0 deletions caveclient/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@
schema_endpoints_v2 = {
"schema": schema_v2 + "/type",
"schema_definition": schema_v2 + "/type/{schema_type}",
"schema_definition_multi": schema_v2 + "/types",
"schema_definition_all": schema_v2 + "/types_all",
}

schema_api_versions = {1: schema_endpoints_v1, 2: schema_endpoints_v2}
Expand Down
Loading

0 comments on commit fe76aa0

Please sign in to comment.