diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-08 20:40:08 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-11-08 21:27:21 +0900 |
commit | 213d9072b684d2dff78d8b4f1c7cfa9d6335b0d0 (patch) | |
tree | 8dc7a203d486e45430cadaf5a4e33e720d1ef015 | |
parent | 34ba445fd1963acada0733c196483c98a57fd753 (diff) | |
download | buildstream-213d9072b684d2dff78d8b4f1c7cfa9d6335b0d0.tar.gz |
Refactor: Move context.py -> _context.py
Consequently:
o Changed Plugin.get_context() to a private Plugin._get_context() accessor.
o Updated anything which imports Context to do so from private _context module
o Updated docs to exclude the now private Context
-rw-r--r-- | buildstream/__init__.py | 5 | ||||
-rw-r--r-- | buildstream/_context.py (renamed from buildstream/context.py) | 98 | ||||
-rw-r--r-- | buildstream/_frontend/main.py | 3 | ||||
-rw-r--r-- | buildstream/_pipeline.py | 2 | ||||
-rw-r--r-- | buildstream/_scheduler/trackqueue.py | 2 | ||||
-rw-r--r-- | buildstream/element.py | 12 | ||||
-rw-r--r-- | buildstream/plugin.py | 15 | ||||
-rw-r--r-- | buildstream/sandbox/_sandboxchroot.py | 2 | ||||
-rw-r--r-- | buildstream/source.py | 2 | ||||
-rw-r--r-- | doc/source/pluginauthoring.rst | 1 | ||||
-rw-r--r-- | tests/context/context.py | 2 | ||||
-rw-r--r-- | tests/pipeline/load.py | 3 | ||||
-rw-r--r-- | tests/plugins/pipeline.py | 3 | ||||
-rw-r--r-- | tests/project/plugins.py | 3 | ||||
-rw-r--r-- | tests/project/project.py | 2 | ||||
-rw-r--r-- | tests/variables/variables.py | 3 |
16 files changed, 74 insertions, 84 deletions
diff --git a/buildstream/__init__.py b/buildstream/__init__.py index b3751a6e3..cde1b43e5 100644 --- a/buildstream/__init__.py +++ b/buildstream/__init__.py @@ -18,11 +18,8 @@ # Authors: # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> -# Core components -from .context import Context -from .sandbox import Sandbox, SandboxFlags - # Plugin auther facing APIs +from .sandbox import Sandbox, SandboxFlags from .plugin import Plugin from .source import Source, SourceError, Consistency from .element import Element, ElementError, Scope diff --git a/buildstream/context.py b/buildstream/_context.py index 81929591a..f85771bac 100644 --- a/buildstream/context.py +++ b/buildstream/_context.py @@ -18,20 +18,6 @@ # Authors: # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> -""" -Context -======= - -The :class:`.Context` object holds all of the user preferences -and context for a given invocation of BuildStream. - -This is a collection of data from configuration files and command -line arguments and consists of information such as where to store -logs and artifacts, where to perform builds and cache downloaded sources, -verbosity levels and basically anything pertaining to the context -in which BuildStream was invoked. -""" - import os import hashlib import pickle @@ -43,72 +29,80 @@ from ._exceptions import LoadError, LoadErrorReason from ._profile import Topics, profile_start, profile_end +# Context() +# +# The Context object holds all of the user preferences +# and context for a given invocation of BuildStream. +# +# This is a collection of data from configuration files and command +# line arguments and consists of information such as where to store +# logs and artifacts, where to perform builds and cache downloaded sources, +# verbosity levels and basically anything pertaining to the context +# in which BuildStream was invoked. +# class Context(): - """Context() - Context of how BuildStream was invoked - """ def __init__(self, cli_options): + # Filename indicating which configuration file was used, or None for the defaults self.config_origin = None - """Filename indicating which configuration file was used, or None for the defaults""" + # Whether elements must be rebuilt when their dependencies have changed self.strict_build_plan = None - """Whether elements must be rebuilt when their dependencies have changed""" + # The directory where various sources are stored self.sourcedir = None - """The directory where various sources are stored""" + # The directory where build sandboxes will be created self.builddir = None - """The directory where build sandboxes will be created""" + # The local binary artifact cache directory self.artifactdir = None - """The local binary artifact cache directory""" + # The URL from which to download prebuilt artifacts self.artifact_pull = None - """The URL from which to download prebuilt artifacts""" + # The URL to upload built artifacts to self.artifact_push = None - """The URL to upload built artifacts to""" + # The port number for pushing artifacts over ssh self.artifact_push_port = 22 - """The port number for pushing artifacts over ssh""" + # The directory to store build logs self.logdir = None - """The directory to store build logs""" + # The abbreviated cache key length to display in the UI self.log_key_length = 0 - """The abbreviated cache key length to display in the UI""" + # Whether debug mode is enabled self.log_debug = False - """Whether debug mode is enabled""" + # Whether verbose mode is enabled self.log_verbose = False - """Whether verbose mode is enabled""" + # Maximum number of lines to print from build logs self.log_error_lines = 0 - """Maximum number of lines to print from build logs""" + # Maximum number of lines to print in the master log for a detailed message self.log_message_lines = 0 - """Maximum number of lines to print in the master log for a detailed message""" + # Format string for printing the pipeline at startup time self.log_element_format = None - """Format string for printing the pipeline at startup time""" + # Maximum number of fetch or refresh tasks self.sched_fetchers = 4 - """Maximum number of fetch or refresh tasks""" + # Maximum number of build tasks self.sched_builders = 4 - """Maximum number of build tasks""" + # Maximum number of push tasks self.sched_pushers = 4 - """Maximum number of push tasks""" + # Maximum number of retries for network tasks self.sched_network_retries = 2 - """Maximum number of retries for network tasks""" + # What to do when a build fails in non interactive mode self.sched_error_action = 'continue' - """What to do when a build fails in non interactive mode""" # Make sure the XDG vars are set in the environment before loading anything self._init_xdg() @@ -121,19 +115,21 @@ class Context(): self._project_overrides = {} self._cli_options = cli_options + # load() + # + # Loads the configuration files + # + # Args: + # config (filename): The user specified configuration file, if any + # + # Raises: + # LoadError + # + # This will first load the BuildStream default configuration and then + # override that configuration with the configuration file indicated + # by *config*, if any was specified. + # def load(self, config=None): - """Loads the configuration files - - Args: - config (filename): The user specified configuration file, if any - - Raises: - :class:`.LoadError` - - This will first load the BuildStream default configuration and then - override that configuration with the configuration file indicated - by *config*, if any was specified. - """ profile_start(Topics.LOAD_CONTEXT, 'load') # If a specific config file is not specified, default to trying @@ -218,10 +214,6 @@ class Context(): "{}: on-error should be one of: {}".format( provenance, ", ".join(valid_actions))) - ############################################################# - # Private Methods used in BuildStream # - ############################################################# - # _get_overrides(): # # Fetch the override dictionary for the active project. This returns diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py index c2002654c..4e00a2be1 100644 --- a/buildstream/_frontend/main.py +++ b/buildstream/_frontend/main.py @@ -25,9 +25,10 @@ from contextlib import contextmanager from blessings import Terminal # Import buildstream public symbols -from .. import Context, Scope, Consistency +from .. import Scope, Consistency # Import various buildstream internals +from .._context import Context from .._project import Project from .._exceptions import BstError, LoadError from .._message import MessageType, unconditional_messages diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index 90ed899ea..febadbcc7 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -829,7 +829,7 @@ class Pipeline(): # bound. # Create a temporary directory to build the source tree in - builddir = target.get_context().builddir + builddir = target._get_context().builddir prefix = "{}-".format(target.normal_name) with TemporaryDirectory(prefix=prefix, dir=builddir) as tempdir: diff --git a/buildstream/_scheduler/trackqueue.py b/buildstream/_scheduler/trackqueue.py index 3159a3adc..df73a7280 100644 --- a/buildstream/_scheduler/trackqueue.py +++ b/buildstream/_scheduler/trackqueue.py @@ -80,7 +80,7 @@ class TrackQueue(Queue): # tracking, this is avoid a following fetch queue operating on the sources # if the tracked ref is cached as a result. # - context = element.get_context() + context = element._get_context() context._push_message_depth(True) element._consistency(recalculate=True) context._pop_message_depth() diff --git a/buildstream/element.py b/buildstream/element.py index 86dd2b8dc..22a2ebdbb 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -855,7 +855,7 @@ class Element(Plugin): if key not in self.__env_nocache } - context = self.get_context() + context = self._get_context() project = self._get_project() return utils._generate_key({ 'artifact-version': "{}.{}".format(BST_CORE_ARTIFACT_VERSION, @@ -969,7 +969,7 @@ class Element(Plugin): # Question marks are returned if information for the cache key is missing. # def _get_full_display_key(self): - context = self.get_context() + context = self._get_context() cache_key = None dim_key = True @@ -1038,7 +1038,7 @@ class Element(Plugin): # Assert call ordering assert(not self._cached()) - context = self.get_context() + context = self._get_context() with self._output_file() as output_file: # Explicitly clean it up, keep the build dir around if exceptions are raised @@ -1203,7 +1203,7 @@ class Element(Plugin): # def _logfile(self, action_name, pid=None): project = self._get_project() - context = self.get_context() + context = self._get_context() key = self._get_display_key() if pid is None: pid = os.getpid() @@ -1412,7 +1412,7 @@ class Element(Plugin): # def _get_strict(self): project = self._get_project() - context = self.get_context() + context = self._get_context() return context._get_strict(project.name) ############################################################# @@ -1420,7 +1420,7 @@ class Element(Plugin): ############################################################# @contextmanager def __sandbox(self, directory, stdout=None, stderr=None): - context = self.get_context() + context = self._get_context() project = self._get_project() platform = Platform.get_platform() diff --git a/buildstream/plugin.py b/buildstream/plugin.py index 56bee90c1..5a7d70961 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -176,14 +176,6 @@ class Plugin(): """ return self.__kind - def get_context(self): - """Fetches the context - - Returns: - (object): The :class:`.Context` - """ - return self.__context - def node_items(self, node): """Iterate over a dictionary loaded from YAML @@ -562,6 +554,13 @@ class Plugin(): # Private Methods used in BuildStream # ############################################################# + # _get_context() + # + # Fetches the invocation context + # + def _get_context(self): + return self.__context + # _get_project() # # Fetches the project object associated with this plugin diff --git a/buildstream/sandbox/_sandboxchroot.py b/buildstream/sandbox/_sandboxchroot.py index 20ead6d84..d8da7e3b5 100644 --- a/buildstream/sandbox/_sandboxchroot.py +++ b/buildstream/sandbox/_sandboxchroot.py @@ -38,8 +38,6 @@ from . import Sandbox, SandboxFlags class SandboxChroot(Sandbox): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - - self.platform = self._get_context()._platform self.mount_map = None def run(self, command, flags, cwd=None, env=None): diff --git a/buildstream/source.py b/buildstream/source.py index ed9ff3aaa..ed3fe92b3 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -99,7 +99,7 @@ class Source(Plugin): """ # Create the directory if it doesnt exist - context = self.get_context() + context = self._get_context() directory = os.path.join(context.sourcedir, self.get_kind()) os.makedirs(directory, exist_ok=True) return directory diff --git a/doc/source/pluginauthoring.rst b/doc/source/pluginauthoring.rst index 4773c3ea8..ce22d3f32 100644 --- a/doc/source/pluginauthoring.rst +++ b/doc/source/pluginauthoring.rst @@ -20,6 +20,5 @@ implement custom :mod:`Element <buildstream.element>` or * :mod:`Element <buildstream.element>` - Base Element Class * :mod:`BuildElement <buildstream.buildelement>` - Build Element Class * :mod:`ScriptElement <buildstream.scriptelement>` - Script Element Class -* :mod:`Context <buildstream.context>` - Invocation Context * :mod:`Sandbox <buildstream.sandbox.sandbox>` - Build Sandbox * :mod:`Utilities <buildstream.utils>` - Utilities for Plugins diff --git a/tests/context/context.py b/tests/context/context.py index be0dd8a55..0db589a1a 100644 --- a/tests/context/context.py +++ b/tests/context/context.py @@ -1,7 +1,7 @@ import os import pytest -from buildstream import Context +from buildstream._context import Context from buildstream._exceptions import LoadError, LoadErrorReason from tests.testutils.site import HAVE_ROOT diff --git a/tests/pipeline/load.py b/tests/pipeline/load.py index a0b6d7ae3..7adcd0f1e 100644 --- a/tests/pipeline/load.py +++ b/tests/pipeline/load.py @@ -1,7 +1,8 @@ import os import pytest -from buildstream import Context, Scope +from buildstream import Scope +from buildstream._context import Context from buildstream._project import Project from buildstream._pipeline import Pipeline from buildstream._platform import Platform diff --git a/tests/plugins/pipeline.py b/tests/plugins/pipeline.py index 6fac82b89..5f1a85e24 100644 --- a/tests/plugins/pipeline.py +++ b/tests/plugins/pipeline.py @@ -1,7 +1,8 @@ import os import pytest -from buildstream import Context, Scope +from buildstream import Scope +from buildstream._context import Context from buildstream._project import Project from buildstream._exceptions import PluginError from buildstream._pipeline import Pipeline diff --git a/tests/project/plugins.py b/tests/project/plugins.py index 424548082..5f7517278 100644 --- a/tests/project/plugins.py +++ b/tests/project/plugins.py @@ -1,7 +1,8 @@ import os import pytest -from buildstream import Context, Scope +from buildstream import Scope +from buildstream._context import Context from buildstream._project import Project from buildstream._pipeline import Pipeline from buildstream._platform import Platform diff --git a/tests/project/project.py b/tests/project/project.py index 32a264c6d..3a1484309 100644 --- a/tests/project/project.py +++ b/tests/project/project.py @@ -1,7 +1,7 @@ import os import pytest -from buildstream import Context +from buildstream._context import Context from buildstream._project import Project from buildstream._exceptions import LoadError, LoadErrorReason diff --git a/tests/variables/variables.py b/tests/variables/variables.py index 51af7e27b..7562857f9 100644 --- a/tests/variables/variables.py +++ b/tests/variables/variables.py @@ -1,7 +1,8 @@ import os import pytest -from buildstream import Context, BuildElement +from buildstream import BuildElement +from buildstream._context import Context from buildstream._project import Project from buildstream._pipeline import Pipeline from buildstream._platform import Platform |