How to use the autohooks.settings.Mode.PYTHONPATH 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_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 / 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 / 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 / cli / __init__.py View on Github external
subparsers = parser.add_subparsers(dest='command')
    activate_parser = subparsers.add_parser(
        'activate', help='Activate the pre-commit hook.'
    )
    activate_parser.add_argument(
        '-f',
        '--force',
        action='store_true',
        help='Force activation of hook even if a hook already exists',
    )
    activate_parser.add_argument(
        '-m',
        '--mode',
        dest='mode',
        choices=[str(Mode.PYTHONPATH), str(Mode.PIPENV), str(Mode.POETRY)],
        help='Mode for loading autohooks during hook execution. Either load '
        'autohooks from the PYTHON_PATH, via pipenv or via poetry.',
    )

    subparsers.add_parser('check', help='Check installed pre-commit hook')

    args = parser.parse_args()

    if not args.command:
        parser.print_usage()

    term = Terminal()
    if args.command == 'activate':
        install_hooks(term, args)
    elif args.command == 'check':
        check_hooks(term)
github greenbone / autohooks / autohooks / settings.py View on Github external
def get_effective_mode(self):
        # pylint: disable=comparison-with-callable
        if self.value == Mode.PIPENV.value:
            return Mode.PIPENV
        if self.value == Mode.POETRY.value:
            return Mode.POETRY
        return Mode.PYTHONPATH