diff options
author | Benjamin Schubert <bschubert15@bloomberg.net> | 2019-11-28 17:50:51 +0000 |
---|---|---|
committer | Benjamin Schubert <bschubert15@bloomberg.net> | 2020-01-16 16:33:19 +0000 |
commit | 5cb2442e789d6b302f7d261ba5d2a2ad5366d7c2 (patch) | |
tree | 172dcee0a766d70fb80c0b41d086c873a0268b44 /src/buildstream | |
parent | 3be6d07753599ef54b9e80ac066571632e217ce2 (diff) | |
download | buildstream-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.
Diffstat (limited to 'src/buildstream')
-rw-r--r-- | src/buildstream/__init__.py | 2 | ||||
-rw-r--r-- | src/buildstream/_gitsourcebase.py | 9 | ||||
-rw-r--r-- | src/buildstream/element.py | 3 | ||||
-rw-r--r-- | src/buildstream/plugin.py | 4 | ||||
-rw-r--r-- | src/buildstream/plugins/sources/_downloadablefilesource.py | 16 | ||||
-rw-r--r-- | src/buildstream/plugins/sources/bzr.py | 13 | ||||
-rw-r--r-- | src/buildstream/plugins/sources/local.py | 5 | ||||
-rw-r--r-- | src/buildstream/plugins/sources/patch.py | 5 | ||||
-rw-r--r-- | src/buildstream/plugins/sources/pip.py | 9 | ||||
-rw-r--r-- | src/buildstream/plugins/sources/workspace.py | 10 | ||||
-rw-r--r-- | src/buildstream/source.py | 51 |
11 files changed, 15 insertions, 112 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 |