Skip to content
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

bpo-36876: [c-analyzer tool] Add a "capi" subcommand to the c-analyzer tool. #23918

Merged
merged 17 commits into from
Dec 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add iter_header_files().
ericsnowcurrently committed Dec 24, 2020
commit acc696de733b0adf2f79d9808d07d6598d23d218
31 changes: 31 additions & 0 deletions Tools/c-analyzer/cpython/_files.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,11 @@
'Python/**/*.h',
'Parser/**/*.c',
]
LEVEL_GLOBS = {
'stable': 'Include/*.h',
'cpython': 'Include/cpython/*.h',
'internal': 'Include/internal/*.h',
}


def resolve_filename(filename):
@@ -36,3 +41,29 @@ def iter_filenames(*, search=False):
else:
globs = (os.path.join(REPO_ROOT, file) for file in GLOBS)
yield from expand_filenames(globs)


def iter_header_files(filenames=None, *, levels=None):
if not filenames:
if levels:
levels = set(levels)
if 'private' in levels:
levels.add('stable')
levels.add('cpython')
for level, glob in LEVEL_GLOBS.items():
if level in levels:
yield from expand_filenames([glob])
else:
yield from iter_files_by_suffix(INCLUDE_DIRS, ('.h',))
return

for filename in filenames:
orig = filename
filename = resolve_filename(filename)
if filename.endswith(os.path.sep):
yield from iter_files_by_suffix(INCLUDE_DIRS, ('.h',))
elif filename.endswith('.h'):
yield filename
else:
# XXX Log it and continue instead?
raise ValueError(f'expected .h file, got {orig!r}')