Skip to content

Commit 5d3b212

Browse files
author
Przemyslaw Kudriawcew
committed
Add avoiding dirs from with open
1 parent 46d621b commit 5d3b212

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

pre_commit_hooks/check_static_path.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import os
23
import subprocess
34
import sys
45
import platform
@@ -19,6 +20,9 @@ def extractMatches(text, pattern):
1920

2021
def findStringInRangeForFile(filename, keywords, changes_range):
2122
results = []
23+
if os.path.isdir(filename):
24+
# Skip the directory and move on to the next file
25+
return results
2226
with open(filename, "r") as f:
2327
lines = f.readlines()
2428
for i, line in enumerate(lines):
@@ -46,6 +50,8 @@ def findStringInRange(filenames, keywords):
4650
return results
4751

4852
def findStringInFile(filename, keywords, retval):
53+
if os.path.isdir(filename):
54+
return retval
4955
with open(filename, 'r') as f:
5056
lines = f.readlines()
5157
for line_num, line in enumerate(lines, start=1):
@@ -95,4 +101,4 @@ def main(argv: Union[Sequence[str], None] = None) -> int:
95101
return retval
96102

97103
if __name__ == '__main__':
98-
raise SystemExit(main())
104+
raise SystemExit(main())

0 commit comments

Comments
 (0)