How to use the autohooks.settings.Mode.UNKNOWN function in autohooks

To help you get started, we’ve selected a few autohooks 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 greenbone / autohooks / tests / test_settings.py View on Github external
def test_get_effective_mode(self):
        self.assertEqual(Mode.PIPENV.get_effective_mode(), Mode.PIPENV)
        self.assertEqual(Mode.PYTHONPATH.get_effective_mode(), Mode.PYTHONPATH)
        self.assertEqual(Mode.POETRY.get_effective_mode(), Mode.POETRY)
        self.assertEqual(Mode.UNDEFINED.get_effective_mode(), Mode.PYTHONPATH)
        self.assertEqual(Mode.UNKNOWN.get_effective_mode(), Mode.PYTHONPATH)
github greenbone / autohooks / tests / test_settings.py View on Github external
def test_string_conversion(self):
        self.assertEqual(str(Mode.PIPENV), 'pipenv')
        self.assertEqual(str(Mode.PYTHONPATH), 'pythonpath')
        self.assertEqual(str(Mode.POETRY), 'poetry')
        self.assertEqual(str(Mode.UNKNOWN), 'unknown')
        self.assertEqual(str(Mode.UNDEFINED), 'undefined')
github greenbone / autohooks / autohooks / hooks.py View on Github external
def read_mode(self) -> Mode:
        lines = self.pre_commit_hook.split('\n')
        if len(lines) < 1 or len(lines[0]) == 0:
            return Mode.UNDEFINED

        shebang = lines[0][2:]

        if shebang == PYTHON3_SHEBANG:
            return Mode.PYTHONPATH
        if shebang == POETRY_SHEBANG:
            return Mode.POETRY
        if shebang == PIPENV_SHEBANG:
            return Mode.PIPENV

        return Mode.UNKNOWN
github greenbone / autohooks / autohooks / settings.py View on Github external
def from_string(modestring: str) -> 'Mode':
        if not modestring:
            return Mode.UNDEFINED

        try:
            return Mode[modestring.upper()]
        except KeyError:
            return Mode.UNKNOWN
github greenbone / autohooks / autohooks / config.py View on Github external
def get_mode(self) -> Mode:
        if self.has_autohooks_config():
            mode = self._autohooks_config.get_value('mode')
            if not mode:
                return Mode.UNDEFINED

            try:
                return Mode[mode.upper()]
            except KeyError:
                return Mode.UNKNOWN

        return Mode.UNDEFINED
github greenbone / autohooks / autohooks / cli / check.py View on Github external
if not config.is_autohooks_enabled():
            term.error(
                'autohooks is not enabled in your {} file. Please add '
                'a "{}" section.'.format(str(pyproject_toml), AUTOHOOKS_SECTION)
            )
        elif pre_commit_hook.exists():
            config_mode = config.get_mode()
            hook_mode = pre_commit_hook.read_mode()

            if config_mode == Mode.UNDEFINED:
                term.warning(
                    'autohooks mode is not defined in {}.'.format(
                        str(pyproject_toml)
                    )
                )
            elif config_mode == Mode.UNKNOWN:
                term.warning(
                    'Unknown autohooks mode in {}.'.format(str(pyproject_toml))
                )

            if (
                config_mode.get_effective_mode()
                != hook_mode.get_effective_mode()
            ):
                term.warning(
                    'autohooks mode "{}" in pre-commit hook {} differs from '
                    'mode "{}" in {}.'.format(
                        str(hook_mode),
                        str(pre_commit_hook),
                        str(config_mode),
                        str(pyproject_toml),
                    )