mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-18 00:24:47 +04:00
feat: add homli custom logic.
This commit is contained in:
parent
03ef7f3f8d
commit
79799eabb0
2 changed files with 56 additions and 4 deletions
|
|
@ -1,13 +1,26 @@
|
|||
from __future__ import annotations
|
||||
import sys
|
||||
from pre_commit.homli.constants import DEFAULT_CONFIG_FILE
|
||||
|
||||
import importlib.metadata
|
||||
if sys.version_info >= (3, 8): # pragma: >=3.8 cover
|
||||
import importlib.metadata as importlib_metadata
|
||||
else: # pragma: <3.8 cover
|
||||
import importlib_metadata
|
||||
|
||||
CONFIG_FILE = '.pre-commit-config.yaml'
|
||||
CONFIG_FILE = DEFAULT_CONFIG_FILE
|
||||
MANIFEST_FILE = '.pre-commit-hooks.yaml'
|
||||
|
||||
# Bump when installation changes in a backwards / forwards incompatible way
|
||||
INSTALLED_STATE_VERSION = '1'
|
||||
# Bump when modifying `empty_template`
|
||||
LOCAL_REPO_VERSION = '1'
|
||||
|
||||
VERSION = importlib.metadata.version('pre_commit')
|
||||
VERSION = importlib_metadata.version('pre_commit')
|
||||
|
||||
# `manual` is not invoked by any installed git hook. See #719
|
||||
STAGES = (
|
||||
'commit', 'merge-commit', 'prepare-commit-msg', 'commit-msg',
|
||||
'post-commit', 'manual', 'post-checkout', 'push', 'post-merge',
|
||||
'post-rewrite',
|
||||
)
|
||||
|
||||
DEFAULT = 'default'
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ from pre_commit.error_handler import error_handler
|
|||
from pre_commit.logging_handler import logging_handler
|
||||
from pre_commit.store import Store
|
||||
|
||||
from pre_commit.homli.install_uninstall import setup_homli
|
||||
from pre_commit.homli.install_uninstall import install_homli
|
||||
|
||||
logger = logging.getLogger('pre_commit')
|
||||
|
||||
|
|
@ -257,6 +259,34 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|||
)
|
||||
_add_hook_type_option(init_templatedir_parser)
|
||||
|
||||
######################################
|
||||
# add custom setup command for homli #
|
||||
######################################
|
||||
setup_homli_parser = subparsers.add_parser(
|
||||
'homli-setup', help='Sets up HOMLI pre-commit configuration.',
|
||||
)
|
||||
add_color_option(setup_homli_parser)
|
||||
_add_config_option(setup_homli_parser)
|
||||
|
||||
install_homli_parser = subparsers.add_parser(
|
||||
'homli-install', help='Install HOMLI pre-commit configuration to git repository.',
|
||||
)
|
||||
add_color_option(install_homli_parser)
|
||||
_add_config_option(install_homli_parser)
|
||||
install_homli_parser.add_argument(
|
||||
'-f', '--overwrite', action='store_true',
|
||||
help='Overwrite existing hooks / remove migration mode.',
|
||||
)
|
||||
install_homli_parser.add_argument(
|
||||
'--install-hooks', action='store_true',
|
||||
help=(
|
||||
'Whether to install hook environments for all environments '
|
||||
'in the config file.'
|
||||
),
|
||||
)
|
||||
_add_hook_type_option(install_homli_parser)
|
||||
######################################
|
||||
|
||||
install_parser = _add_cmd('install', help='Install the pre-commit script.')
|
||||
_add_config_option(install_parser)
|
||||
install_parser.add_argument(
|
||||
|
|
@ -400,6 +430,15 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|||
hooks=args.install_hooks,
|
||||
skip_on_missing_config=args.allow_missing_config,
|
||||
)
|
||||
elif args.command == 'homli-install':
|
||||
return install_homli(
|
||||
store,
|
||||
hook_types=args.hook_types,
|
||||
overwrite=args.overwrite,
|
||||
hooks=args.install_hooks
|
||||
)
|
||||
elif args.command == 'homli-setup':
|
||||
return setup_homli()
|
||||
elif args.command == 'init-templatedir':
|
||||
return init_templatedir(
|
||||
args.config, store, args.directory,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue