Skip to content

Commit

Permalink
Add pre-commit wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
  • Loading branch information
LecrisUT committed Apr 19, 2023
1 parent c193045 commit 6a80dfe
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

- id: tmt-lint
name: tmt lint
entry: bash -c "git ls-files --error-unmatch $(python3 -c 'import tmt; print(tmt.Tree(logger=tmt.Logger.create(), path=\".\").root)')/.fmf/version && tmt lint --source $@" PAD
entry: tmt-pre-commit
files: '.*\.fmf$'
verbose: true
pass_filenames: true
Expand All @@ -18,7 +18,7 @@

- id: tmt-tests-lint
name: tmt tests lint
entry: bash -c "git ls-files --error-unmatch $(python3 -c 'import tmt; print(tmt.Tree(logger=tmt.Logger.create(), path=\".\").root)')/.fmf/version && tmt tests lint --source $@" PAD
entry: tmt-pre-commit --lint-type tests
files: '.*\.fmf$'
verbose: true
pass_filenames: true
Expand All @@ -27,7 +27,7 @@

- id: tmt-plans-lint
name: tmt plans lint
entry: bash -c "git ls-files --error-unmatch $(python3 -c 'import tmt; print(tmt.Tree(logger=tmt.Logger.create(), path=\".\").root)')/.fmf/version && tmt plans lint --source $@" PAD
entry: tmt-pre-commit --lint-type plans
files: '.*\.fmf$'
verbose: true
pass_filenames: true
Expand All @@ -36,7 +36,7 @@

- id: tmt-stories-lint
name: tmt stories lint
entry: bash -c "git ls-files --error-unmatch $(python3 -c 'import tmt; print(tmt.Tree(logger=tmt.Logger.create(), path=\".\").root)')/.fmf/version && tmt stories lint --source $@" PAD
entry: tmt-pre-commit --lint-type stories
files: '.*\.fmf$'
verbose: true
pass_filenames: true
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,8 @@
packages=__pkgs__,
provides=__provides__,
scripts=__scripts__,
entry_points={
'console_scripts': ['tmt-pre-commit=tmt.cli:pre_commit']
},
version=__version__
)
2 changes: 2 additions & 0 deletions tmt.spec
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ package to have all available plugins ready for testing.

%install
%py3_install
# Executable only used for pre-commit. Should not be installed
rm %{buildroot}/%{_bindir}/tmt-pre-commit

mkdir -p %{buildroot}%{_mandir}/man1
mkdir -p %{buildroot}/etc/bash_completion.d/
Expand Down
44 changes: 44 additions & 0 deletions tmt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1618,3 +1618,47 @@ def completion_fish(context: Context, install: bool, **kwargs: Any) -> None:
Setup shell completions for fish.
"""
setup_completion('fish', install)


@click.command(context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True,
))
@click.pass_context
@click.option(
'-r', '--root', metavar='PATH', show_default=True, default='.',
help='Variable passed to tmt main. See `tmt --help`')
@click.option(
'-v', '--verbose', count=True, default=0,
help='Variable passed to tmt main. See `tmt --help`')
@click.option(
'--version', is_flag=True,
help="Variable passed to tmt main. See `tmt --help`")
@click.option(
'--lint-type', default=None,
type=click.Choice(['tests', 'plans', 'stories'], case_sensitive=False),
help='tmt types to lint')
def pre_commit(
context: Context,
root: str,
verbose: int,
version: bool,
lint_type: Optional[str]) -> None:
"""
Cli wrapper of tmt lint for
"""
# Special handling for --version
if version:
main(['--version'])
# Construct the arguments for main cli
args = ['--root', root]
if verbose:
args += ['-' + 'v' * verbose]
if lint_type:
args += [lint_type]
args += ['lint', '--source']
# Get everything else
if '--source' in context.args:
context.args.remove('--source')
args += context.args
main(args)

0 comments on commit 6a80dfe

Please sign in to comment.