Beispiel #1
0
    def env(self, parent, default_env):
        """Retrieve env for the dependency.

        :param parent: Anod instance in which the dep was declared
        :type parent: Anod
        :param default_env: default env for the current context
        :type default_env: BaseEnv
        :return: env object that should be used by the dependency
        :rtype: BaseEnv
        """
        # Get the current environment associated with the Anod instance
        # and adjust it based on dependency parameters
        dep_env = BaseEnv(parent.env.build, parent.env.host, parent.env.target)

        # For simulation purposes we sometimes load specs as if it was
        # loaded on a non local machine thus 'default' does not correspond
        # to the default build platform of the local machine.
        if self.build == "default":
            build = default_env.build.platform
        else:
            build = self.build

        if self.host == "default":
            host = default_env.build.platform
        else:
            host = self.host

        if self.target == "default":
            target = default_env.build.platform
        else:
            target = self.target

        dep_env.set_env(build, host, target)
        return dep_env
Beispiel #2
0
    def __init__(self,
                 stack=None,
                 plan=None,
                 server=None,
                 build=None,
                 host=None,
                 target=None,
                 **kwargs):
        """Initialize an execution context or a scope.

        :param stack: stack of BaseEnv object that keep track of scopes. Used
            only internally
        :type stack: list[BaseEnv]
        :param server: a BaseEnv object that represent the host default env.
            server parameter is taken into account only during creation of
            the initial context.
        :type server: BaseEnv
        :param build: see e3.env.BaseEnv.set_env
        :type build: str | None
        :param host: see e3.env.BaseEnv.set_env
        :type host: str | None
        :param target: see e3.env.BaseEnv.set_env
        :type target: str | None
        :param kwargs: additional data for the current scope/context
        :type kwargs: dict
        """
        if stack:
            # This is a scope creation, so copy current env
            self.stack = stack
            self.plan = plan
            new = self.stack[-1].copy(build=build, host=host, target=target)
        else:
            self.stack = []
            if server is not None:
                # This is a new context
                new = server.copy(build, host, target)
            else:
                # This is a new context with no server information. In that
                # case retrieve defaults for the local machine.
                new = BaseEnv()
                new.set_env(build, host, target)

        # Store additional data
        for k, v in kwargs.iteritems():
            setattr(new, k, v)

        # And push on the stack
        self.stack.append(new)

        # Registered functions that correspond to actions. Note that
        # there is no need to propagate registered action to children
        # scopes. Only initial context use them. The overall scheme
        # works also because all scopes refer to the same stack of env
        # (because the object is mutable).
        self.actions = {}
        self.action_list = []
Beispiel #3
0
    def __init__(self,
                 stack=None,
                 plan=None,
                 server=None,
                 build=None,
                 host=None,
                 target=None,
                 **kwargs):
        """Initialize an execution context or a scope.

        :param stack: stack of BaseEnv object that keep track of scopes. Used
            only internally
        :type stack: list[BaseEnv]
        :param server: a BaseEnv object that represent the host default env.
            server parameter is taken into acount only during creation of the
            initial context.
        :type server: BaseEnv
        :param build: see e3.env.BaseEnv.set_env
        :type build: str | None
        :param host: see e3.env.BaseEnv.set_env
        :type host: str | None
        :param target: see e3.env.BaseEnv.set_env
        :type target: str | None
        :param kwargs: additional data for the current scope/context
        :type kwargs: dict
        """
        if stack:
            # This is a scope creation, so copy current env
            self.stack = stack
            self.plan = plan
            new = self.stack[-1].copy(build=build, host=host, target=target)
        else:
            self.stack = []
            if server is not None:
                # This is a new context
                new = server.copy(build, host, target)
            else:
                # This is a new context with no server information. In that
                # case retrieve defaults for the local machine.
                new = BaseEnv()
                new.set_env(build, host, target)

        # Store additionnal data
        for k, v in kwargs.iteritems():
            setattr(new, k, v)

        # And push on the stack
        self.stack.append(new)

        # Registered functions that correspond to actions. Note that
        # there is no need to propagate registered action to children
        # scopes. Only initial context use them. The overall scheme
        # works also because all scopes refer to the same stack of env
        # (because the object is mutable).
        self.actions = {}
Beispiel #4
0
    def env(self, parent, default_env=None):
        """Retrieve env for the dependency.

        :param parent: Anod instance in which the dep was declared
        :type parent: Anod
        :param default_env: default env for the current context
        :type default_env: BaseEnv | None
        :return: env object that should be used by the dependency
        :rtype: BaseEnv
        """
        # Get the current environment associated with the Anod instance
        # and adjust it based on dependency parameters
        dep_env = BaseEnv(parent.env.build, parent.env.host, parent.env.target)

        if self.build == 'default' and default_env is not None:
            # For simulation purposes we sometimes load specs as if it was
            # load on a non local machine thus 'default' does not correspond
            # to the default build platform of the local machine.
            build = default_env.build.platform
        else:
            build = self.build

        dep_env.set_env(build, self.host, self.target)
        return dep_env
Beispiel #5
0
    def __init__(
        self,
        stack: Optional[List[BaseEnv]] = None,
        plan: Optional[Plan] = None,
        ignore_disabled: bool = True,
        server: Optional[BaseEnv] = None,
        build: Optional[str] = None,
        host: Optional[str] = None,
        target: Optional[str] = None,
        enabled: bool = True,
        **kwargs: Any,
    ):
        """Initialize an execution context or a scope.

        :param stack: stack of BaseEnv object that keep track of scopes. Used
            only internally. User instantiation of PlanContext should be done
            with stack set to None.
        :param plan: the plan to execute
        :param ignore_disabled: when true, discard all lines in
            blocks "with defaults(enabled=False):"
        :param server: a BaseEnv object that represent the host default env.
            server parameter is taken into account only during creation of
            the initial context.
        :param build: see e3.env.BaseEnv.set_env
        :param host: see e3.env.BaseEnv.set_env
        :param target: see e3.env.BaseEnv.set_env
        :param enabled: whether the plan line is enabled or disabled
        :param kwargs: additional data for the current scope/context
        """
        self.ignore_disabled = ignore_disabled
        if stack:
            # This is a scope creation, so copy current env
            self.stack = stack
            self.plan = plan
            new = self.stack[-1].copy(build=build, host=host, target=target)

            if not enabled:
                # we are in a block with enabled=False set, disable all
                # lines in that block
                new.enabled = enabled

        else:
            self.stack = []
            if server is not None:
                # This is a new context
                new = server.copy(build, host, target)
            else:
                # This is a new context with no server information. In that
                # case retrieve defaults for the local machine.
                new = BaseEnv()
                new.set_env(build, host, target)
            new.enabled = enabled

        # Store additional data
        for k, v in kwargs.items():
            setattr(new, k, v)

        # And push on the stack
        self.stack.append(new)

        # Registered functions that correspond to actions. Note that
        # there is no need to propagate registered action to children
        # scopes. Only initial context use them. The overall scheme
        # works also because all scopes refer to the same stack of env
        # (because the object is mutable).
        self.actions: Dict[str, Callable] = {}
        self.action_list: List[BaseEnv] = []