-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Description
For 0.1.3 I removed the cumbersome path-based system for running analyses, upgrading to the Runner() class.
However, this has the side effect of no longer having self-made paths. It'll be more flexible, because a dataset can sit there on a system with a fixed path regardless of which analysis it belongs to... but means there's no baked-in path on the dataset.
We need to resolve this, either by attaching a path index to the Analysis instance which manages that all... or by doing something like a mixin that gets instantiated with the appropriate path and local_path_prefix.
Inspired by the Datafile class this might look something like the following, but I haven't figured out a way to instantiate it yet which will then be easily used.
import os
import uuid
from octue.exceptions import InvalidInputException
from octue.utils import gen_uuid
class Pathable:
""" Mixin to allow a class to have a path attribute (which may be a directory or file path and name)
Prevents setting path after an object is instantiated.
```
class MyResource(Pathable):
pass
MyResource().id # Some generated uuid
MyResource(id='not_a_uuid') # Raises exception
MyResource(id='a10603a0-194c-40d0-a7b7-fcf9952c3690').id # That same uuid
```
"""
_path_field = None
def __init__(self, *args, path=None, local_path_prefix=".", **kwargs):
""" Constructor for Pathable class
# TODO Update datafile to use this mixin
"""
super().__init__(*args, **kwargs)
path = path or self._get_default_path()
self._path = self._clean_path(path)
self.local_path_prefix = str(os.path.abspath(local_path_prefix))
def _get_default_path(self):
if self._path_field is not None:
return str(getattr(self, self._path_field))
@staticmethod
def _clean_path(path):
if path is not None:
return str(os.path.normpath(path)).lstrip(r"\/")
@property
def name(self):
return str(os.path.split(self.path)[-1])
@property
def full_path(self):
return os.path.join(self.local_path_prefix, self.path)
@property
def path(self):
return self._pathMetadata
Metadata
Assignees
Labels
No labels