How to use the stm32pio.lib.ProjectStage 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_integration.py View on Github external
def test_current_stage(self):
        """
        Go through the sequence of states emulating the real-life project lifecycle
        """

        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})

        for method, expected_stage in [(None, stm32pio.lib.ProjectStage.EMPTY),
                                       ('save_config', stm32pio.lib.ProjectStage.INITIALIZED),
                                       ('generate_code', stm32pio.lib.ProjectStage.GENERATED),
                                       ('pio_init', stm32pio.lib.ProjectStage.PIO_INITIALIZED),
                                       ('patch', stm32pio.lib.ProjectStage.PATCHED),
                                       ('build', stm32pio.lib.ProjectStage.BUILT),
                                       ('clean', stm32pio.lib.ProjectStage.EMPTY),
                                       ('pio_init', stm32pio.lib.ProjectStage.UNDEFINED)]:
            if method is not None:
                getattr(project, method)()
            self.assertEqual(project.state.current_stage, expected_stage)
            if expected_stage != stm32pio.lib.ProjectStage.UNDEFINED:
                self.assertTrue(project.state.is_consistent)
            else:
                # Should be UNDEFINED when the project is messed up (pio_init() after clean())
                self.assertFalse(project.state.is_consistent)
github ussserrr / stm32pio / tests / test_integration.py View on Github external
def test_current_stage(self):
        """
        Go through the sequence of states emulating the real-life project lifecycle
        """

        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})

        for method, expected_stage in [(None, stm32pio.lib.ProjectStage.EMPTY),
                                       ('save_config', stm32pio.lib.ProjectStage.INITIALIZED),
                                       ('generate_code', stm32pio.lib.ProjectStage.GENERATED),
                                       ('pio_init', stm32pio.lib.ProjectStage.PIO_INITIALIZED),
                                       ('patch', stm32pio.lib.ProjectStage.PATCHED),
                                       ('build', stm32pio.lib.ProjectStage.BUILT),
                                       ('clean', stm32pio.lib.ProjectStage.EMPTY),
                                       ('pio_init', stm32pio.lib.ProjectStage.UNDEFINED)]:
            if method is not None:
                getattr(project, method)()
            self.assertEqual(project.state.current_stage, expected_stage)
            if expected_stage != stm32pio.lib.ProjectStage.UNDEFINED:
                self.assertTrue(project.state.is_consistent)
            else:
                # Should be UNDEFINED when the project is messed up (pio_init() after clean())
                self.assertFalse(project.state.is_consistent)
github ussserrr / stm32pio / tests / test_integration.py View on Github external
def test_current_stage(self):
        """
        Go through the sequence of states emulating the real-life project lifecycle
        """

        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})

        for method, expected_stage in [(None, stm32pio.lib.ProjectStage.EMPTY),
                                       ('save_config', stm32pio.lib.ProjectStage.INITIALIZED),
                                       ('generate_code', stm32pio.lib.ProjectStage.GENERATED),
                                       ('pio_init', stm32pio.lib.ProjectStage.PIO_INITIALIZED),
                                       ('patch', stm32pio.lib.ProjectStage.PATCHED),
                                       ('build', stm32pio.lib.ProjectStage.BUILT),
                                       ('clean', stm32pio.lib.ProjectStage.EMPTY),
                                       ('pio_init', stm32pio.lib.ProjectStage.UNDEFINED)]:
            if method is not None:
                getattr(project, method)()
            self.assertEqual(project.state.current_stage, expected_stage)
            if expected_stage != stm32pio.lib.ProjectStage.UNDEFINED:
                self.assertTrue(project.state.is_consistent)
            else:
                # Should be UNDEFINED when the project is messed up (pio_init() after clean())
                self.assertFalse(project.state.is_consistent)
github ussserrr / stm32pio / tests / test_integration.py View on Github external
def test_current_stage(self):
        """
        Go through the sequence of states emulating the real-life project lifecycle
        """

        project = stm32pio.lib.Stm32pio(FIXTURE_PATH, parameters={'project': {'board': TEST_PROJECT_BOARD}})

        for method, expected_stage in [(None, stm32pio.lib.ProjectStage.EMPTY),
                                       ('save_config', stm32pio.lib.ProjectStage.INITIALIZED),
                                       ('generate_code', stm32pio.lib.ProjectStage.GENERATED),
                                       ('pio_init', stm32pio.lib.ProjectStage.PIO_INITIALIZED),
                                       ('patch', stm32pio.lib.ProjectStage.PATCHED),
                                       ('build', stm32pio.lib.ProjectStage.BUILT),
                                       ('clean', stm32pio.lib.ProjectStage.EMPTY),
                                       ('pio_init', stm32pio.lib.ProjectStage.UNDEFINED)]:
            if method is not None:
                getattr(project, method)()
            self.assertEqual(project.state.current_stage, expected_stage)
            if expected_stage != stm32pio.lib.ProjectStage.UNDEFINED:
                self.assertTrue(project.state.is_consistent)
            else:
                # Should be UNDEFINED when the project is messed up (pio_init() after clean())
                self.assertFalse(project.state.is_consistent)
