Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check-absolute-imports only for whiteliste directories
Change-Id: I7ffb485494adc4b04bd19123a8b9087cb7e090bf
- Loading branch information
1 parent
153d454
commit 4b4418e
Showing
4 changed files
with
30 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2 | ||
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and | ||
# conditions defined in the file COPYING, which is part of this source code package. | ||
|
||
# This file is for execution by the pre-commit framework. | ||
|
||
import os | ||
import re | ||
import sys | ||
from typing import List | ||
from pathlib import PurePosixPath | ||
|
||
WHITELIST = ("cmk/gui",) | ||
|
||
if __name__ == "__main__": | ||
fails: List[str] = [] | ||
for filename in sys.argv[1:]: | ||
if str(PurePosixPath(filename).parent) not in WHITELIST: | ||
continue | ||
fails.extend([filename for line in open(filename) if re.match("^(from|import) \\.", line)]) | ||
if fails: | ||
sys.stderr.write(f"error: These files are using relative imports: {fails}" + os.linesep) | ||
sys.stderr.write("We currently mandate absolute imports. Please use them." + os.linesep) | ||
sys.stderr.flush() | ||
sys.exit(1) | ||
sys.stderr.flush() | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters