From da4e44035c45af33a32de4a2470d2f5db3e2d45b Mon Sep 17 00:00:00 2001 From: Christopher Kotfila Date: Tue, 13 Feb 2018 09:07:59 -0500 Subject: [PATCH 1/2] Change transform/cleanup signatures to accept *args, **kwargs Currently transforms are expected to act solely on the state defined in their __init__ function. While this provides a clean interface, it may be too restrictive for some transforms (i.e. if a transform needs access to the task object that is calling it). Changing these signatures now hedges against making breaking changes to the API after there are a lot of these out in the wild. --- girder_worker_utils/transform.py | 6 +++--- girder_worker_utils/transforms/girder_io.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/girder_worker_utils/transform.py b/girder_worker_utils/transform.py index 5fe2b17..30c0b4e 100644 --- a/girder_worker_utils/transform.py +++ b/girder_worker_utils/transform.py @@ -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 diff --git a/girder_worker_utils/transforms/girder_io.py b/girder_worker_utils/transforms/girder_io.py index 8664266..8203526 100644 --- a/girder_worker_utils/transforms/girder_io.py +++ b/girder_worker_utils/transforms/girder_io.py @@ -34,7 +34,7 @@ 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)) @@ -42,7 +42,7 @@ def transform(self): return self.file_path - def cleanup(self): + def cleanup(self, *args, **kwargs): shutil.rmtree(os.path.dirname(self.file_path), ignore_errors=True) @@ -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 @@ -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): @@ -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) From 09b29cf5d9d176bf6fe2a18e62759f614ca468f2 Mon Sep 17 00:00:00 2001 From: Christopher Kotfila Date: Tue, 13 Feb 2018 09:54:29 -0500 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 37b2000..30acb47 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,8 @@ Bug fixes Changes ------- +* Update transform()/cleanup() methods to accept *args and **kwargs (`#21 `_) + Deprecations ------------