Skip to content

Commit

Permalink
add semver versioning example
Browse files Browse the repository at this point in the history
  • Loading branch information
bdpedigo committed Mar 27, 2024
1 parent c3d4de3 commit 471f741
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
60 changes: 52 additions & 8 deletions caveclient/chunkedgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions caveclient/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected],[email protected],[email protected],",
url="https://github.com/seung-lab/CAVEclient",
url="https://github.com/CAVEconnectome/CAVEclient",
packages=find_packages(where="."),
include_package_data=True,
install_requires=required,
Expand Down

0 comments on commit 471f741

Please sign in to comment.