diff --git a/caveclient/chunkedgraph.py b/caveclient/chunkedgraph.py index a7f3680e..329e074c 100644 --- a/caveclient/chunkedgraph.py +++ b/caveclient/chunkedgraph.py @@ -2,14 +2,15 @@ import datetime import json import logging -from typing import Iterable, Tuple, Union +from typing import Iterable, Optional, Tuple, Union from urllib.parse import urlencode import networkx as nx import numpy as np -import pandas as pd import pytz +import pandas as pd + from .auth import AuthClient from .base import BaseEncoder, ClientBase, _api_endpoints, handle_response from .endpoints import ( @@ -182,6 +183,7 @@ def __init__( self._default_timestamp = timestamp self._table_name = table_name self._segmentation_info = None + self._semver = self._get_current_semver() @property def default_url_mapping(self): @@ -191,6 +193,48 @@ def default_url_mapping(self): def table_name(self): return self._table_name + # TODO refactor to base client + def _get_current_semver(self): + endpoint_mapping = self.default_url_mapping + url = self._endpoints["get_current_semver"].format_map(endpoint_mapping) + response = self.session.get(url) + if response.status_code == 404: # server doesn't have this endpoint yet + return None + else: + return response.json() + + @property + def major_version(self) -> Optional[int]: + if self._semver is None: + return None + else: + return int(self._semver.split(".")[0]) + + @property + def minor_version(self) -> Optional[int]: + if self._semver is None: + return None + else: + return int(self._semver.split(".")[1]) + + @property + def patch_version(self) -> Optional[int]: + if self._semver is None: + return None + else: + return int(self._semver.split(".")[2]) + + @property + def version(self) -> Optional[str]: + return self._semver + + @property + def max_version(self) -> str: + if self._semver is None: + return "2.15.0" # this is the last version that doesn't have the endpoints + else: + return self._semver + def _process_timestamp(self, timestamp): """Process timestamp with default logic""" if timestamp is None: @@ -785,11 +829,11 @@ def level2_chunk_graph(self, root_id, bounds=None) -> list: Root id of object bounds : np.array 3x2 bounding box (x,y,z) x (min,max) in chunked graph coordinates (use - `client.chunkedgraph.base_resolution` to view this default resolution for - your chunkedgraph client). Note that the result will include any level 2 - nodes which have chunk boundaries within some part of this bounding box, - meaning that the representative point for a given level 2 node could still - be slightly outside of these bounds. If None, returns all level 2 chunks + `client.chunkedgraph.base_resolution` to view this default resolution for + your chunkedgraph client). Note that the result will include any level 2 + nodes which have chunk boundaries within some part of this bounding box, + meaning that the representative point for a given level 2 node could still + be slightly outside of these bounds. If None, returns all level 2 chunks for the root ID. Returns @@ -818,7 +862,7 @@ def level2_chunk_graph(self, root_id, bounds=None) -> list: "your system administrator to update the chunkedgraph." ) raise ValueError(warning) - + r = handle_response(response) return r["edge_graph"] diff --git a/caveclient/endpoints.py b/caveclient/endpoints.py index 2bd158bb..d40f92e4 100644 --- a/caveclient/endpoints.py +++ b/caveclient/endpoints.py @@ -128,6 +128,7 @@ pcg_common = "{cg_server_address}/segmentation" chunkedgraph_endpoints_common = { "get_api_versions": pcg_common + "/api/versions", + "get_current_semver": pcg_common + "/api/current_semver", "info": pcg_common + "/table/{table_id}/info", } diff --git a/setup.py b/setup.py index f7ac297b..ade6f1d4 100644 --- a/setup.py +++ b/setup.py @@ -26,17 +26,17 @@ def find_version(*file_paths): # read the contents of README file this_directory = Path(__file__).parent -long_description = (this_directory / "README.rst").read_text() +long_description = (this_directory / "README.md").read_text() setup( version=find_version("caveclient", "__init__.py"), name="caveclient", - description="a service for interacting with the Connectome Annotation Versioning Engine", + description="A client for interacting with the Connectome Annotation Versioning Engine", long_description=long_description, - long_description_content_type="text/x-rst", + long_description_content_type="text/markdown", author="Forrest Collman, Casey Schneider-Mizell, Sven Dorkenwald", author_email="forrestc@alleninstute.org,caseys@alleninstitute.org,svenmd@princeton.edu,", - url="https://github.com/seung-lab/CAVEclient", + url="https://github.com/CAVEconnectome/CAVEclient", packages=find_packages(where="."), include_package_data=True, install_requires=required,