diff options
author | Darius Makovsky <traveltissues@protonmail.com> | 2019-09-05 14:55:29 +0100 |
---|---|---|
committer | Darius Makovsky <traveltissues@protonmail.com> | 2019-09-05 17:52:52 +0100 |
commit | 2138c4715c97cc8df223c0929e775f8affdabf3e (patch) | |
tree | a3e3ef80607d9a1cb49c3902114f8f97ed616ffa | |
parent | 8c7ec2a7685868cf2fbc348f84214a1176e85083 (diff) | |
download | buildstream-2138c4715c97cc8df223c0929e775f8affdabf3e.tar.gz |
workspace.py: clean up and annotate types
-rw-r--r-- | src/buildstream/plugins/sources/workspace.py | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/src/buildstream/plugins/sources/workspace.py b/src/buildstream/plugins/sources/workspace.py index 1d5a8b949..1a99e8a2e 100644 --- a/src/buildstream/plugins/sources/workspace.py +++ b/src/buildstream/plugins/sources/workspace.py @@ -41,6 +41,7 @@ from buildstream.storage.directory import Directory from buildstream.storage._casbaseddirectory import CasBasedDirectory from buildstream import Source, SourceError, Consistency from buildstream import utils +from buildstream.types import SourceRef class WorkspaceSource(Source): @@ -51,15 +52,17 @@ class WorkspaceSource(Source): def __init__(self, context, project, meta): super().__init__(context, project, meta) - # Cached unique key to avoid multiple file system traversal if the unique key is requested multiple times. + # Cached unique key self.__unique_key = None + # the element source objects from the specified metasources self.__element_sources = [] + # the digest of the Directory following the import of the workspace self.__source_digest = None - def set_element_sources(self, _element_sources): + def set_element_sources(self, _element_sources: [Source]): self.__element_sources = _element_sources - def get_element_sources(self): + def get_element_sources(self) -> [Source]: return self.__element_sources def configure(self, node): @@ -72,7 +75,7 @@ class WorkspaceSource(Source): for source in self.get_element_sources(): source.preflight() - def get_ref(self): + def get_ref(self) -> str: return str(self.__source_digest) def load_ref(self, node): @@ -81,10 +84,10 @@ class WorkspaceSource(Source): def set_ref(self, ref, node): node['ref'] = self.__source_digest = ref - def get_unique_key(self): + def get_unique_key(self) -> (str, SourceRef): return (self.fullpath, self.__source_digest) - def init_workspace(self, directory): + def init_workspace(self, directory: Directory): # for each source held by the workspace we must call init_workspace # those sources may override `init_workspace` expecting str or Directory # and this will need to be extracted from the directory passed to this method @@ -98,15 +101,12 @@ class WorkspaceSource(Source): return Consistency.INCONSISTENT return Consistency.RESOLVED - def load_ref(self, node): - return None - def fetch(self): context = self._get_context() directory = CasBasedDirectory(context.get_cascache()) self.stage(directory) - def stage(self, directory): + def stage(self, directory: Directory): # directory should always be a Directory object assert isinstance(directory, Directory) with self.timed_activity("Staging local files into CAS"): @@ -121,21 +121,6 @@ class WorkspaceSource(Source): def _get_local_path(self): return self.fullpath - -# Create a unique key for a file -def unique_key(filename): - - # Return some hard coded things for files which - # have no content to calculate a key for - if os.path.islink(filename): - # For a symbolic link, use the link target as its unique identifier - return os.readlink(filename) - elif os.path.isdir(filename): - return "0" - - return utils.sha256sum(filename) - - # Plugin entry point def setup(): return WorkspaceSource |