summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <bschubert15@bloomberg.net>2019-11-28 17:50:51 +0000
committerBenjamin Schubert <bschubert15@bloomberg.net>2020-01-16 16:33:19 +0000
commit5cb2442e789d6b302f7d261ba5d2a2ad5366d7c2 (patch)
tree172dcee0a766d70fb80c0b41d086c873a0268b44
parent3be6d07753599ef54b9e80ac066571632e217ce2 (diff)
downloadbuildstream-5cb2442e789d6b302f7d261ba5d2a2ad5366d7c2.tar.gz
source.py: Remove 'get_consistency' completely
This is not needed now that we have 'is_resolved' and 'is_cached'. We can therefore drop all calling places and implementations of it.
-rw-r--r--src/buildstream/__init__.py2
-rw-r--r--src/buildstream/_gitsourcebase.py9
-rw-r--r--src/buildstream/element.py3
-rw-r--r--src/buildstream/plugin.py4
-rw-r--r--src/buildstream/plugins/sources/_downloadablefilesource.py16
-rw-r--r--src/buildstream/plugins/sources/bzr.py13
-rw-r--r--src/buildstream/plugins/sources/local.py5
-rw-r--r--src/buildstream/plugins/sources/patch.py5
-rw-r--r--src/buildstream/plugins/sources/pip.py9
-rw-r--r--src/buildstream/plugins/sources/workspace.py10
-rw-r--r--src/buildstream/source.py51
-rw-r--r--tests/format/project/plugin-no-load-ref/plugins/noloadref.py5
-rw-r--r--tests/format/project/plugin-preflight-error/errorplugin/preflighterror.py5
-rw-r--r--tests/frontend/consistencyerror/plugins/consistencybug.py3
-rw-r--r--tests/frontend/consistencyerror/plugins/consistencyerror.py3
-rw-r--r--tests/frontend/project/sources/fetch_source.py11
-rw-r--r--tests/internals/pluginloading/badversionsource/customsources/foo.py5
-rw-r--r--tests/internals/pluginloading/customsource/pluginsources/foo.py5
-rw-r--r--tests/sources/git.py2
-rw-r--r--tests/sources/no-fetch-cached/plugins/sources/always_cached.py5
-rw-r--r--tests/sources/previous_source_access/plugins/sources/foo_transform.py16
-rw-r--r--tests/sources/project_key_test/plugins/sources/key-test.py8
22 files changed, 32 insertions, 163 deletions
diff --git a/src/buildstream/__init__.py b/src/buildstream/__init__.py
index c78fcbbf6..c68c63e39 100644
--- a/src/buildstream/__init__.py
+++ b/src/buildstream/__init__.py
@@ -30,7 +30,7 @@ if "_BST_COMPLETION" not in os.environ:
from .utils import UtilError, ProgramNotFoundError
from .sandbox import Sandbox, SandboxFlags, SandboxCommandError
- from .types import Scope, Consistency, CoreWarnings
+ from .types import Scope, CoreWarnings
from .node import MappingNode, Node, ProvenanceInformation, ScalarNode, SequenceNode
from .plugin import Plugin
from .source import Source, SourceError, SourceFetcher
diff --git a/src/buildstream/_gitsourcebase.py b/src/buildstream/_gitsourcebase.py
index 125d34df4..a8253e36f 100644
--- a/src/buildstream/_gitsourcebase.py
+++ b/src/buildstream/_gitsourcebase.py
@@ -30,7 +30,7 @@ from tempfile import TemporaryFile
from configparser import RawConfigParser
from .source import Source, SourceError, SourceFetcher
-from .types import Consistency, CoreWarnings
+from .types import CoreWarnings
from . import utils
from .types import FastEnum
from .utils import move_atomic, DirectoryExistsError
@@ -517,13 +517,6 @@ class _GitSourceBase(Source):
return key
- def get_consistency(self):
- if self._have_all_refs():
- return Consistency.CACHED
- elif self.mirror.ref is not None:
- return Consistency.RESOLVED
- return Consistency.INCONSISTENT
-
def is_resolved(self):
return self.mirror.ref is not None
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index b0a4da928..cdbf4b3dd 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -2361,9 +2361,6 @@ class Element(Plugin):
if not source.is_resolved():
self.__consistency = Consistency.INCONSISTENT
else:
- # FIXME: It'd be nice to remove this eventually
- source._update_state()
-
if source._is_cached():
self.__consistency = min(self.__consistency, Consistency.CACHED)
else:
diff --git a/src/buildstream/plugin.py b/src/buildstream/plugin.py
index 0cbd72e27..9794b9bba 100644
--- a/src/buildstream/plugin.py
+++ b/src/buildstream/plugin.py
@@ -353,8 +353,8 @@ class Plugin:
which could possibly affect the output and return a dictionary of these settings.
For Sources, this is guaranteed to only be called if
- :func:`Source.get_consistency() <buildstream.source.Source.get_consistency>`
- has not returned :func:`Consistency.INCONSISTENT <buildstream.source.Consistency.INCONSISTENT>`
+ :func:`Source.is_resolved() <buildstream.source.Source.is_resolved>`
+ has returned `True`
which is to say that the Source is expected to have an exact *ref* indicating
exactly what source is going to be staged.
"""
diff --git a/src/buildstream/plugins/sources/_downloadablefilesource.py b/src/buildstream/plugins/sources/_downloadablefilesource.py
index 581d32e7d..50f8561fb 100644
--- a/src/buildstream/plugins/sources/_downloadablefilesource.py
+++ b/src/buildstream/plugins/sources/_downloadablefilesource.py
@@ -7,7 +7,7 @@ import contextlib
import shutil
import netrc
-from buildstream import Source, SourceError, Consistency
+from buildstream import Source, SourceError
from buildstream import utils
@@ -91,16 +91,6 @@ class DownloadableFileSource(Source):
def is_cached(self) -> bool:
return os.path.isfile(self._get_mirror_file())
- def get_consistency(self):
- if self.ref is None:
- return Consistency.INCONSISTENT
-
- if os.path.isfile(self._get_mirror_file()):
- return Consistency.CACHED
-
- else:
- return Consistency.RESOLVED
-
def load_ref(self, node):
self.ref = node.get_str("ref", None)
self._warn_deprecated_etag(node)
@@ -133,7 +123,7 @@ class DownloadableFileSource(Source):
# Just a defensive check, it is impossible for the
# file to be already cached because Source.fetch() will
- # not be called if the source is already Consistency.CACHED.
+ # not be called if the source is already cached.
#
if os.path.isfile(self._get_mirror_file()):
return # pragma: nocover
@@ -181,7 +171,7 @@ class DownloadableFileSource(Source):
etag = self._get_etag(self.ref)
# Do not re-download the file if the ETag matches.
- if etag and self.get_consistency() == Consistency.CACHED:
+ if etag and self.is_cached():
request.add_header("If-None-Match", etag)
opener = self.__get_urlopener()
diff --git a/src/buildstream/plugins/sources/bzr.py b/src/buildstream/plugins/sources/bzr.py
index f9d95fca2..8a02eff95 100644
--- a/src/buildstream/plugins/sources/bzr.py
+++ b/src/buildstream/plugins/sources/bzr.py
@@ -59,7 +59,7 @@ import shutil
import fcntl
from contextlib import contextmanager
-from buildstream import Source, SourceError, Consistency
+from buildstream import Source, SourceError
from buildstream import utils
@@ -85,17 +85,6 @@ class BzrSource(Source):
with self._locked():
return self._check_ref()
- def get_consistency(self):
- if self.ref is None or self.tracking is None:
- return Consistency.INCONSISTENT
-
- # Lock for the _check_ref()
- with self._locked():
- if self._check_ref():
- return Consistency.CACHED
- else:
- return Consistency.RESOLVED
-
def load_ref(self, node):
self.ref = node.get_str("ref", None)
diff --git a/src/buildstream/plugins/sources/local.py b/src/buildstream/plugins/sources/local.py
index 206dcb8c1..57bcf14df 100644
--- a/src/buildstream/plugins/sources/local.py
+++ b/src/buildstream/plugins/sources/local.py
@@ -38,7 +38,7 @@ details on common configuration options for sources.
import os
from buildstream.storage.directory import Directory
-from buildstream import Source, SourceError, Consistency
+from buildstream import Source, SourceError
class LocalSource(Source):
@@ -61,9 +61,6 @@ class LocalSource(Source):
def preflight(self):
pass
- def get_consistency(self):
- return Consistency.CACHED
-
def is_resolved(self):
return True
diff --git a/src/buildstream/plugins/sources/patch.py b/src/buildstream/plugins/sources/patch.py
index cf6ce99cc..f33dfedec 100644
--- a/src/buildstream/plugins/sources/patch.py
+++ b/src/buildstream/plugins/sources/patch.py
@@ -45,7 +45,7 @@ details on common configuration options for sources.
"""
import os
-from buildstream import Source, SourceError, Consistency
+from buildstream import Source, SourceError
from buildstream import utils
@@ -73,9 +73,6 @@ class PatchSource(Source):
def is_cached(self):
return True
- def get_consistency(self):
- return Consistency.CACHED
-
def load_ref(self, node):
pass
diff --git a/src/buildstream/plugins/sources/pip.py b/src/buildstream/plugins/sources/pip.py
index d45ef70c7..eac2f3d01 100644
--- a/src/buildstream/plugins/sources/pip.py
+++ b/src/buildstream/plugins/sources/pip.py
@@ -72,7 +72,7 @@ import hashlib
import os
import re
-from buildstream import Consistency, Source, SourceError, utils
+from buildstream import Source, SourceError, utils
_OUTPUT_DIRNAME = ".bst_pip_downloads"
_PYPI_INDEX_URL = "https://pypi.org/simple/"
@@ -139,13 +139,6 @@ class PipSource(Source):
def is_cached(self):
return os.path.exists(self._mirror) and os.listdir(self._mirror)
- def get_consistency(self):
- if not self.ref:
- return Consistency.INCONSISTENT
- if os.path.exists(self._mirror) and os.listdir(self._mirror):
- return Consistency.CACHED
- return Consistency.RESOLVED
-
def get_ref(self):
return self.ref
diff --git a/src/buildstream/plugins/sources/workspace.py b/src/buildstream/plugins/sources/workspace.py
index 5cea85dc2..ce62f3aff 100644
--- a/src/buildstream/plugins/sources/workspace.py
+++ b/src/buildstream/plugins/sources/workspace.py
@@ -38,7 +38,7 @@ workspace. The node constructed would be specified as follows:
import os
from buildstream.storage.directory import Directory
-from buildstream import Source, SourceError, Consistency
+from buildstream import Source, SourceError
from buildstream.types import SourceRef
from buildstream.node import MappingNode
@@ -90,14 +90,6 @@ class WorkspaceSource(Source):
def init_workspace(self, directory: Directory) -> None:
raise AssertionError("Attempting to re-open an existing workspace")
- def get_consistency(self) -> Consistency:
- if not os.path.exists(self._get_local_path()):
- # A workspace is considered inconsistent in the case that
- # its directory went missing
- return Consistency.INCONSISTENT
- else:
- return Consistency.CACHED
-
def fetch(self) -> None: # pylint: disable=arguments-differ
pass # pragma: nocover
diff --git a/src/buildstream/source.py b/src/buildstream/source.py
index fa439ee06..4839cf0fe 100644
--- a/src/buildstream/source.py
+++ b/src/buildstream/source.py
@@ -59,10 +59,6 @@ For loading and configuration purposes, Sources must implement the
Sources expose the following abstract methods. Unless explicitly mentioned,
these methods are mandatory to implement.
-* :func:`Source.get_consistency() <buildstream.source.Source.get_consistency>`
-
- Report the sources consistency state.
-
* :func:`Source.load_ref() <buildstream.source.Source.load_ref>`
Load the ref from a specific YAML node
@@ -169,7 +165,7 @@ from typing import Iterable, Iterator, Optional, Tuple, TYPE_CHECKING
from . import _yaml, utils
from .node import MappingNode
from .plugin import Plugin
-from .types import Consistency, SourceRef, Union, List
+from .types import SourceRef, Union, List
from ._exceptions import BstError, ImplError, PluginError, ErrorDomain
from ._loader.metasource import MetaSource
from ._projectrefs import ProjectRefStorage
@@ -356,7 +352,6 @@ class Source(Plugin):
self.__element_index = meta.element_index # The index of the source in the owning element's source list
self.__element_kind = meta.element_kind # The kind of the element owning this source
self.__directory = meta.directory # Staging relative directory
- self.__consistency = Consistency.INCONSISTENT # Cached consistency state
self.__meta_kind = meta.kind # The kind of this source, required for unpickling
self.__key = None # Cache key for source
@@ -391,13 +386,6 @@ class Source(Plugin):
#############################################################
# Abstract Methods #
#############################################################
- def get_consistency(self) -> int:
- """Report whether the source has a resolved reference
-
- Returns:
- (:class:`.Consistency`): The source consistency
- """
- raise ImplError("Source plugin '{}' does not implement get_consistency()".format(self.get_kind()))
def load_ref(self, node: MappingNode) -> None:
"""Loads the *ref* for this Source from the specified *node*.
@@ -562,9 +550,8 @@ class Source(Plugin):
"""Implement any validations once we know the sources are cached
This is guaranteed to be called only once for a given session
- once the sources are known to be
- :attr:`Consistency.CACHED <buildstream.types.Consistency.CACHED>`,
- if source tracking is enabled in the session for this source,
+ once the sources are known to be cached.
+ If source tracking is enabled in the session for this source,
then this will only be called if the sources become cached after
tracking completes.
@@ -783,37 +770,6 @@ class Source(Plugin):
# Prepend provenance to the error
raise SourceError("{}: {}".format(self, e), reason=e.reason) from e
- # Update cached consistency for a source
- #
- # This must be called whenever the state of a source may have changed.
- #
- def _update_state(self):
-
- if self.__consistency < Consistency.CACHED:
-
- # Source consistency interrogations are silent.
- context = self._get_context()
- with context.messenger.silence():
- try:
- self.__consistency = self.get_consistency() # pylint: disable=assignment-from-no-return
- except SourceError:
- # SourceErrors should be preserved so that the
- # plugin can communicate real error cases.
- raise
- except Exception as err: # pylint: disable=broad-except
- # Generic errors point to bugs in the plugin, so
- # we need to catch them and make sure they do not
- # cause stacktraces
- raise PluginError(
- "Source plugin '{}' failed to compute source consistency: {}".format(self.get_kind(), err),
- reason="source-bug",
- )
-
- # Give the Source an opportunity to validate the cached
- # sources as soon as the Source becomes Consistency.CACHED.
- if self.__consistency == Consistency.CACHED:
- self.validate_cache()
-
# Get whether the source is cached by the source plugin
#
def _is_cached(self):
@@ -1312,7 +1268,6 @@ class Source(Plugin):
#
clone._preflight()
clone._load_ref()
- clone._update_state()
return clone
diff --git a/tests/format/project/plugin-no-load-ref/plugins/noloadref.py b/tests/format/project/plugin-no-load-ref/plugins/noloadref.py
index 5d44cd5c7..e2fe0ac46 100644
--- a/tests/format/project/plugin-no-load-ref/plugins/noloadref.py
+++ b/tests/format/project/plugin-no-load-ref/plugins/noloadref.py
@@ -1,4 +1,4 @@
-from buildstream import Source, Consistency
+from buildstream import Source
# Just a dummy plugin which does not support the new load_ref() method.
@@ -15,9 +15,6 @@ class NoLoadRefSource(Source):
def get_unique_key(self):
return {}
- def get_consistency(self):
- return Consistency.CACHED
-
def get_ref(self):
return None
diff --git a/tests/format/project/plugin-preflight-error/errorplugin/preflighterror.py b/tests/format/project/plugin-preflight-error/errorplugin/preflighterror.py
index 3fa8afb93..db2895f8b 100644
--- a/tests/format/project/plugin-preflight-error/errorplugin/preflighterror.py
+++ b/tests/format/project/plugin-preflight-error/errorplugin/preflighterror.py
@@ -1,4 +1,4 @@
-from buildstream import Source, SourceError, Consistency
+from buildstream import Source, SourceError
class PreflightErrorSource(Source):
@@ -13,9 +13,6 @@ class PreflightErrorSource(Source):
def get_unique_key(self):
return {}
- def get_consistency(self):
- return Consistency.CACHED
-
def get_ref(self):
return None
diff --git a/tests/frontend/consistencyerror/plugins/consistencybug.py b/tests/frontend/consistencyerror/plugins/consistencybug.py
index 7f0bd9211..abcbbc997 100644
--- a/tests/frontend/consistencyerror/plugins/consistencybug.py
+++ b/tests/frontend/consistencyerror/plugins/consistencybug.py
@@ -15,9 +15,6 @@ class ConsistencyBugSource(Source):
return True
def is_cached(self):
- return True
-
- def get_consistency(self):
# Raise an unhandled exception (not a BstError)
raise Exception("Something went terribly wrong")
diff --git a/tests/frontend/consistencyerror/plugins/consistencyerror.py b/tests/frontend/consistencyerror/plugins/consistencyerror.py
index 523ac0b6f..2e30d4842 100644
--- a/tests/frontend/consistencyerror/plugins/consistencyerror.py
+++ b/tests/frontend/consistencyerror/plugins/consistencyerror.py
@@ -15,9 +15,6 @@ class ConsistencyErrorSource(Source):
return True
def is_cached(self):
- return True
-
- def get_consistency(self):
# Raise an error unconditionally
raise SourceError("Something went terribly wrong", reason="the-consistency-error")
diff --git a/tests/frontend/project/sources/fetch_source.py b/tests/frontend/project/sources/fetch_source.py
index 60b4ba95d..c62d1d29a 100644
--- a/tests/frontend/project/sources/fetch_source.py
+++ b/tests/frontend/project/sources/fetch_source.py
@@ -1,6 +1,6 @@
import os
-from buildstream import Source, Consistency, SourceError, SourceFetcher
+from buildstream import Source, SourceError, SourceFetcher
# Expected config
# sources:
@@ -70,19 +70,16 @@ class FetchSource(Source):
return True
def is_cached(self) -> bool:
- return self.get_consistency() == Consistency.CACHED
-
- def get_consistency(self):
if not os.path.exists(self.output_file):
- return Consistency.RESOLVED
+ return False
with open(self.output_file, "r") as f:
contents = f.read()
for url in self.original_urls:
if url not in contents:
- return Consistency.RESOLVED
+ return False
- return Consistency.CACHED
+ return True
# We dont have a ref, we're a local file...
def load_ref(self, node):
diff --git a/tests/internals/pluginloading/badversionsource/customsources/foo.py b/tests/internals/pluginloading/badversionsource/customsources/foo.py
index f50855fd1..628f99b29 100644
--- a/tests/internals/pluginloading/badversionsource/customsources/foo.py
+++ b/tests/internals/pluginloading/badversionsource/customsources/foo.py
@@ -1,4 +1,4 @@
-from buildstream import Source, Consistency
+from buildstream import Source
class BarSource(Source):
@@ -11,9 +11,6 @@ class BarSource(Source):
def configure(self, node):
pass
- def get_consistency(self):
- return Consistency.INCONSISTENT
-
def setup():
return BarSource
diff --git a/tests/internals/pluginloading/customsource/pluginsources/foo.py b/tests/internals/pluginloading/customsource/pluginsources/foo.py
index 706c96f3b..fce5239b1 100644
--- a/tests/internals/pluginloading/customsource/pluginsources/foo.py
+++ b/tests/internals/pluginloading/customsource/pluginsources/foo.py
@@ -1,4 +1,4 @@
-from buildstream import Source, Consistency
+from buildstream import Source
class FooSource(Source):
@@ -11,9 +11,6 @@ class FooSource(Source):
def get_unique_key(self):
pass
- def get_consistency(self):
- return Consistency.INCONSISTENT
-
def setup():
return FooSource
diff --git a/tests/sources/git.py b/tests/sources/git.py
index 096338bbe..d6f9cb223 100644
--- a/tests/sources/git.py
+++ b/tests/sources/git.py
@@ -541,7 +541,7 @@ def test_track_unlisted_submodule(cli, tmpdir, datafiles, fail):
assert "git:unlisted-submodule" not in result.stderr
# We won't get a warning/error when tracking either, the source
- # has not become Consistency.CACHED so the opportunity to check
+ # has not become cached so the opportunity to check
# for the warning has not yet arisen.
result = cli.run(project=project, args=["source", "track", "target.bst"])
result.assert_success()
diff --git a/tests/sources/no-fetch-cached/plugins/sources/always_cached.py b/tests/sources/no-fetch-cached/plugins/sources/always_cached.py
index 6267a99eb..aef13279b 100644
--- a/tests/sources/no-fetch-cached/plugins/sources/always_cached.py
+++ b/tests/sources/no-fetch-cached/plugins/sources/always_cached.py
@@ -7,7 +7,7 @@ Used to test that BuildStream core does not call fetch() for cached sources.
"""
-from buildstream import Consistency, Source
+from buildstream import Source
class AlwaysCachedSource(Source):
@@ -26,9 +26,6 @@ class AlwaysCachedSource(Source):
def is_cached(self):
return True
- def get_consistency(self):
- return Consistency.CACHED
-
def load_ref(self, node):
pass
diff --git a/tests/sources/previous_source_access/plugins/sources/foo_transform.py b/tests/sources/previous_source_access/plugins/sources/foo_transform.py
index c59c81e63..dbc44c8aa 100644
--- a/tests/sources/previous_source_access/plugins/sources/foo_transform.py
+++ b/tests/sources/previous_source_access/plugins/sources/foo_transform.py
@@ -10,7 +10,7 @@ previous sources, and copies its contents to a file called "filetransform".
import os
import hashlib
-from buildstream import Consistency, Source, SourceError, utils
+from buildstream import Source, SourceError, utils
class FooTransformSource(Source):
@@ -40,21 +40,17 @@ class FooTransformSource(Source):
return (self.ref,)
def is_cached(self):
- return self.get_consistency() == Consistency.CACHED
-
- def get_consistency(self):
- if self.ref is None:
- return Consistency.INCONSISTENT
# If we have a file called "filetransform", verify that its checksum
- # matches our ref. Otherwise, it resolved but not cached.
+ # matches our ref. Otherwise, it is not cached.
fpath = os.path.join(self.mirror, "filetransform")
try:
with open(fpath, "rb") as f:
if hashlib.sha256(f.read()).hexdigest() == self.ref.strip():
- return Consistency.CACHED
- except Exception:
+ return True
+ except FileNotFoundError:
pass
- return Consistency.RESOLVED
+
+ return False
def get_ref(self):
return self.ref
diff --git a/tests/sources/project_key_test/plugins/sources/key-test.py b/tests/sources/project_key_test/plugins/sources/key-test.py
index 98dd380ef..88a211738 100644
--- a/tests/sources/project_key_test/plugins/sources/key-test.py
+++ b/tests/sources/project_key_test/plugins/sources/key-test.py
@@ -1,6 +1,6 @@
import os
-from buildstream import Source, Consistency
+from buildstream import Source
class KeyTest(Source):
@@ -23,12 +23,6 @@ class KeyTest(Source):
def is_cached(self):
return False
- def get_consistency(self):
- if self.ref:
- return Consistency.RESOLVED
- else:
- return Consistency.INCONSISTENT
-
def load_ref(self, node):
pass