Skip to content

Commit

Permalink
check-absolute-imports only for whiteliste directories
Browse files Browse the repository at this point in the history
Change-Id: I7ffb485494adc4b04bd19123a8b9087cb7e090bf
  • Loading branch information
UlrichBschorer committed Feb 24, 2021
1 parent 153d454 commit 4b4418e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 42 deletions.
14 changes: 1 addition & 13 deletions .pre-commit-config.yaml
Expand Up @@ -22,14 +22,8 @@ repos:
- id: trailing-whitespace
- id: check-merge-conflict
types: [file]
# - id: check-docstring-first
- id: check-yaml
- id: end-of-file-fixer
# - repo: https://github.com/pre-commit/mirrors-scss-lint
# rev: v0.59.0
# hooks:
# - id: scss-lint
# files: \.scss$
- repo: local
hooks:
- id: yapf
Expand Down Expand Up @@ -66,7 +60,7 @@ repos:
types: [file, python]
- id: absolute-imports
name: Check absolute imports
entry: scripts/check-absolute-imports
entry: scripts/check-absolute-imports.py
language: script
types: [file, python]
- id: flake8
Expand All @@ -75,9 +69,3 @@ repos:
language: script
types: [file, python]
verbose: true
# - id: unit-tests
#name: Check affected unit tests
#entry: scripts/check-pytest-testmon 127
#language: script
#types: [file, python]
#verbose: true
28 changes: 0 additions & 28 deletions scripts/check-absolute-imports

This file was deleted.

28 changes: 28 additions & 0 deletions scripts/check-absolute-imports.py
@@ -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)
2 changes: 1 addition & 1 deletion scripts/check-licence
Expand Up @@ -29,7 +29,7 @@ log() {
}

if [ ${#fails[*]} -ne 0 ]; then
log "These files are missing licence headers or the copyright is outdated:"
log "These files are missing licence headers:"
log ${fails[@]}
log
exit 1
Expand Down

0 comments on commit 4b4418e

Please sign in to comment.