Returns the config variables which were not found.
(config_variables)
| 24 | |
| 25 | |
| 26 | def find_config_variables(config_variables): |
| 27 | """Returns the config variables which were not found.""" |
| 28 | # Set of variables that have yet to be found. |
| 29 | variables_not_found = set(config_variables) |
| 30 | # Precompile regex for every config variable (~1.6x speedup). |
| 31 | regex_cache = {} |
| 32 | for variable_code in variables_not_found.copy(): |
| 33 | regex_cache[variable_code] = re.compile(generate_regex(variable_code)) |
| 34 | for root, _, files in os.walk("src"): |
| 35 | if not variables_not_found: |
| 36 | break |
| 37 | for file in files: |
| 38 | if not variables_not_found: |
| 39 | break |
| 40 | if file.endswith((".cpp", ".h")) and "external" not in root: |
| 41 | filepath = os.path.join(root, file) |
| 42 | with open(filepath, "r", encoding="utf-8") as f: |
| 43 | content = f.read() |
| 44 | # Only variables not yet found are searched in the remaining files (~3.6x speedup). |
| 45 | # Copy set to remove elements while iterating, which is slightly faster than collecting |
| 46 | # the elements to remove in another set and removing them after the loop. |
| 47 | for variable_code in variables_not_found.copy(): |
| 48 | if regex_cache[variable_code].search(content): |
| 49 | variables_not_found.remove(variable_code) |
| 50 | return variables_not_found |
| 51 | |
| 52 | |
| 53 | def main(): |
no test coverage detected