Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Change transform/cleanup signatures to accept *args, **kwargs #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Bug fixes
Changes
-------

* Update transform()/cleanup() methods to accept *args and **kwargs (`#21 <https://github.com/girder/girder_worker_utils/pull/21>`_)

Deprecations
------------

Expand Down
6 changes: 3 additions & 3 deletions girder_worker_utils/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ def _repr_model_(self):
"""
return str(self)

def cleanup(self):
def cleanup(self, *args, **kwargs):
pass

@abc.abstractmethod
def transform(self):
def transform(self, *args, **kwargs):
pass


@six.add_metaclass(abc.ABCMeta)
class ResultTransform(Transform):
@abc.abstractmethod
def transform(self, data):
def transform(self, data, *args, **kwargs):
pass
10 changes: 5 additions & 5 deletions girder_worker_utils/transforms/girder_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def __init__(self, _id, **kwargs):
def _repr_model_(self):
return "{}('{}')".format(self.__class__.__name__, self.file_id)

def transform(self):
def transform(self, *args, **kwargs):
self.file_path = os.path.join(
tempfile.mkdtemp(), '{}'.format(self.file_id))

self.gc.downloadFile(self.file_id, self.file_path)

return self.file_path

def cleanup(self):
def cleanup(self, *args, **kwargs):
shutil.rmtree(os.path.dirname(self.file_path),
ignore_errors=True)

Expand All @@ -55,7 +55,7 @@ def __init__(self, _id, **kwargs):
def _repr_model_(self):
return "{}('{}')".format(self.__class__.__name__, self.item_id)

def transform(self, data):
def transform(self, data, *args, **kwargs):
self.gc.addMetadataToItem(self.item_id, data)

return data
Expand All @@ -71,7 +71,7 @@ def __init__(self, _id, delete_file=False, upload_kwargs=None, **kwargs):
def _repr_model_(self):
return "{}('{}')".format(self.__class__.__name__, self.item_id)

def transform(self, path):
def transform(self, path, *args, **kwargs):
self.output_file_path = path
if os.path.isdir(path):
for f in os.listdir(path):
Expand All @@ -82,7 +82,7 @@ def transform(self, path):
self.gc.uploadFileToItem(self.item_id, path, **self.upload_kwargs)
return self.item_id

def cleanup(self):
def cleanup(self, *args, **kwargs):
if self.delete_file is True:
if os.path.isdir(self.output_file_path):
shutil.rmtree(self.output_file_path)
Expand Down