summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2017-07-14 10:19:20 +0200
committerJürg Billeter <j@bitron.ch>2017-07-14 14:13:51 +0200
commit0fc743f19a95b789651108981570f6239d1c01c7 (patch)
tree20ab60e6afce8192ce30735f5ec079bf9f55c01a
parenta37ff7d129b438c863d88998309007b000e4cb77 (diff)
downloadbuildstream-0fc743f19a95b789651108981570f6239d1c01c7.tar.gz
Move ArtifactError to exceptions.py
This avoids cyclic imports between element.py and artifactcache.py.
-rw-r--r--buildstream/_artifactcache/__init__.py2
-rw-r--r--buildstream/_artifactcache/artifactcache.py29
-rw-r--r--buildstream/element.py5
-rw-r--r--buildstream/exceptions.py4
-rw-r--r--tests/artifactcache/basics.py5
5 files changed, 22 insertions, 23 deletions
diff --git a/buildstream/_artifactcache/__init__.py b/buildstream/_artifactcache/__init__.py
index 76ee871f4..638575f5a 100644
--- a/buildstream/_artifactcache/__init__.py
+++ b/buildstream/_artifactcache/__init__.py
@@ -18,7 +18,7 @@
# Authors:
# Tristan Van Berkom <tristan.vanberkom@codethink.co.uk>
-from .artifactcache import ArtifactCache, ArtifactError
+from .artifactcache import ArtifactCache
# Entry points for our local ostree-push implementation
from .pushreceive import receive_main
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py
index 0693515bf..9435321c8 100644
--- a/buildstream/_artifactcache/artifactcache.py
+++ b/buildstream/_artifactcache/artifactcache.py
@@ -22,19 +22,14 @@ import os
import tempfile
from .. import _ostree, utils
-from ..exceptions import _BstError
+from ..exceptions import _ArtifactError
from .._ostree import OSTreeError
from .pushreceive import push as push_artifact
from .pushreceive import PushException
-# For users of this file, they must expect (except) it.
-class ArtifactError(_BstError):
- pass
-
-
-def buildref(element):
+def buildref(element, key):
project = element.get_project()
key = element._get_cache_key()
@@ -109,7 +104,7 @@ class ArtifactCache():
# element (Element): The Element to extract
#
# Raises:
- # ArtifactError: In cases there was an OSError, or if the artifact
+ # _ArtifactError: In cases there was an OSError, or if the artifact
# did not exist.
#
# Returns: path to extracted artifact
@@ -125,7 +120,7 @@ class ArtifactCache():
# resolve ref to checksum
rev = _ostree.checksum(self.repo, ref)
if not rev:
- raise ArtifactError("Artifact missing for {}".format(ref))
+ raise _ArtifactError("Artifact missing for {}".format(ref))
os.makedirs(self.extractdir, exist_ok=True)
with tempfile.TemporaryDirectory(prefix='tmp', dir=self.extractdir) as tmpdir:
@@ -144,8 +139,8 @@ class ArtifactCache():
# If rename fails with these errors, another process beat
# us to it so just ignore.
if e.errno not in [os.errno.ENOTEMPTY, os.errno.EEXIST]:
- raise ArtifactError("Failed to extract artifact for ref '{}': {}"
- .format(ref, e)) from e
+ raise _ArtifactError("Failed to extract artifact for ref '{}': {}"
+ .format(ref, e)) from e
return dest
@@ -186,15 +181,15 @@ class ArtifactCache():
elif self.remote is not None:
remote = self.remote
else:
- raise ArtifactError("Attempt to pull artifact without any pull URL")
+ raise _ArtifactError("Attempt to pull artifact without any pull URL")
ref = buildref(element)
try:
_ostree.fetch(self.repo, remote=remote,
ref=ref, progress=progress)
except OSTreeError as e:
- raise ArtifactError("Failed to pull artifact for element {}: {}"
- .format(element.name, e)) from e
+ raise _ArtifactError("Failed to pull artifact for element {}: {}"
+ .format(element.name, e)) from e
# can_push():
#
@@ -217,11 +212,11 @@ class ArtifactCache():
# and no updated was required
#
# Raises:
- # ArtifactError if there was an error
+ # _ArtifactError if there was an error
def push(self, element):
if self.context.artifact_push is None:
- raise ArtifactError("Attempt to push artifact without any push URL")
+ raise _ArtifactError("Attempt to push artifact without any push URL")
ref = buildref(element)
if self.context.artifact_push.startswith("/"):
@@ -252,6 +247,6 @@ class ArtifactCache():
self.context.artifact_push_port,
ref, output_file)
except PushException as e:
- raise ArtifactError("Failed to push artifact {}: {}".format(ref, e)) from e
+ raise _ArtifactError("Failed to push artifact {}: {}".format(ref, e)) from e
return pushed
diff --git a/buildstream/element.py b/buildstream/element.py
index db2fd44b1..dbdae352c 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -33,10 +33,9 @@ import shutil
from . import _yaml
from ._yaml import CompositePolicy
from ._variables import Variables
-from .exceptions import _BstError
+from .exceptions import _BstError, _ArtifactError
from . import LoadError, LoadErrorReason, ElementError, ImplError
from ._sandboxbwrap import SandboxBwrap
-from ._artifactcache import ArtifactError
from . import Sandbox, SandboxFlags
from . import Plugin, Consistency
from . import utils
@@ -940,7 +939,7 @@ class Element(Plugin):
display_key = self._get_display_key()
self.info("Downloaded artifact {}".format(display_key))
downloaded = True
- except ArtifactError:
+ except _ArtifactError:
# Just return false, so that the frontend knows that
# the artifact was not downloaded
#
diff --git a/buildstream/exceptions.py b/buildstream/exceptions.py
index b28a9c22a..039551c16 100644
--- a/buildstream/exceptions.py
+++ b/buildstream/exceptions.py
@@ -128,3 +128,7 @@ class ProgramNotFoundError(_BstError):
bubblewrap is installed for it to work.
"""
pass
+
+
+class _ArtifactError(_BstError):
+ pass
diff --git a/tests/artifactcache/basics.py b/tests/artifactcache/basics.py
index c7661820c..6fc8a8b7c 100644
--- a/tests/artifactcache/basics.py
+++ b/tests/artifactcache/basics.py
@@ -3,7 +3,8 @@ import pytest
import tempfile
from buildstream import Context, Project
-from buildstream._artifactcache import ArtifactCache, ArtifactError
+from buildstream.exceptions import _ArtifactError
+from buildstream._artifactcache import ArtifactCache
from buildstream._pipeline import Pipeline
DATA_DIR = os.path.join(
@@ -30,7 +31,7 @@ def test_empty_contains(pipeline):
# Test that we get an ArtifactError when trying to extract a nonexistent artifact
def test_empty_extract(pipeline):
- with pytest.raises(ArtifactError) as exc:
+ with pytest.raises(_ArtifactError) as exc:
pipeline.artifacts.extract(pipeline.target)