diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2022-02-16 03:07:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-16 03:07:11 (GMT) |
commit | 4d8a515d193a4c9f3844704f974ddb870d7ee383 (patch) | |
tree | 1b193201f0e92b1f2f1954dda16fb9067b1af30a | |
parent | 6c8958948666403f2370ca7b4c0a52b2010ec16d (diff) | |
download | cpython-4d8a515d193a4c9f3844704f974ddb870d7ee383.zip cpython-4d8a515d193a4c9f3844704f974ddb870d7ee383.tar.gz cpython-4d8a515d193a4c9f3844704f974ddb870d7ee383.tar.bz2 |
bpo-46541: Scan Fewer Files in generate_global_objects.py (gh-31364)
https://bugs.python.org/issue46541
-rw-r--r-- | Tools/scripts/generate_global_objects.py | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index 7a5f42f..bad7865 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -100,24 +100,28 @@ IDENTIFIERS = [ ####################################### # helpers +def iter_files(): + for name in ('Modules', 'Objects', 'Parser', 'PC', 'Programs', 'Python'): + root = os.path.join(ROOT, name) + for dirname, _, files in os.walk(root): + for name in files: + if not name.endswith(('.c', '.h')): + continue + yield os.path.join(dirname, name) + + def iter_global_strings(): id_regex = re.compile(r'\b_Py_ID\((\w+)\)') str_regex = re.compile(r'\b_Py_DECLARE_STR\((\w+), "(.*?)"\)') - for dirname, _, files in os.walk(ROOT): - if os.path.relpath(dirname, ROOT).startswith('Include'): - continue - for name in files: - if not name.endswith(('.c', '.h')): - continue - filename = os.path.join(dirname, name) - with open(os.path.join(filename), encoding='utf-8') as infile: - for lno, line in enumerate(infile, 1): - for m in id_regex.finditer(line): - identifier, = m.groups() - yield identifier, None, filename, lno, line - for m in str_regex.finditer(line): - varname, string = m.groups() - yield varname, string, filename, lno, line + for filename in iter_files(): + with open(filename, encoding='utf-8') as infile: + for lno, line in enumerate(infile, 1): + for m in id_regex.finditer(line): + identifier, = m.groups() + yield identifier, None, filename, lno, line + for m in str_regex.finditer(line): + varname, string = m.groups() + yield varname, string, filename, lno, line def iter_to_marker(lines, marker): for line in lines: |