Exemple #1
0
 def test_get_poetry_multiline_mode_from_string(self):
     self.assertEqual(
         Mode.from_string('poetry_multiline'), Mode.POETRY_MULTILINE
     )
     self.assertEqual(
         Mode.from_string('POETRY_MULTILINE'), Mode.POETRY_MULTILINE
     )
Exemple #2
0
 def test_get_pipenv_multiline_mode_from_string(self):
     self.assertEqual(
         Mode.from_string('pipenv_multiline'), Mode.PIPENV_MULTILINE
     )
     self.assertEqual(
         Mode.from_string('PIPENV_MULTILINE'), Mode.PIPENV_MULTILINE
     )
Exemple #3
0
def install_hooks(term: Terminal, args: Namespace) -> None:
    pre_commit_hook = PreCommitHook()
    pyproject_toml = get_pyproject_toml_path()
    config = load_config_from_pyproject_toml(pyproject_toml)

    if pre_commit_hook.exists() and not args.force:
        term.ok('autohooks pre-commit hook is already installed at {}.'.format(
            str(pre_commit_hook)))
        with term.indent():
            term.print()
            term.info(
                "Run 'autohooks activate --force' to override the current "
                "installed pre-commit hook.")
            term.info(
                "Run 'autohooks check' to validate the current status of "
                "the installed pre-commit hook.")
    else:
        if not config.is_autohooks_enabled():
            term.warning('autohooks is not enabled in your {} file. '
                         'Run \'autohooks check\' for more '
                         'details.'.format(str(pyproject_toml)))

        if args.mode:
            mode = Mode.from_string(args.mode)
        else:
            mode = config.get_mode()

        pre_commit_hook.write(mode=mode)

        term.ok(
            'autohooks pre-commit hook installed at {} using {} mode.'.format(
                str(pre_commit_hook), str(mode.get_effective_mode())))
Exemple #4
0
    def get_mode(self) -> Mode:
        if self.has_autohooks_config():
            mode = self._autohooks_config.get_value('mode')
            if not mode:
                return Mode.UNDEFINED

            mode = Mode.from_string(mode.upper())
            is_virtual_env = mode == Mode.PIPENV or mode == Mode.POETRY
            if is_virtual_env and not is_split_env():
                if mode == Mode.POETRY:
                    mode = Mode.POETRY_MULTILINE
                else:
                    mode = Mode.PIPENV_MULTILINE
            return mode

        return Mode.UNDEFINED
 def test_get_invalid_mode_from_string(self):
     self.assertEqual(Mode.from_string('foo'), Mode.UNKNOWN)
     self.assertEqual(Mode.from_string(None), Mode.UNDEFINED)
     self.assertEqual(Mode.from_string(''), Mode.UNDEFINED)
 def test_get_poetry_mode_from_string(self):
     self.assertEqual(Mode.from_string('poetry'), Mode.POETRY)
     self.assertEqual(Mode.from_string('POETRY'), Mode.POETRY)
 def test_get_pythonpathvenv_mode_from_string(self):
     self.assertEqual(Mode.from_string('pythonpathvenv'),
                      Mode.PYTHONPATHVENV)
     self.assertEqual(Mode.from_string('PYTHONPATHVENV'),
                      Mode.PYTHONPATHVENV)
 def test_get_pythonpath_mode_from_string(self):
     self.assertEqual(Mode.from_string('pythonpath'), Mode.PYTHONPATH)
     self.assertEqual(Mode.from_string('PYTHONPATH'), Mode.PYTHONPATH)
 def test_get_pipenv_mode_from_string(self):
     self.assertEqual(Mode.from_string('pipenv'), Mode.PIPENV)
     self.assertEqual(Mode.from_string('PIPENV'), Mode.PIPENV)