mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-29 10:16:52 +00:00
Allow customizing the module denylist
This commit is contained in:
parent
6e513a2e71
commit
12f60d656d
2 changed files with 30 additions and 0 deletions
|
|
@ -74,8 +74,24 @@ def check_file(filename: str) -> int:
|
|||
def main(argv: Sequence[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to run')
|
||||
parser.add_argument(
|
||||
'--forbid',
|
||||
type=str, action='append',
|
||||
help='Extra module name(s) to forbid',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--allow',
|
||||
type=str,
|
||||
action='append',
|
||||
help='Extra module name(s) to allow',
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
for name in args.forbid or ():
|
||||
DEBUG_STATEMENTS.add(name)
|
||||
for name in args.allow or ():
|
||||
DEBUG_STATEMENTS.discard(name)
|
||||
|
||||
retv = 0
|
||||
for filename in args.filenames:
|
||||
retv |= check_file(filename)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,20 @@ def test_finds_breakpoint():
|
|||
assert visitor.breakpoints == [Debug(1, 0, 'breakpoint', 'called')]
|
||||
|
||||
|
||||
def test_allow(tmpdir):
|
||||
f_py = tmpdir.join('f.py')
|
||||
f_py.write('import q')
|
||||
ret = main([str(f_py), '--allow', 'q'])
|
||||
assert ret == 0
|
||||
|
||||
|
||||
def test_forbid(tmpdir):
|
||||
f_py = tmpdir.join('f.py')
|
||||
f_py.write('import foo')
|
||||
ret = main([str(f_py), '--forbid', 'foo'])
|
||||
assert ret == 1
|
||||
|
||||
|
||||
def test_returns_one_for_failing_file(tmpdir):
|
||||
f_py = tmpdir.join('f.py')
|
||||
f_py.write('def f():\n import pdb; pdb.set_trace()')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue