objectstore: yield Object not path from .new()
Instead of just returning the path of the temporary object that is created in .new() the actual instance of the new `Object` is being returned, which can then provide a richer interface for clients than a plain directory path.
This commit is contained in:
parent
52736169f1
commit
d10537da42
3 changed files with 16 additions and 16 deletions
|
|
@ -105,11 +105,11 @@ class ObjectStore:
|
|||
|
||||
@contextlib.contextmanager
|
||||
def new(self, object_id, base_id=None):
|
||||
"""Creates a new directory for `object_id`.
|
||||
"""Creates a new `Object` for `object_id`.
|
||||
|
||||
This method must be used as a context manager. It returns a path to a
|
||||
temporary directory and only commits it when the context completes
|
||||
without raising an exception.
|
||||
This method must be used as a context manager. It returns a new
|
||||
temporary instance of `Object`. It will only be committed to the
|
||||
store if the context completes without raising an exception.
|
||||
"""
|
||||
with tempfile.TemporaryDirectory(dir=self.store) as tmp:
|
||||
# the object that is yielded will be added to the content store
|
||||
|
|
@ -122,7 +122,7 @@ class ObjectStore:
|
|||
# fs supports it
|
||||
obj.init(self.resolve_ref(base_id))
|
||||
|
||||
yield obj.path
|
||||
yield obj
|
||||
|
||||
# if the yield above raises an exception, the working tree
|
||||
# is cleaned up by tempfile, otherwise, the it the content
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ class Pipeline:
|
|||
try:
|
||||
with object_store.new(self.tree_id, base_id=base) as tree:
|
||||
for stage in self.stages[base_idx + 1:]:
|
||||
r = stage.run(tree,
|
||||
r = stage.run(tree.path,
|
||||
self.runner,
|
||||
build_tree,
|
||||
store,
|
||||
|
|
@ -281,7 +281,7 @@ class Pipeline:
|
|||
var=store,
|
||||
secrets=secrets)
|
||||
if stage.checkpoint:
|
||||
object_store.snapshot(tree, stage.id)
|
||||
object_store.snapshot(tree.path, stage.id)
|
||||
results["stages"].append(r.as_dict())
|
||||
except BuildError as err:
|
||||
results["stages"].append(err.as_dict())
|
||||
|
|
@ -298,7 +298,7 @@ class Pipeline:
|
|||
r = self.assembler.run(tree,
|
||||
self.runner,
|
||||
build_tree,
|
||||
output_dir=output_dir,
|
||||
output_dir=output_dir.path,
|
||||
interactive=interactive,
|
||||
libdir=libdir,
|
||||
var=store)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class TestObjectStore(unittest.TestCase):
|
|||
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
|
||||
object_store = objectstore.ObjectStore(tmp)
|
||||
with object_store.new("a") as tree:
|
||||
p = Path(f"{tree}/A")
|
||||
p = Path(f"{tree.path}/A")
|
||||
p.touch()
|
||||
|
||||
assert os.path.exists(f"{object_store.refs}/a")
|
||||
|
|
@ -35,9 +35,9 @@ class TestObjectStore(unittest.TestCase):
|
|||
assert len(os.listdir(f"{object_store.refs}/a/")) == 1
|
||||
|
||||
with object_store.new("b") as tree:
|
||||
p = Path(f"{tree}/A")
|
||||
p = Path(f"{tree.path}/A")
|
||||
p.touch()
|
||||
p = Path(f"{tree}/B")
|
||||
p = Path(f"{tree.path}/B")
|
||||
p.touch()
|
||||
|
||||
assert os.path.exists(f"{object_store.refs}/b")
|
||||
|
|
@ -51,12 +51,12 @@ class TestObjectStore(unittest.TestCase):
|
|||
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
|
||||
object_store = objectstore.ObjectStore(tmp)
|
||||
with object_store.new("a") as tree:
|
||||
p = Path(f"{tree}/A")
|
||||
p = Path(f"{tree.path}/A")
|
||||
p.touch()
|
||||
|
||||
with object_store.new("b") as tree:
|
||||
shutil.copy2(f"{object_store.refs}/a/A",
|
||||
f"{tree}/A")
|
||||
f"{tree.path}/A")
|
||||
|
||||
assert os.path.exists(f"{object_store.refs}/a")
|
||||
assert os.path.exists(f"{object_store.refs}/a/A")
|
||||
|
|
@ -70,10 +70,10 @@ class TestObjectStore(unittest.TestCase):
|
|||
def test_snapshot(self):
|
||||
object_store = objectstore.ObjectStore(self.store)
|
||||
with object_store.new("b") as tree:
|
||||
p = Path(f"{tree}/A")
|
||||
p = Path(f"{tree.path}/A")
|
||||
p.touch()
|
||||
object_store.snapshot(tree, "a")
|
||||
p = Path(f"{tree}/B")
|
||||
object_store.snapshot(tree.path, "a")
|
||||
p = Path(f"{tree.path}/B")
|
||||
p.touch()
|
||||
|
||||
# check the references exist
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue