Commit 949d5be3 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[common] Fix handling of forkable VS versionnable asset types

The lists were wrong. All assets that can be versionned are not
forkable and experiment can currently be forked but has not version
parent 7d4030f9
......@@ -151,9 +151,9 @@ class Selector(object):
self.__version = {}
self.__fork = {}
self.__versionables = [
......@@ -161,7 +161,15 @@ class Selector(object):
self.__forkables = self.__versionables + ["experiment"]
self.__forkables = [
if os.path.exists(self.path):
......@@ -187,27 +195,37 @@ class Selector(object):
if asset_type not in self.__fork:
self.__fork[asset_type] = dict()
def fork(self, type, src, dst):
def can_fork(self, asset_type):
"""Returns whether the given asset type can be forked"""
return asset_type in self.__forkables
def fork(self, asset_type, src, dst):
"""Registers that object ``dst`` is a fork of object ``src``"""
if not self.can_fork(asset_type):
raise RuntimeError("Can't create new version of {}".format(asset_type))
"`%s/%s' is forked from `%s/%s'",
self.__fork[type][dst] = src
self.__fork[asset_type][dst] = src
def forked_from(self, type, name):
def forked_from(self, asset_type, name):
"""Returns the name of the originating source object or ``None``"""
if not self.can_fork(asset_type):
return None
return self.__fork[type].get(name)
return self.__fork[asset_type].get(name)
def version(self, asset_type, src, dst):
"""Registers that object ``dst`` is a new version of object ``src``"""
if asset_type not in self.__version:
if asset_type not in self.__versionables:
raise RuntimeError("Can't create new version of {}".format(asset_type))
......@@ -230,7 +248,7 @@ class Selector(object):
def delete(self, asset_type, name):
"""Forgets about an object that was being tracked"""
if name in self.__fork[asset_type]:
if asset_type in self.__fork and name in self.__fork[asset_type]:
del self.__fork[asset_type][name]
if asset_type in self.__version and name in self.__version[asset_type]:
del self.__version[asset_type][name]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment