From ff2f4d4c4986bffbc5348a197396e11bef057346 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Wed, 15 Dec 2021 11:46:07 +0100 Subject: [PATCH] assert scripts have +x bit Signed-off-by: Giampaolo Rodola --- psutil/tests/test_misc.py | 11 ++++++----- scripts/internal/git_pre_commit.py | 5 +++-- scripts/internal/winmake.py | 10 +++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py index fb4d0c022..0362432c5 100755 --- a/psutil/tests/test_misc.py +++ b/psutil/tests/test_misc.py @@ -720,11 +720,12 @@ def test_coverage(self): @unittest.skipIf(not POSIX, "POSIX only") def test_executable(self): - for name in os.listdir(SCRIPTS_DIR): - if name.endswith('.py'): - path = os.path.join(SCRIPTS_DIR, name) - if not stat.S_IXUSR & os.stat(path)[stat.ST_MODE]: - self.fail('%r is not executable' % path) + for root, dirs, files in os.walk(SCRIPTS_DIR): + for file in files: + if file.endswith('.py'): + path = os.path.join(root, file) + if not stat.S_IXUSR & os.stat(path)[stat.ST_MODE]: + raise self.fail('%r is not executable' % path) def test_disk_usage(self): self.assert_stdout('disk_usage.py') diff --git a/scripts/internal/git_pre_commit.py b/scripts/internal/git_pre_commit.py index dca17ffb0..c6f223bba 100755 --- a/scripts/internal/git_pre_commit.py +++ b/scripts/internal/git_pre_commit.py @@ -13,6 +13,7 @@ - assert not pdb.set_trace in code - assert no bare except clause ("except:") in code - assert "flake8" checks pass +- assert "isort" checks pass - assert C linter checks pass - abort if files were added/renamed/removed and MANIFEST.in was not updated @@ -124,7 +125,7 @@ def main(): cmd = "%s -m flake8 --config=.flake8 %s" % (PYTHON, " ".join(py_files)) ret = subprocess.call(shlex.split(cmd)) if ret != 0: - return exit("python code is not flake8 compliant; " + return exit("python code didn't pass 'flake8' style check; " "try running 'make fix-flake8'") # isort assert os.path.exists('.isort.cfg') @@ -132,7 +133,7 @@ def main(): PYTHON, " ".join(py_files)) ret = subprocess.call(shlex.split(cmd)) if ret != 0: - return exit("python code is not flake8 compliant; " + return exit("python code didn't pass 'isort' style check; " "try running 'make fix-imports'") # C linter if c_files: diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py index 4452ef099..6c4829751 100755 --- a/scripts/internal/winmake.py +++ b/scripts/internal/winmake.py @@ -156,11 +156,11 @@ def onerror(fun, path, excinfo): safe_remove(pattern) return - for root, subdirs, subfiles in os.walk('.'): + for root, dirs, files in os.walk('.'): root = os.path.normpath(root) if root.startswith('.git/'): continue - found = fnmatch.filter(subdirs if directory else subfiles, pattern) + found = fnmatch.filter(dirs if directory else files, pattern) for name in found: path = os.path.join(root, name) if directory: @@ -195,15 +195,15 @@ def onerror(fun, path, excinfo): def recursive_rm(*patterns): """Recursively remove a file or matching a list of patterns.""" - for root, subdirs, subfiles in os.walk(u'.'): + for root, dirs, files in os.walk(u'.'): root = os.path.normpath(root) if root.startswith('.git/'): continue - for file in subfiles: + for file in files: for pattern in patterns: if fnmatch.fnmatch(file, pattern): safe_remove(os.path.join(root, file)) - for dir in subdirs: + for dir in dirs: for pattern in patterns: if fnmatch.fnmatch(dir, pattern): safe_rmtree(os.path.join(root, dir))