How to use the stm32pio.settings.config_default 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_cli.py View on Github external
def test_init(self):
        """
        Check for config creation and parameters presence
        """
        result = subprocess.run([PYTHON_EXEC, STM32PIO_MAIN_SCRIPT, 'init', '-d', str(FIXTURE_PATH),
                                 '-b', TEST_PROJECT_BOARD], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        self.assertEqual(result.returncode, 0, msg="Non-zero return code")

        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)
        config.read(str(FIXTURE_PATH.joinpath(stm32pio.settings.config_file_name)))
        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 saved config file"):
                    self.assertIsNotNone(config.get(section, option, fallback=None))
        self.assertEqual(config.get('project', 'board', fallback="Not found"), TEST_PROJECT_BOARD,
                         msg="'board' has not been set")
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
Prepare ConfigParser config for the project. Order of getting values (masking) (higher levels overwrites lower):

            default dict (settings module)  =>  config file stm32pio.ini  =>  user-given (runtime) values
                                                                              (via CLI or another way)

        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]:

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