Activate conda environment in pre-commit hook.

Save conda environment that was active during conda install when using
option --hooks-activate-conda. The saved environment will be activated
before calling pre-commit hooks.

Especially on Windows, more and more actions within a conda environment
require the conda environment to be activated. Thus saving just the
python executable is not enough any more.

There is currently one downside of using the option
--hooks-activate-conda. It uses "conda run" which will only show
console output after the run is completed. We have a pull request to
conda open which introduces an option to show interactive console
output in conda run. Once this is approved, it might be ok to make this
option the default behaviour.
This commit is contained in:
Martin Trautmann 2020-02-10 16:56:29 +01:00
parent f0ee93c5a7
commit dbdba3c67f
4 changed files with 92 additions and 16 deletions

View file

@ -250,6 +250,13 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
'or exit with a failure code.'
),
)
install_parser.add_argument(
'--hooks-activate-conda', action='store_true', default=False,
help=(
'Whether to activate conda environment before calling pre-commit'
'within hooks.'
),
)
install_hooks_parser = subparsers.add_parser(
'install-hooks',
@ -357,6 +364,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
overwrite=args.overwrite,
hooks=args.install_hooks,
skip_on_missing_config=args.allow_missing_config,
hooks_activate_conda=args.hooks_activate_conda,
)
elif args.command == 'init-templatedir':
return init_templatedir(