Skip to content

Commit

Permalink
Fixes for errors reported by mypy 1.11.0 in BaseObjectStore
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Jul 29, 2024
1 parent ad0532a commit 40b51e9
Showing 1 changed file with 146 additions and 29 deletions.
175 changes: 146 additions & 29 deletions lib/galaxy/objectstore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,35 +450,152 @@ def _get_object_id(self, obj):
def _invoke(self, delegate, obj=None, **kwargs):
return self.__getattribute__(f"_{delegate}")(obj=obj, **kwargs)

def exists(self, obj, **kwargs):
return self._invoke("exists", obj, **kwargs)
def exists(self, obj, base_dir=None, dir_only=False, extra_dir=None, extra_dir_at_root=False, alt_name=None):
return self._invoke(
"exists",
obj,
base_dir=base_dir,
dir_only=dir_only,
extra_dir=extra_dir,
extra_dir_at_root=extra_dir_at_root,
alt_name=alt_name,
)

def construct_path(self, obj, **kwargs):
return self._invoke("construct_path", obj, **kwargs)
def construct_path(
self, obj, base_dir=None, dir_only=False, extra_dir=None, extra_dir_at_root=False, alt_name=None
):
return self._invoke(
"construct_path",
obj,
base_dir=base_dir,
dir_only=dir_only,
extra_dir=extra_dir,
extra_dir_at_root=extra_dir_at_root,
alt_name=alt_name,
)

def create(self, obj, **kwargs):
return self._invoke("create", obj, **kwargs)
def create(
self, obj, base_dir=None, dir_only=False, extra_dir=None, extra_dir_at_root=False, alt_name=None, obj_dir=False
):
return self._invoke(
"create",
obj,
base_dir=base_dir,
dir_only=dir_only,
extra_dir=extra_dir,
extra_dir_at_root=extra_dir_at_root,
alt_name=alt_name,
obj_dir=obj_dir,
)

def empty(self, obj, **kwargs):
return self._invoke("empty", obj, **kwargs)
def empty(self, obj, base_dir=None, extra_dir=None, extra_dir_at_root=False, alt_name=None, obj_dir=False):
return self._invoke(
"empty",
obj,
base_dir=base_dir,
extra_dir=extra_dir,
extra_dir_at_root=extra_dir_at_root,
alt_name=alt_name,
obj_dir=obj_dir,
)

def size(self, obj, **kwargs):
return self._invoke("size", obj, **kwargs)
def size(self, obj, extra_dir=None, extra_dir_at_root=False, alt_name=None, obj_dir=False) -> int:
return self._invoke(
"size", obj, extra_dir=extra_dir, extra_dir_at_root=extra_dir_at_root, alt_name=alt_name, obj_dir=obj_dir
)

def delete(self, obj, **kwargs):
return self._invoke("delete", obj, **kwargs)
def delete(
self,
obj,
entire_dir=False,
base_dir=None,
extra_dir=None,
extra_dir_at_root=False,
alt_name=None,
obj_dir=False,
):
return self._invoke(
"delete",
obj,
entire_dir=entire_dir,
base_dir=base_dir,
extra_dir=extra_dir,
extra_dir_at_root=extra_dir_at_root,
alt_name=alt_name,
obj_dir=obj_dir,
)

def get_data(self, obj, **kwargs):
return self._invoke("get_data", obj, **kwargs)
def get_data(
self,
obj,
start=0,
count=-1,
base_dir=None,
extra_dir=None,
extra_dir_at_root=False,
alt_name=None,
obj_dir=False,
):
return self._invoke(
"get_data",
obj,
start=start,
count=count,
base_dir=base_dir,
extra_dir=extra_dir,
extra_dir_at_root=extra_dir_at_root,
alt_name=alt_name,
obj_dir=obj_dir,
)

def get_filename(self, obj, **kwargs):
return self._invoke("get_filename", obj, **kwargs)
def get_filename(
self, obj, base_dir=None, dir_only=False, extra_dir=None, extra_dir_at_root=False, alt_name=None, obj_dir=False
):
return self._invoke(
"get_filename",
obj,
base_dir=base_dir,
dir_only=dir_only,
extra_dir=extra_dir,
extra_dir_at_root=extra_dir_at_root,
alt_name=alt_name,
obj_dir=obj_dir,
)

