Skip to content

Commit dcd340e

Browse files
committed
Issue #19358: "make clinic" now runs the Argument Clinic preprocessor
over all CPython source files.
1 parent ebdcb50 commit dcd340e

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

Makefile.pre.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,12 @@ coverage-report:
526526
: # build lcov report
527527
$(MAKE) coverage-lcov
528528

529+
# Run "Argument Clinic" over all source files
530+
# (depends on python having already been built)
531+
.PHONY=clinic
532+
clinic: $(BUILDPYTHON)
533+
$(RUNSHARED) $(PYTHON_FOR_BUILD) ./Tools/clinic/clinic.py --make
534+
529535
# Build the interpreter
530536
$(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
531537
$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Projected release date: 2013-11-24
99

1010
Core and Builtins
1111
-----------------
12+
1213
- Use the repr of a module name in more places in import, especially
1314
exceptions.
1415

@@ -66,6 +67,7 @@ Core and Builtins
6667

6768
Library
6869
-------
70+
6971
- Issue #19722: Added opcode.stack_effect(), which
7072
computes the stack effect of bytecode instructions.
7173

@@ -403,6 +405,9 @@ Documentation
403405
Build
404406
-----
405407

408+
- Issue #19358: "make clinic" now runs the Argument Clinic preprocessor
409+
over all CPython source files.
410+
406411
- Update SQLite to 3.8.1, xz to 5.0.5, and Tcl/Tk to 8.6.1 on Windows.
407412

408413
- Issue #16632: Enable DEP and ASLR on Windows.
@@ -449,6 +454,7 @@ Build
449454

450455
Tools/Demos
451456
-----------
457+
452458
- Issue #19730: Argument Clinic now supports all the existing PyArg
453459
"format units" as legacy converters, as well as two new features:
454460
"self converters" and the "version" directive.

Tools/clinic/clinic.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,6 @@ def print_block(self, block):
988988
dsl_name = block.dsl_name
989989
write = self.f.write
990990

991-
assert (not input) or (input.endswith('\n'))
992991
assert not ((dsl_name == None) ^ (output == None)), "you must specify dsl_name and output together, dsl_name " + repr(dsl_name)
993992

994993
if not dsl_name:
@@ -1122,12 +1121,16 @@ def parse_file(filename, *, verify=True, output=None, encoding='utf-8'):
11221121
clinic = Clinic(language, verify=verify, filename=filename)
11231122

11241123
with open(filename, 'r', encoding=encoding) as f:
1125-
text = clinic.parse(f.read())
1124+
raw = f.read()
1125+
1126+
cooked = clinic.parse(raw)
1127+
if cooked == raw:
1128+
return
11261129

11271130
directory = os.path.dirname(filename) or '.'
11281131

11291132
with tempfile.TemporaryDirectory(prefix="clinic", dir=directory) as tmpdir:
1130-
bytes = text.encode(encoding)
1133+
bytes = cooked.encode(encoding)
11311134
tmpfilename = os.path.join(tmpdir, os.path.basename(filename))
11321135
with open(tmpfilename, "wb") as f:
11331136
f.write(bytes)
@@ -2619,6 +2622,7 @@ def main(argv):
26192622
cmdline.add_argument("-f", "--force", action='store_true')
26202623
cmdline.add_argument("-o", "--output", type=str)
26212624
cmdline.add_argument("--converters", action='store_true')
2625+
cmdline.add_argument("--make", action='store_true')
26222626
cmdline.add_argument("filename", type=str, nargs="*")
26232627
ns = cmdline.parse_args(argv)
26242628

@@ -2697,6 +2701,23 @@ def main(argv):
26972701
print("All return converters also accept (doc_default=None).")
26982702
sys.exit(0)
26992703

2704+
if ns.make:
2705+
if ns.output or ns.filename:
2706+
print("Usage error: can't use -o or filenames with --make.")
2707+
print()
2708+
cmdline.print_usage()
2709+
sys.exit(-1)
2710+
for root, dirs, files in os.walk('.'):
2711+
for rcs_dir in ('.svn', '.git', '.hg'):
2712+
if rcs_dir in dirs:
2713+
dirs.remove(rcs_dir)
2714+
for filename in files:
2715+
if not filename.endswith('.c'):
2716+
continue
2717+
path = os.path.join(root, filename)
2718+
parse_file(path, verify=not ns.force)
2719+
return
2720+
27002721
if not ns.filename:
27012722
cmdline.print_usage()
27022723
sys.exit(-1)

0 commit comments

Comments
 (0)