Skip to content

Commit

Permalink
pythongh-104683: Add --exclude option to Argument Clinic CLI
Browse files Browse the repository at this point in the history
Explicitly exclude Lib/test/clinic.test.c when running make clinic.
  • Loading branch information
erlend-aasland committed Aug 8, 2023
1 parent a9aeb99 commit bb701b7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Doc/howto/clinic.rst
Expand Up @@ -188,6 +188,11 @@ The CLI supports the following options:

The directory tree to walk in :option:`--make` mode.

.. option:: --exclude FILES

Comma-separated list of files to exclude in :option:`--make` mode.
This option has no effect unless :option:`--make` is also given.

.. option:: FILE ...

The list of files to process.
Expand Down
2 changes: 1 addition & 1 deletion Makefile.pre.in
Expand Up @@ -775,7 +775,7 @@ coverage-report: regen-token regen-frozen
# Run "Argument Clinic" over all source files
.PHONY: clinic
clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/clinic/clinic.py --make --srcdir $(srcdir)
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/clinic/clinic.py --make --exclude Lib/test/clinic.test.c --srcdir $(srcdir)
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/build/generate_global_objects.py

# Build the interpreter
Expand Down
@@ -0,0 +1 @@
Add ``--exclude`` option to Argument Clinic CLI.
5 changes: 5 additions & 0 deletions Tools/clinic/clinic.py
Expand Up @@ -5832,6 +5832,8 @@ def create_cli() -> argparse.ArgumentParser:
help="walk --srcdir to run over all relevant files")
cmdline.add_argument("--srcdir", type=str, default=os.curdir,
help="the directory tree to walk in --make mode")
cmdline.add_argument("--exclude", type=str,
help="a list of files to exclude --make mode")
cmdline.add_argument("filename", metavar="FILE", type=str, nargs="*",
help="the list of files to process")
return cmdline
Expand Down Expand Up @@ -5903,6 +5905,7 @@ def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None:
parser.error("can't use -o or filenames with --make")
if not ns.srcdir:
parser.error("--srcdir must not be empty with --make")
excludes = [os.path.join(ns.srcdir, f) for f in ns.exclude.split(",")]
for root, dirs, files in os.walk(ns.srcdir):
for rcs_dir in ('.svn', '.git', '.hg', 'build', 'externals'):
if rcs_dir in dirs:
Expand All @@ -5912,6 +5915,8 @@ def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None:
if not filename.endswith(('.c', '.cpp', '.h')):
continue
path = os.path.join(root, filename)
if path in excludes:
continue
if ns.verbose:
print(path)
parse_file(path, verify=not ns.force)
Expand Down

0 comments on commit bb701b7

Please sign in to comment.