Skip to content

make ray and semver dependencies optional #3

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

Merged
merged 1 commit into from
Jun 10, 2021
Merged
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
18 changes: 11 additions & 7 deletions btrdb/utils/ray.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
from functools import partial

import ray

import semver

import btrdb
from btrdb.conn import BTrDB
from functools import partial

def register_serializer(conn_str=None, apikey=None, profile=None):
"""
Expand All @@ -24,14 +19,23 @@ def register_serializer(conn_str=None, apikey=None, profile=None):
found in the user's predictive grid credentials file
`~/.predictivegrid/credentials.yaml`.
"""
try:
import ray
except ImportError:
raise ImportError("must pip install ray to register custom serializer")
try:
import semver
except ImportError:
raise ImportError("must pip install semver to register custom serializer")

assert ray.is_initialized(), "Need to call ray.init() before registering custom serializer"
# TODO: check the version using the 'semver' package?
ver = semver.VersionInfo.parse(ray.__version__)
if ver.major == 0:
ray.register_custom_serializer(
BTrDB, serializer=btrdb_serializer, deserializer=partial(btrdb_deserializer, conn_str=conn_str, apikey=apikey, profile=profile))
elif ver.major == 1 and ver.minor in range(2, 4):
# TODO: check different versions of ray?
# TODO: check different versions of ray?
ray.util.register_serializer(
BTrDB, serializer=btrdb_serializer, deserializer=partial(btrdb_deserializer, conn_str=conn_str, apikey=apikey, profile=profile))
else:
Expand Down