def update_from_file(self, obj, **kwargs):
return self._invoke("update_from_file", obj, **kwargs)
def update_from_file(
self,
obj,
base_dir=None,
extra_dir=None,
extra_dir_at_root=False,
alt_name=None,
obj_dir=False,
file_name=None,
create=False,
preserve_symlinks=False,
):
return self._invoke(
"update_from_file",
obj,
base_dir=base_dir,
extra_dir=extra_dir,
extra_dir_at_root=extra_dir_at_root,
alt_name=alt_name,
obj_dir=obj_dir,
file_name=file_name,
create=create,
preserve_symlinks=preserve_symlinks,
)

def get_object_url(self, obj, **kwargs):
return self._invoke("get_object_url", obj, **kwargs)
def get_object_url(self, obj, extra_dir=None, extra_dir_at_root=False, alt_name=None, obj_dir=False):
return self._invoke(
"get_object_url",
obj,
extra_dir=extra_dir,
extra_dir_at_root=extra_dir_at_root,
alt_name=alt_name,
obj_dir=obj_dir,
)

def get_concrete_store_name(self, obj):
return self._invoke("get_concrete_store_name", obj)
Expand Down Expand Up @@ -843,7 +960,7 @@ def _create(self, obj, **kwargs):

def _empty(self, obj, **kwargs):
"""Override `ObjectStore`'s stub by checking file size on disk."""
return self.size(obj, **kwargs) == 0
return self._size(obj, **kwargs) == 0

def _size(self, obj, **kwargs) -> int:
"""Override `ObjectStore`'s stub by return file size on disk.
Expand Down Expand Up @@ -1045,7 +1162,7 @@ def _repr_object_for_exception(self, obj):
def _call_method(self, method, obj, default, default_is_exception, **kwargs):
"""Check all children object stores for the first one with the dataset."""
for store in self.backends.values():
if store.exists(obj, **kwargs):
if store._exists(obj, **kwargs):
return store.__getattribute__(method)(obj, **kwargs)
if default_is_exception:
raise default(
Expand Down Expand Up @@ -1109,22 +1226,22 @@ def __init__(

user_selection_allowed = []
for backend_def in config_dict["backends"]:
backened_id = backend_def["id"]
backend_id = backend_def["id"]
maxpctfull = backend_def.get("max_percent_full", 0)
weight = backend_def["weight"]
allow_selection = backend_def.get("allow_selection")
if allow_selection:
user_selection_allowed.append(backened_id)
user_selection_allowed.append(backend_id)
backend = build_object_store_from_config(config, config_dict=backend_def, fsmon=fsmon)

self.backends[backened_id] = backend
self.max_percent_full[backened_id] = maxpctfull
self.backends[backend_id] = backend
self.max_percent_full[backend_id] = maxpctfull

for _ in range(0, weight):
# The simplest way to do weighting: add backend ids to a
# sequence the number of times equalling weight, then randomly
# choose a backend from that sequence at creation
self.weighted_backend_ids.append(backened_id)
self.weighted_backend_ids.append(backend_id)

self.original_weighted_backend_ids = self.weighted_backend_ids
self.user_object_store_resolver = user_object_store_resolver
Expand Down Expand Up @@ -1340,7 +1457,7 @@ def __get_store_id_for(self, obj, **kwargs):
# distributed object store, or if the object's store id is invalid,
# try to locate the object
for id, store in self.backends.items():
if store.exists(obj, **kwargs):
if store._exists(obj, **kwargs):
log.warning(
f"{obj.__class__.__name__} object with ID {obj.id} found in backend object store with ID {id}"
)
Expand Down Expand Up @@ -1401,7 +1518,7 @@ def __init__(self, config, config_dict, fsmon=False):
"""The default constructor. Extends `NestedObjectStore`."""
super().__init__(config, config_dict)

backends: Dict[int, ObjectStore] = {}
backends: Dict[int, BaseObjectStore] = {}
is_private = config_dict.get("private", DEFAULT_PRIVATE)
for order, backend_def in enumerate(config_dict["backends"]):
backend_is_private = backend_def.get("private")
Expand Down

0 comments on commit 40b51e9

Please sign in to comment.