github ussserrr / stm32pio / tests / test_cli.py View on Github external
def test_status(self):
        """
        Test the output returning by the app on a request to the 'status' command
        """

        buffer_stdout = io.StringIO()
        with contextlib.redirect_stdout(buffer_stdout), contextlib.redirect_stderr(None):
            return_code = stm32pio.app.main(sys_argv=['status', '-d', str(FIXTURE_PATH)])

        self.assertEqual(return_code, 0, msg="Non-zero return code")

        matches_counter = 0
        last_stage_pos = -1
        for stage in stm32pio.lib.ProjectStage:
            if stage != stm32pio.lib.ProjectStage.UNDEFINED:
                match = re.search(r"^((\[ \])|(\[\*\])) {2}" + str(stage) + '$', buffer_stdout.getvalue(), re.MULTILINE)
                self.assertTrue(match, msg="Status information was not found on STDOUT")
                if match:
                    matches_counter += 1
                    self.assertGreater(match.start(), last_stage_pos, msg="The order of stages is messed up")
                    last_stage_pos = match.start()

        self.assertEqual(matches_counter, len(stm32pio.lib.ProjectStage) - 1)
github ussserrr / stm32pio / stm32pio / lib.py View on Github external
platformio_ini_is_patched = False
        if pio_is_initialized:  # make no sense to proceed if there is something happened in the first place
            with contextlib.suppress(Exception):  # we just want to know the status and don't care about the details
                platformio_ini_is_patched = self.platformio_ini_is_patched

        # Create the temporary ordered dictionary and fill it with the conditions results arrays
        stages_conditions = collections.OrderedDict()
        stages_conditions[ProjectStage.UNDEFINED] = [True]
        stages_conditions[ProjectStage.EMPTY] = [self.ioc_file.is_file()]
        stages_conditions[ProjectStage.INITIALIZED] = [self.path.joinpath(stm32pio.settings.config_file_name).is_file()]
        stages_conditions[ProjectStage.GENERATED] = [self.path.joinpath('Inc').is_dir() and
                                                     len(list(self.path.joinpath('Inc').iterdir())) > 0,
                                                     self.path.joinpath('Src').is_dir() and
                                                     len(list(self.path.joinpath('Src').iterdir())) > 0]
        stages_conditions[ProjectStage.PIO_INITIALIZED] = [pio_is_initialized]
        stages_conditions[ProjectStage.PATCHED] = [platformio_ini_is_patched,
                                                   not self.path.joinpath('include').is_dir()]
        # Hidden folder! Can be not visible in your file manager and cause a confusion
        stages_conditions[ProjectStage.BUILT] = [
            self.path.joinpath('.pio').is_dir() and
            any([item.is_file() for item in self.path.joinpath('.pio').rglob('*firmware*')])]

        # Fold arrays and save results in ProjectState instance
        conditions_results = ProjectState()
        for state, conditions in stages_conditions.items():
            conditions_results[state] = all(condition is True for condition in conditions)

        return conditions_results
github ussserrr / stm32pio / stm32pio / lib.py View on Github external
def current_stage(self) -> ProjectStage:
        last_consistent_stage = ProjectStage.UNDEFINED
        not_fulfilled_stage_found = False

        # Search for a consecutive sequence of True's and find the last of them. For example, if the array is
        #   [1,1,1,0,0,0,0]
        #        ^
        # we should consider 2 as the last index
        for stage_name, stage_fulfilled in self.items():
            if stage_fulfilled:
                if not_fulfilled_stage_found:
                    # Fall back to the UNDEFINED stage if we have breaks in conditions results array. E.g., for
                    #   [1,1,1,0,1,0,0]
                    # we should return UNDEFINED as it doesn't look like a correct set of files actually
                    last_consistent_stage = ProjectStage.UNDEFINED
                    break
                else:
                    last_consistent_stage = stage_name
            else:
                not_fulfilled_stage_found = True

        return last_consistent_stage
github ussserrr / stm32pio / stm32pio / lib.py View on Github external
pio_is_initialized = False
        with contextlib.suppress(Exception):  # we just want to know the status and don't care about the details
            # Is present, is correct and is not empty
            pio_is_initialized = len(self.platformio_ini_config.sections()) != 0

        platformio_ini_is_patched = False
        if pio_is_initialized:  # make no sense to proceed if there is something happened in the first place
            with contextlib.suppress(Exception):  # we just want to know the status and don't care about the details
                platformio_ini_is_patched = self.platformio_ini_is_patched

        # Create the temporary ordered dictionary and fill it with the conditions results arrays
        stages_conditions = collections.OrderedDict()
        stages_conditions[ProjectStage.UNDEFINED] = [True]
        stages_conditions[ProjectStage.EMPTY] = [self.ioc_file.is_file()]
        stages_conditions[ProjectStage.INITIALIZED] = [self.path.joinpath(stm32pio.settings.config_file_name).is_file()]
        stages_conditions[ProjectStage.GENERATED] = [self.path.joinpath('Inc').is_dir() and
                                                     len(list(self.path.joinpath('Inc').iterdir())) > 0,
                                                     self.path.joinpath('Src').is_dir() and
                                                     len(list(self.path.joinpath('Src').iterdir())) > 0]
        stages_conditions[ProjectStage.PIO_INITIALIZED] = [pio_is_initialized]
        stages_conditions[ProjectStage.PATCHED] = [platformio_ini_is_patched,
                                                   not self.path.joinpath('include').is_dir()]
        # Hidden folder! Can be not visible in your file manager and cause a confusion
        stages_conditions[ProjectStage.BUILT] = [
            self.path.joinpath('.pio').is_dir() and
            any([item.is_file() for item in self.path.joinpath('.pio').rglob('*firmware*')])]

        # Fold arrays and save results in ProjectState instance
        conditions_results = ProjectState()
        for state, conditions in stages_conditions.items():
            conditions_results[state] = all(condition is True for condition in conditions)

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