bpo-46541: Scan Fewer Files in generate_global_objects.py (gh-31364)

https://bugs.python.org/issue46541
This commit is contained in:
Eric Snow 2022-02-15 20:07:11 -07:00 committed by GitHub
parent 6c89589486
commit 4d8a515d19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 15 deletions

View File

@ -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: