Skip to content

Commit

Permalink
Add the import linter with rules to cover our core modules (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
tolomea authored Aug 7, 2019
1 parent 55d9a13 commit da15fe9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ repos:
name: "Black"
language: system
pass_filenames: false
entry: python -m tools.black_runner kedro extras features tests
entry: python -m tools.min_version 3.6 "pip install black" "black kedro extras features tests"
- id: legal
name: "Licence check"
language: system
pass_filenames: false
entry: make legal
- id: imports
name: "Import Linter"
language: system
pass_filenames: false
entry: python -m tools.min_version 3.6 "pip install import-linter" lint-imports
43 changes: 43 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,46 @@ addopts=--cov-report xml:coverage.xml
--cov tests
--no-cov-on-fail
-ra

[importlinter]
root_package = kedro

[importlinter:contract:1]
name = Contrib > CLI > Context > Library, Runner > IO & Pipeline
type = layers
containers = kedro
layers =
contrib
cli
context
runner
io
pipeline
config

[importlinter:contract:2]
name = Pipeline and IO are independent
type = independence
modules =
kedro.pipeline
kedro.io

[importlinter:contract:3]
name = Config can't import Runner et al
type = forbidden
source_modules =
kedro.config
forbidden_modules =
kedro.runner
kedro.io
kedro.pipeline
[importlinter:contract:4]
name = Runner et al can't import Config
type = forbidden
source_modules =
kedro.runner
kedro.io
kedro.pipeline
forbidden_modules =
kedro.config
24 changes: 14 additions & 10 deletions tools/black_runner.py → tools/min_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@
If python version is 3.5 - just exit with 0 status.
"""
import platform
import shlex
import subprocess
import sys

VERSION = tuple(map(int, platform.python_version_tuple()[:2]))
if __name__ == "__main__":
required_version = tuple(int(x) for x in sys.argv[1].strip().split("."))
install_cmd = shlex.split(sys.argv[2])
run_cmd = shlex.split(sys.argv[3])

if VERSION < (3, 6):
print("Python version is too low, exiting")
sys.exit(0)
current_version = tuple(map(int, platform.python_version_tuple()[:2]))

try:
import black # noqa: F401 pylint: disable=unused-import
except ImportError:
subprocess.run(["pip", "install", "black"], check=True)
if current_version < required_version:
print("Python version is too low, exiting")
sys.exit(0)


subprocess.run(["black"] + sys.argv[1:], check=True)
try:
subprocess.run(run_cmd, check=True)
except FileNotFoundError:
subprocess.run(install_cmd, check=True)
subprocess.run(run_cmd, check=True)

0 comments on commit da15fe9

Please sign in to comment.