Skip to content

Commit 445c21c

Browse files
committed
ci(check_files): expand file paths after search
Keep the full file paths around and expand them after the search. This search is still fairly rudimentary, but right now these are hard confirmations on potentially multiple files for a single name. Signed-off-by: Randolph Sapp <rs@ti.com>
1 parent c686ee2 commit 445c21c

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

bin/check_files.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
IGNORED = re.compile(r"([^_].*\.rst)|(version\.txt)")
1818

1919

20-
def get_names(base):
21-
"""Get a set of file names to check for, ignoring anything in that matches the IGNORED regex.
20+
def get_paths(base):
21+
"""Get a list of paths to check for, ignoring anything with a name that matches the IGNORED
22+
regex.
2223
2324
:param base: Pathlib path to directory to search
24-
:return: Set of string path names
25+
:return: List of pathlib paths
2526
"""
26-
files_to_check = set()
27+
files_to_check = []
2728
for file in base.glob("**/*"):
2829
if file.is_dir():
2930
continue
@@ -33,7 +34,7 @@ def get_names(base):
3334
logger.debug("Ignored: %s", name)
3435
continue
3536

36-
files_to_check.add(name)
37+
files_to_check.append(file)
3738
return files_to_check
3839

3940

@@ -67,15 +68,33 @@ def check_all(string):
6768
return False
6869

6970

71+
def get_unused_files(files):
72+
"""Get a list of unused files from a subset of files given
73+
74+
:param files: List of pathlib paths
75+
:return: List of unused pathlib paths
76+
"""
77+
names_to_check = {x.name for x in files}
78+
unused_names = []
79+
for filename in names_to_check:
80+
if check_all(filename):
81+
continue
82+
83+
logging.debug("Name not found: %s", filename)
84+
unused_names.append(filename)
85+
86+
return [x for x in files if x.name in unused_names]
87+
88+
7089
def main():
7190
"""Main CLI entrypoint"""
7291
logging.basicConfig(level=logging.INFO)
7392

74-
files_to_check = get_names(SOURCE_PATH)
75-
for filename in files_to_check:
76-
if check_all(filename):
77-
continue
78-
logging.info("File not used: %s", filename)
93+
files_to_check = get_paths(SOURCE_PATH)
94+
files_unused = get_unused_files(files_to_check)
95+
96+
for path in files_unused:
97+
logging.warning("File not used: %s", path)
7998

8099

81100
if __name__ == "__main__":

0 commit comments

Comments
 (0)