Skip to content
Merged
Show file tree
Hide file tree
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
Normalise paths, provide better UX, and add clinic-tests make target
  • Loading branch information
erlend-aasland committed Aug 8, 2023
commit a2787bce8dec10484cf441a9065f1c977908e00a
6 changes: 3 additions & 3 deletions Doc/howto/clinic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ The CLI supports the following options:

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

.. option:: --exclude EXCLUDES
.. option:: --exclude EXCLUDE

Comma-separated list of files to exclude in :option:`--make` mode.
This option has no effect unless :option:`--make` is also given.
A file to exclude in :option:`--make` mode.
This option can be given multiple times.

.. option:: FILE ...

Expand Down
4 changes: 4 additions & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,10 @@ clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c
$(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

.PHONY: clinic-tests
clinic-tests: check-clean-src $(srcdir)/Lib/test/clinic.test.c
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/clinic/clinic.py -f $(srcdir)/Lib/test/clinic.test.c

# Build the interpreter
$(BUILDPYTHON): Programs/python.o $(LINK_PYTHON_DEPS)
$(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS) $(SYSLIBS)
Expand Down
13 changes: 10 additions & 3 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5832,8 +5832,9 @@ 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, default="", metavar="EXCLUDES",
help="a comma-separated list of files to exclude in --make mode")
cmdline.add_argument("--exclude", type=str, action="append",
help=("a file to exclude in --make mode; "
"can be given multiple times"))
cmdline.add_argument("filename", metavar="FILE", type=str, nargs="*",
help="the list of files to process")
return cmdline
Expand Down Expand Up @@ -5905,7 +5906,11 @@ 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(",")]
if ns.exclude:
excludes = [os.path.join(ns.srcdir, f) for f in ns.exclude]
excludes = [os.path.normpath(f) for f in excludes]
else:
excludes = []
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 @@ -5915,7 +5920,9 @@ def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None:
if not filename.endswith(('.c', '.cpp', '.h')):
continue
path = os.path.join(root, filename)
path = os.path.normpath(path)
if path in excludes:
print("Excluding", path)
continue
if ns.verbose:
print(path)
Expand Down