Skip to content

Commit

Permalink
assert scripts have +x bit
Browse files Browse the repository at this point in the history
Signed-off-by: Giampaolo Rodola <[email protected]>
  • Loading branch information
giampaolo committed Dec 15, 2021
1 parent ebbaae8 commit ff2f4d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
11 changes: 6 additions & 5 deletions psutil/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 3 additions & 2 deletions scripts/internal/git_pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -124,15 +125,15 @@ 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')
cmd = "%s -m isort --settings=.isort.cfg --check-only %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 'isort' style check; "
"try running 'make fix-imports'")
# C linter
if c_files:
Expand Down
10 changes: 5 additions & 5 deletions scripts/internal/winmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit ff2f4d4

Please sign in to comment.