diff options
author | Larry Hastings <larry@hastings.org> | 2013-11-23 22:58:45 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2013-11-23 22:58:45 (GMT) |
commit | dcd340eeebf0793ea0797ca90d72ac535db4ea78 (patch) | |
tree | 6a83a666b0cecee44d0b94dc97a339ab92a50cc5 /Tools | |
parent | ebdcb50b8a0d37af4acd7d2387eae8ff2b5f0b9b (diff) | |
download | cpython-dcd340eeebf0793ea0797ca90d72ac535db4ea78.zip cpython-dcd340eeebf0793ea0797ca90d72ac535db4ea78.tar.gz cpython-dcd340eeebf0793ea0797ca90d72ac535db4ea78.tar.bz2 |
Issue #19358: "make clinic" now runs the Argument Clinic preprocessor
over all CPython source files.
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/clinic/clinic.py | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 5b8786a..d34c3da 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -988,7 +988,6 @@ class BlockPrinter: dsl_name = block.dsl_name write = self.f.write - assert (not input) or (input.endswith('\n')) assert not ((dsl_name == None) ^ (output == None)), "you must specify dsl_name and output together, dsl_name " + repr(dsl_name) if not dsl_name: @@ -1122,12 +1121,16 @@ def parse_file(filename, *, verify=True, output=None, encoding='utf-8'): clinic = Clinic(language, verify=verify, filename=filename) with open(filename, 'r', encoding=encoding) as f: - text = clinic.parse(f.read()) + raw = f.read() + + cooked = clinic.parse(raw) + if cooked == raw: + return directory = os.path.dirname(filename) or '.' with tempfile.TemporaryDirectory(prefix="clinic", dir=directory) as tmpdir: - bytes = text.encode(encoding) + bytes = cooked.encode(encoding) tmpfilename = os.path.join(tmpdir, os.path.basename(filename)) with open(tmpfilename, "wb") as f: f.write(bytes) @@ -2619,6 +2622,7 @@ def main(argv): cmdline.add_argument("-f", "--force", action='store_true') cmdline.add_argument("-o", "--output", type=str) cmdline.add_argument("--converters", action='store_true') + cmdline.add_argument("--make", action='store_true') cmdline.add_argument("filename", type=str, nargs="*") ns = cmdline.parse_args(argv) @@ -2697,6 +2701,23 @@ def main(argv): print("All return converters also accept (doc_default=None).") sys.exit(0) + if ns.make: + if ns.output or ns.filename: + print("Usage error: can't use -o or filenames with --make.") + print() + cmdline.print_usage() + sys.exit(-1) + for root, dirs, files in os.walk('.'): + for rcs_dir in ('.svn', '.git', '.hg'): + if rcs_dir in dirs: + dirs.remove(rcs_dir) + for filename in files: + if not filename.endswith('.c'): + continue + path = os.path.join(root, filename) + parse_file(path, verify=not ns.force) + return + if not ns.filename: cmdline.print_usage() sys.exit(-1) |