Commit c81fb2da authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

Moving 'fetch_subprojects' configuration to stream <--> loader

This was previously decided in CLI, but knowledge of what to initialize
has been moved to Stream().

Now there is no more point to store this configuration in the Context,
we just have the Stream() decide it when asking the Pipeline() to
invoke the Loader().
parent 541cd760
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -45,10 +45,7 @@ from ._artifactcache import artifact_cache_specs_from_config_node
#
class Context():

    def __init__(self, *, fetch_subprojects=False):

        # Whether to automatically fetch subprojects in this session
        self.fetch_subprojects = fetch_subprojects
    def __init__(self):

        # Filename indicating which configuration file was used, or None for the defaults
        self.config_origin = None
+4 −12
Original line number Diff line number Diff line
@@ -134,12 +134,8 @@ class App():
    # partial initialization is useful for some contexts where we dont
    # want to load the pipeline, such as executing workspace commands.
    #
    # Args:
    #    fetch_subprojects (bool): Whether we should fetch subprojects as a part of the
    #                              loading process, if they are not yet locally cached
    #
    @contextmanager
    def partially_initialized(self, *, fetch_subprojects=False):
    def partially_initialized(self):
        directory = self._main_options['directory']
        config = self._main_options['config']

@@ -147,7 +143,7 @@ class App():
        # Load the Context
        #
        try:
            self.context = Context(fetch_subprojects=fetch_subprojects)
            self.context = Context()
            self.context.load(config)
        except BstError as e:
            self._error_exit(e, "Error loading user configuration")
@@ -241,8 +237,6 @@ class App():
    #
    # Args:
    #    session_name (str): The name of the session, or None for no session
    #    fetch_subprojects (bool): Whether we should fetch subprojects as a part of the
    #                              loading process, if they are not yet locally cached
    #
    # Note that the except_ argument may have a subtly different meaning depending
    # on the activity performed on the Pipeline. In normal circumstances the except_
@@ -253,14 +247,12 @@ class App():
    # the session header and summary, and time the main session from startup time.
    #
    @contextmanager
    def initialized(self, *,
                    session_name=None,
                    fetch_subprojects=False):
    def initialized(self, *, session_name=None):

        self._session_name = session_name

        # Start with the early stage init, this enables logging right away
        with self.partially_initialized(fetch_subprojects=fetch_subprojects):
        with self.partially_initialized():

            # Mark the beginning of the session
            if session_name:
+6 −6
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ def build(app, elements, all_, track_, track_save, track_all, track_except, trac
    if track_all:
        track_ = elements

    with app.initialized(session_name="Build", fetch_subprojects=True):
    with app.initialized(session_name="Build"):
        app.stream.build(elements,
                         track_targets=track_,
                         track_except=track_except,
@@ -279,7 +279,7 @@ def fetch(app, elements, deps, track_, except_, track_cross_junctions):
        click.echo("ERROR: The --track-cross-junctions option can only be used with --track", err=True)
        sys.exit(-1)

    with app.initialized(session_name="Fetch", fetch_subprojects=True):
    with app.initialized(session_name="Fetch"):
        app.stream.fetch(elements,
                         selection=deps,
                         except_targets=except_,
@@ -315,7 +315,7 @@ def track(app, elements, deps, except_, cross_junctions):
        none:  No dependencies, just the specified elements
        all:   All dependencies of all specified elements
    """
    with app.initialized(session_name="Track", fetch_subprojects=True):
    with app.initialized(session_name="Track"):
        app.stream.track(elements,
                         selection=deps,
                         except_targets=except_,
@@ -347,7 +347,7 @@ def pull(app, elements, deps, remote):
        none:  No dependencies, just the element itself
        all:   All dependencies
    """
    with app.initialized(session_name="Pull", fetch_subprojects=True):
    with app.initialized(session_name="Pull"):
        app.stream.pull(elements, selection=deps, remote=remote)


@@ -375,7 +375,7 @@ def push(app, elements, deps, remote):
        none:  No dependencies, just the element itself
        all:   All dependencies
    """
    with app.initialized(session_name="Push", fetch_subprojects=True):
    with app.initialized(session_name="Push"):
        app.stream.push(elements, selection=deps, remote=remote)


@@ -716,7 +716,7 @@ def source_bundle(app, element, force, directory,
                  track_, compression, except_):
    """Produce a source bundle to be manually executed
    """
    with app.initialized(fetch_subprojects=True):
    with app.initialized():
        app.stream.source_bundle(element, directory,
                                 track_first=track_,
                                 force=force,
+8 −3
Original line number Diff line number Diff line
@@ -51,10 +51,11 @@ from . import MetaSource
#    parent (Loader): A parent Loader object, in the case this is a junctioned Loader
#    tempdir (str): A directory to cleanup with the Loader, given to the loader by a parent
#                   loader in the case that this loader is a subproject loader.
#    fetch_subprojects (bool): Whether to fetch subprojects while loading
#
class Loader():

    def __init__(self, context, project, filenames, *, parent=None, tempdir=None):
    def __init__(self, context, project, filenames, *, parent=None, tempdir=None, fetch_subprojects=False):

        # Ensure we have an absolute path for the base directory
        basedir = project.element_path
@@ -78,6 +79,7 @@ class Loader():
        #
        # Private members
        #
        self._fetch_subprojects = fetch_subprojects
        self._context = context
        self._options = project.options      # Project options (OptionPool)
        self._basedir = basedir              # Base project directory
@@ -475,7 +477,7 @@ class Loader():
            # Handle the case where a subproject needs to be fetched
            #
            if source.get_consistency() == Consistency.RESOLVED:
                if self._context.fetch_subprojects:
                if self._fetch_subprojects:
                    if ticker:
                        ticker(filename, 'Fetching subproject from {} source'.format(source.get_kind()))
                    source.fetch()
@@ -511,7 +513,10 @@ class Loader():
            else:
                raise

        loader = Loader(self._context, project, [], parent=self, tempdir=basedir)
        loader = Loader(self._context, project, [],
                        parent=self,
                        tempdir=basedir,
                        fetch_subprojects=self._fetch_subprojects)

        self._loaders[filename] = loader

+7 −5
Original line number Diff line number Diff line
@@ -69,9 +69,8 @@ class PipelineSelection():
#                         current source refs will not be the effective refs.
#    rewritable (bool): Whether the loaded files should be rewritable
#                       this is a bit more expensive due to deep copies
#    use_configured_remote_caches (bool): Whether to connect to configured artifact remotes.
#    add_remote_cache (str): Adds an additional artifact remote URL, which is
#                            prepended to the list of remotes (and thus given highest priority).
#    fetch_subprojects (bool): Whether we should fetch subprojects as a part of the
#                              loading process, if they are not yet locally cached
#
# The ticker methods will be called with an element name for each tick, a final
# tick with None as the argument is passed to signal that processing of this
@@ -86,7 +85,9 @@ class PipelineSelection():
#
class Pipeline():

    def __init__(self, context, project, artifacts, targets, except_, rewritable=False):
    def __init__(self, context, project, artifacts, targets, except_, *,
                 rewritable=False,
                 fetch_subprojects=True):

        self.context = context     # The Context
        self.project = project     # The toplevel project
@@ -105,7 +106,8 @@ class Pipeline():
        # Early initialization
        #

        self._loader = Loader(self.context, self.project, targets + except_)
        self._loader = Loader(self.context, self.project, targets + except_,
                              fetch_subprojects=fetch_subprojects)

        with self.context.timed_activity("Loading pipeline", silent_nested=True):
            meta_elements = self._loader.load(rewritable, None)
Loading