Use DataLocator consistently on backend (#1208)

* allow DataLocator to accept another locator as init param

* migrate to DataLocator

* migrate to DataLocator

* lint

* migrate to DataLocator

* add check for erroroneous use of remote path and annotations

* lint

* revert default data location - now back go CWD

* remove unused import
This commit is contained in:
Bruce Martin
2020-03-10 19:12:49 -07:00
committed by GitHub
parent 234f25b782
commit 8beeb57c96
6 changed files with 46 additions and 30 deletions
+8 -6
View File
@@ -10,7 +10,6 @@ from server.common.errors import FilterError, JSONEncodingValueError
from server.compute.diffexp import diffexp_ttest
from server.common.utils import jsonify_numpy
from server.common.app_config import AppFeature, AppConfig
from server.common.data_locator import DataLocator
class DataAdaptor(metaclass=ABCMeta):
@@ -32,17 +31,17 @@ class DataAdaptor(metaclass=ABCMeta):
@staticmethod
@abstractmethod
def pre_load_validation(location):
def pre_load_validation(data_locator):
pass
@staticmethod
@abstractmethod
def open(location, config):
def open(data_locator, config):
pass
@staticmethod
@abstractmethod
def file_size(location):
def file_size(data_locator):
pass
@abstractmethod
@@ -105,6 +104,10 @@ class DataAdaptor(metaclass=ABCMeta):
def get_location(self):
pass
@abstractmethod
def get_data_locator(self):
pass
def get_about(self):
return None
@@ -345,8 +348,7 @@ class DataAdaptor(metaclass=ABCMeta):
def get_last_mod_time(self):
try:
data_locator = DataLocator(self.get_location())
lastmod = data_locator.lastmodtime()
lastmod = self.get_data_locator().lastmodtime()
except RuntimeError:
lastmod = None
return lastmod
+5 -3
View File
@@ -3,6 +3,7 @@ import threading
import time
from server.data_common.rwlock import RWLock
from server.common.errors import DatasetAccessError
from server.common.data_locator import DataLocator
from contextlib import contextmanager
@@ -136,7 +137,8 @@ class MatrixDataType(Enum):
class MatrixDataLoader(object):
def __init__(self, location, etype=None):
self.location = location
""" location can be a string or DataLocator """
self.location = DataLocator(location)
if etype is None:
self.etype = self.matrix_data_type()
else:
@@ -152,9 +154,9 @@ class MatrixDataLoader(object):
self.matrix_type = CxgAdaptor
def matrix_data_type(self):
if self.location.endswith(".h5ad"):
if self.location.path.endswith(".h5ad"):
return MatrixDataType.H5AD
elif ".cxg" in self.location:
elif ".cxg" in self.location.path:
return MatrixDataType.CXG
else:
return MatrixDataType.UNKNOWN