Skip to content

Commit

Permalink
[KED-1275] Simplify min_version and add import-linter to test_require…
Browse files Browse the repository at this point in the history
…ments (kedro-org#358)
  • Loading branch information
Lorena Bălan committed Dec 17, 2019
1 parent aad73e6 commit bfd802d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 5 additions & 13 deletions tools/min_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit bfd802d

Please sign in to comment.