diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2021-12-14 23:54:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-14 23:54:58 +0100 |
commit | 39dc44bfa5fbb9500166b3480295379602e5bbc5 (patch) | |
tree | ee785ba8d9e189fb2b1bffda19492414cd7c0d2c /scripts/internal/git_pre_commit.py | |
parent | b490b5d51af6ed29709c357a00fcdb6bda26df78 (diff) | |
download | psutil-39dc44bfa5fbb9500166b3480295379602e5bbc5.tar.gz |
Automatically sort imports (isort CLI tool) (#2033)
Diffstat (limited to 'scripts/internal/git_pre_commit.py')
-rwxr-xr-x | scripts/internal/git_pre_commit.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/scripts/internal/git_pre_commit.py b/scripts/internal/git_pre_commit.py index 2ec4303d..92bc0f0a 100755 --- a/scripts/internal/git_pre_commit.py +++ b/scripts/internal/git_pre_commit.py @@ -20,6 +20,7 @@ Install this with "make install-git-hooks". """ from __future__ import print_function + import os import subprocess import sys @@ -115,14 +116,26 @@ def main(): print("%s:%s %s" % (path, lineno, line)) return exit("bare except clause") - # Python linter + # Python linters if py_files: + # Flake8 assert os.path.exists('.flake8') # XXX: we should escape spaces and possibly other amenities here cmd = "%s -m flake8 --config=.flake8 %s" % (PYTHON, " ".join(py_files)) ret = subprocess.call(cmd, shell=True) if ret != 0: - return exit("python code is not flake8 compliant") + return exit("python code is not flake8 compliant; " + "try running 'make fix-flake8'") + + # isort + assert os.path.exists('.isort.cfg') + cmd = "%s -m isort --settings=.isort.cfg --check-only %s" % ( + PYTHON, " ".join(py_files)) + ret = subprocess.call(cmd, shell=True) + if ret != 0: + return exit("python code is not flake8 compliant; " + "try running 'make fix-imports'") + # C linter if c_files: # XXX: we should escape spaces and possibly other amenities here |