summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-02-18 15:12:48 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2020-02-18 15:12:48 +0100
commitd928430a5cafea6506906b0e466d9d5465e2e180 (patch)
tree003dc543f75b4a65f77adecba285b3e67cdba149
parent3dc7bd8c32ffdaf5a11ef4db9f1221024f9c605a (diff)
downloadpsutil-d928430a5cafea6506906b0e466d9d5465e2e180.tar.gz
integrate C linter in GIT commit hook
-rw-r--r--psutil/_psutil_aix.c2
-rw-r--r--psutil/arch/solaris/environ.c4
-rwxr-xr-xscripts/internal/.git-pre-commit16
-rwxr-xr-xscripts/internal/clinter.py2
4 files changed, 17 insertions, 7 deletions
diff --git a/psutil/_psutil_aix.c b/psutil/_psutil_aix.c
index b8584f26..cf79d307 100644
--- a/psutil/_psutil_aix.c
+++ b/psutil/_psutil_aix.c
@@ -15,7 +15,7 @@
* - psutil.Process.io_counters read count is always 0
* - psutil.Process.io_counters may not be available on older AIX versions
* - psutil.Process.threads may not be available on older AIX versions
- # - psutil.net_io_counters may not be available on older AIX versions
+ * - psutil.net_io_counters may not be available on older AIX versions
* - reading basic process info may fail or return incorrect values when
* process is starting (see IBM APAR IV58499 - fixed in newer AIX versions)
* - sockets and pipes may not be counted in num_fds (fixed in newer AIX
diff --git a/psutil/arch/solaris/environ.c b/psutil/arch/solaris/environ.c
index eb0fa2ab..482fe1fc 100644
--- a/psutil/arch/solaris/environ.c
+++ b/psutil/arch/solaris/environ.c
@@ -11,8 +11,8 @@
#include <Python.h>
#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
-# undef _FILE_OFFSET_BITS
-# undef _LARGEFILE64_SOURCE
+ #undef _FILE_OFFSET_BITS
+ #undef _LARGEFILE64_SOURCE
#endif
#include <sys/types.h>
diff --git a/scripts/internal/.git-pre-commit b/scripts/internal/.git-pre-commit
index 621879df..e6009253 100755
--- a/scripts/internal/.git-pre-commit
+++ b/scripts/internal/.git-pre-commit
@@ -77,6 +77,8 @@ def main():
out = sh("git diff --cached --name-only")
py_files = [x for x in out.split('\n') if x.endswith('.py') and
os.path.exists(x)]
+ c_files = [x for x in out.split('\n') if x.endswith(('.c', '.h')) and
+ os.path.exists(x)]
lineno = 0
kw = {'encoding': 'utf8'} if sys.version_info[0] == 3 else {}
@@ -100,7 +102,7 @@ def main():
print("%s:%s %s" % (path, lineno, line))
return exit("commit aborted: bare except clause")
- # flake8
+ # Python linter
if py_files:
try:
import flake8 # NOQA
@@ -108,12 +110,22 @@ def main():
return exit("commit aborted: flake8 is not installed; "
"run 'make setup-dev-env'")
- # XXX: we should scape spaces and possibly other amenities here
+ # XXX: we should escape spaces and possibly other amenities here
ret = subprocess.call(
"%s -m flake8 %s" % (sys.executable, " ".join(py_files)),
shell=True)
if ret != 0:
return exit("commit aborted: python code is not flake8 compliant")
+ # C linter
+ if c_files:
+ # XXX: we should escape spaces and possibly other amenities here
+ cmd = "%s scripts/internal/clinter.py %s" % (
+ sys.executable, " ".join(c_files))
+ print(cmd)
+ ret = subprocess.call(cmd, shell=True)
+ if ret != 0:
+ return exit("commit aborted: C code didn't pass style check")
+
main()
diff --git a/scripts/internal/clinter.py b/scripts/internal/clinter.py
index e783dd68..1d4ba9b1 100755
--- a/scripts/internal/clinter.py
+++ b/scripts/internal/clinter.py
@@ -43,8 +43,6 @@ def check_line(path, line, idx, lines):
sls = s.lstrip()
if sls.startswith('//') and sls[2] != ' ' and line.strip() != '//':
warn(path, line, lineno, "no space after // comment")
- if sls.startswith("#") and sls[1:2] == " ":
- warn(path, line, lineno, "space after #")
# e.g. "if(..." after keywords
keywords = ("if", "else", "while", "do", "enum", "for")