diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index daeae8d56f..fe4ece7a2a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -106,7 +106,7 @@ repos: name: "Black" language: system pass_filenames: false - entry: python -m tools.min_version 3.6 "pip install black" "black kedro extras features tests" + entry: python -m tools.min_version 3.6 "black kedro extras features tests" - id: legal name: "Licence check" language: system @@ -116,4 +116,4 @@ repos: name: "Import Linter" language: system pass_filenames: false - entry: python -m tools.min_version 3.6 "pip install import-linter" lint-imports + entry: python -m tools.min_version 3.6 lint-imports diff --git a/test_requirements.txt b/test_requirements.txt index 71465109ac..09c1164b47 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -9,6 +9,7 @@ codacy-coverage flake8>=3.5,<4.0 gcsfs>=0.3.0, <1.0 hdfs>=2.5.8, <3.0 +import-linter==1.0; python_version >= '3.6' joblib==0.12.3 jupyter_client>=5.1.0, <6.0 matplotlib>=3.0.3, <4.0 diff --git a/tools/min_version.py b/tools/min_version.py index 193c2879b3..4ddb225051 100644 --- a/tools/min_version.py +++ b/tools/min_version.py @@ -27,30 +27,22 @@ # limitations under the License. """ -Black needs python 3.6+, but Kedro should work on 3.5 too, -that's why we can't put ``black`` into test_requirements.txt and -have to install it manually like that. +Black and import-linter need python 3.6+, but Kedro should work on 3.5 too. +That's why we run the relevant commands conditionally on CI/precommit. If python version is 3.5 - just exit with 0 status. """ -import platform import shlex import subprocess import sys 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]) - - current_version = tuple(map(int, platform.python_version_tuple()[:2])) + current_version = sys.version_info[:2] if current_version < required_version: print("Python version is too low, exiting") sys.exit(0) - try: - subprocess.run(run_cmd, check=True) - except (FileNotFoundError, subprocess.CalledProcessError): - subprocess.run(install_cmd, check=True) - subprocess.run(run_cmd, check=True) + run_cmd = shlex.split(sys.argv[2]) + subprocess.run(run_cmd, check=True)