-
Notifications
You must be signed in to change notification settings - Fork 78
ci(check-files): replace bash with faster python #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
praneethbajjuri
merged 1 commit into
TexasInstruments:master
from
StaticRocket:bugfix/check-files
Oct 24, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| """Tool to check that all files are being used | ||
|
|
||
| SPDX-License-Identifier: MIT | ||
| Copyright (C) 2025 Texas Instruments Incorporated - https://www.ti.com | ||
| """ | ||
|
|
||
| import logging | ||
| import re | ||
| from pathlib import Path | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| SOURCE_PATH = Path("source/") | ||
| RST_SOURCE = set(SOURCE_PATH.glob("**/*.rst")) | ||
| IGNORED = re.compile(r"([^_].*\.rst)|(version\.txt)") | ||
|
|
||
|
|
||
| def get_names(base): | ||
| """Get a set of file names to check for, ignoring anything in that matches the IGNORED regex. | ||
|
|
||
| :param base: Pathlib path to directory to search | ||
| :return: Set of string path names | ||
| """ | ||
| files_to_check = set() | ||
| for file in base.glob("**/*"): | ||
| if file.is_dir(): | ||
| continue | ||
|
|
||
| name = file.name | ||
| if IGNORED.match(name): | ||
| logger.debug("Ignored: %s", name) | ||
| continue | ||
|
|
||
| files_to_check.add(name) | ||
| return files_to_check | ||
|
|
||
|
|
||
| def check_file(string, file): | ||
| """Check to see if the given string appears in the file. | ||
|
|
||
| :param string: String to look up | ||
| :param file: Pathlib path to file | ||
| :return: Boolean based on presence of string | ||
| """ | ||
| pattern = re.compile(re.escape(string)) | ||
| text = file.read_text(encoding="utf-8") | ||
| for _ in pattern.finditer(text): | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def check_all(string): | ||
| """Use an scan for any matches in RST_SOURCE files. Do not look for matches in the file itself. | ||
| That last bit is particularly relevant for RST files that exist to be included in other files. | ||
|
|
||
| :param string: String to look up | ||
| :return: Boolean based on presence of string in any other files | ||
| """ | ||
| for file in RST_SOURCE: | ||
| if file == string: | ||
| continue | ||
|
|
||
| if check_file(string, file): | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def main(): | ||
| """Main CLI entrypoint""" | ||
| logging.basicConfig(level=logging.INFO) | ||
|
|
||
| files_to_check = get_names(SOURCE_PATH) | ||
| for filename in files_to_check: | ||
| if check_all(filename): | ||
| continue | ||
| logging.info("File not used: %s", filename) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.