Пример #1
0
    def __init__(self, *arguments, runtime_overrides: List[Tuple[str, str, Any]] = None):
        """
        Construct a context from command line arguments.

        * `arguments`: A series of command line arguments which can be parsed
         by the ravestate command line parser (see argparse.py).
        * `runtime_overrides`: A list of config overrides in the form of (modulename, key, value).
         Can be used to set config entries to values other than strings or lists like in command line arguments.
         An example use-case is a module that starts a new context (in separate process) and can set
         config entries to Connection Objects to enable communication between old and new context.
        """
        modules, overrides, config_files = argparse.handle_args(*arguments)
        self._config = Configuration(config_files)
        self._core_config = {
            self.import_modules_config: [],
            self.tick_rate_config: 20
        }
        self._config.add_conf(Module(name=self.core_module_name, config=self._core_config))
        self._lock = RLock()
        self._shutdown_flag = Event()
        self._properties = dict()
        self._spikes = set()
        self._act_per_state_per_signal_age = dict()
        self._signal_causes = dict()
        self._activations_per_state = dict()
        self._run_task = None

        # Register default signals
        for signal in self._default_signals:
            self._add_sig(signal)

        # Register default properties
        for prop in self._default_properties:
            self.add_prop(prop=prop)

        # Load required modules
        for module_name in self._core_config[self.import_modules_config] + modules:
            self.add_module(module_name)

        # Set required config overrides
        for module_name, key, value in overrides:
            self._config.set(module_name, key, value)
        # Set additional config runtime overrides
        if runtime_overrides:
            for module_name, key, value in runtime_overrides:
                self._config.set(module_name, key, value)

        if self._core_config[self.tick_rate_config] < 1:
            logger.error("Attempt to set core config `tickrate` to a value less-than 1!")
            self._core_config[self.tick_rate_config] = 1
Пример #2
0
    def __init__(self,
                 *arguments,
                 runtime_overrides: List[Tuple[str, str, Any]] = None):
        """
        Construct a context from command line arguments.

        * `arguments`: A series of command line arguments which can be parsed
         by the ravestate command line parser (see argparser.py).
        * `runtime_overrides`: A list of config overrides in the form of (modulename, key, value).
         Can be used to set config entries to values other than strings or lists like in command line arguments.
         An example use-case is a module that starts a new context (in separate process) and can set
         config entries to Connection Objects to enable communication between old and new context.
        """
        modules, overrides, config_files = argparser.handle_args(*arguments)
        self._config = Configuration(config_files)
        self._lock = RLock()
        self._shutdown_flag = Event()
        self._properties = dict()
        self._spikes_per_signal = defaultdict(set)
        self._needy_acts_per_state_per_signal = dict()
        self._signal_causes = dict()
        self._activations_per_state = dict()
        self._run_task = None
        self._modules = set()

        # Load required modules
        self.add_module(CORE_MODULE_NAME)
        self._load_modules(
            self.conf(mod=CORE_MODULE_NAME, key=IMPORT_MODULES_CONFIG_KEY) +
            modules)

        # Set required config overrides
        for module_name, key, value in overrides:
            self._config.set(module_name, key, value)

        # Set additional config runtime overrides
        if runtime_overrides:
            for module_name, key, value in runtime_overrides:
                self._config.set(module_name, key, value)

        self.tick_rate = int(
            self.conf(mod=CORE_MODULE_NAME, key=TICK_RATE_CONFIG_KEY))
        if self.tick_rate < 1:
            logger.error(
                "Attempt to set core config `tickrate` to a value less-than 1!"
            )
            self.tick_rate = 1
Пример #3
0
    def __init__(self, *arguments):
        """
        Construct a context from command line arguments.

        * `arguments`: A series of command line arguments which can be parsed
         by the ravestate command line parser (see argparse.py).
        """
        modules, overrides, config_files = argparse.handle_args(*arguments)
        self._config = Configuration(config_files)
        self._core_config = {
            self._import_modules_config: [],
            self._tick_rate_config: 20
        }
        self._config.add_conf(Module(name=self._core_module_name, config=self._core_config))
        self._lock = Lock()
        self._shutdown_flag = Event()
        self._properties = dict()
        self._spikes = set()
        self._act_per_state_per_signal_age = dict()
        self._signal_causes = dict()
        self._activations_per_state = dict()
        self._run_task = None

        # Register default signals
        for signal in self._default_signals:
            self._add_sig(signal)

        # Register default properties
        for prop in self._default_properties:
            self.add_prop(prop=prop)

        # Set required config overrides
        for module_name, key, value in overrides:
            self._config.set(module_name, key, value)
        if self._core_config[self._tick_rate_config] < 1:
            logger.error("Attempt to set core config `tickrate` to a value less-than 1!")
            self._core_config[self._tick_rate_config] = 1

        # Load required modules
        for module_name in self._core_config[self._import_modules_config]+modules:
            self.add_module(module_name)
Пример #4
0
def under_test():
    return Configuration([])
Пример #5
0
def test_read_config_3(config_file_paths):
    under_test = Configuration(paths=config_file_paths)
    assert under_test.parsed_config_per_module["foo"]["a"] is False
    assert under_test.parsed_config_per_module["poo"]["c"] == 1
    assert under_test.parsed_config_per_module["poo"]["d"] == "hehe"