How to use the stm32pio.settings function in stm32pio

To help you get started, we’ve selected a few stm32pio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ussserrr / stm32pio / tests / test_unit.py View on Github external
def test_save_config(self):
        """
        Explicitly save the config to file and look did that actually happen and whether all the information was
        preserved
        """
        # 'board' is non-default, 'project'-section parameter
        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})
        project.save_config()

        self.assertTrue(FIXTURE_PATH.joinpath(stm32pio.settings.config_file_name).is_file(),
                        msg=f"{stm32pio.settings.config_file_name} file hasn't been created")

        config = configparser.ConfigParser(interpolation=None)
        self.assertGreater(len(config.read(str(FIXTURE_PATH.joinpath(stm32pio.settings.config_file_name)))), 0,
                           msg="Config is empty")
        for section, parameters in stm32pio.settings.config_default.items():
            for option, value in parameters.items():
                with self.subTest(section=section, option=option,
                                  msg="Section/key is not found in the saved config file"):
                    self.assertNotEqual(config.get(section, option, fallback="Not found"), "Not found")

        self.assertEqual(config.get('project', 'board', fallback="Not found"), TEST_PROJECT_BOARD,
                         msg="'board' has not been set")
github ussserrr / stm32pio / stm32pio / lib.py View on Github external
Returns:
            new configparser.ConfigParser instance
        """

        if runtime_parameters is None:
            runtime_parameters = {}

        config = configparser.ConfigParser(interpolation=None)

        # Fill with default values ...
        config.read_dict(copy.deepcopy(stm32pio.settings.config_default))

        # ... then merge with user's config file values (if exist) ...
        self.logger.debug(f"searching for {stm32pio.settings.config_file_name}...")
        config.read(self.path.joinpath(stm32pio.settings.config_file_name))

        ini_config = configparser.ConfigParser(interpolation=None)
        ini_config.read(self.path.joinpath(stm32pio.settings.config_file_name))
        runtime_config = configparser.ConfigParser(interpolation=None)
        runtime_config.read_dict(runtime_parameters)

        if len(ini_config.sections()):
            if len(runtime_config.sections()):
                for ini_sect in ini_config.sections():
                    if runtime_config.has_section(ini_sect):
                        for ini_key, ini_value in ini_config.items(ini_sect):
                            if runtime_config.get(ini_sect, ini_key, fallback=None) not in [None, ini_value]:
                                self.logger.info(f"given '{ini_key}' has taken a precedence over the .ini one")
        else:
            self.logger.debug(f"no or empty {stm32pio.settings.config_file_name} config file, will use the default one")

stm32pio

Small cross-platform Python app that can create and update PlatformIO projects from STM32CubeMX .ioc files. It uses STM32CubeMX to generate a HAL-framework-based code and alongside creates PlatformIO project with compatible parameters to stick them both together. Both CLI and GUI editions are available

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis

Similar packages