diff options
Diffstat (limited to 'Tools/scripts')
| -rwxr-xr-x | Tools/scripts/diff.py | 34 | ||||
| -rw-r--r-- | Tools/scripts/dutree.doc | 6 | ||||
| -rwxr-xr-x | Tools/scripts/eptags.py | 2 | ||||
| -rwxr-xr-x | Tools/scripts/find_recursionlimit.py | 4 | ||||
| -rwxr-xr-x | Tools/scripts/findnocoding.py | 2 | ||||
| -rwxr-xr-x | Tools/scripts/fixcid.py | 52 | ||||
| -rw-r--r-- | Tools/scripts/generate_opcode_h.py | 54 | ||||
| -rw-r--r-- | Tools/scripts/run_tests.py | 8 | ||||
| -rw-r--r-- | Tools/scripts/win_add2path.py | 3 |
9 files changed, 113 insertions, 52 deletions
diff --git a/Tools/scripts/diff.py b/Tools/scripts/diff.py index 8be527f..9720a43 100755 --- a/Tools/scripts/diff.py +++ b/Tools/scripts/diff.py @@ -8,7 +8,7 @@ """ -import sys, os, time, difflib, optparse +import sys, os, time, difflib, argparse from datetime import datetime, timezone def file_mtime(path): @@ -18,23 +18,25 @@ def file_mtime(path): def main(): - usage = "usage: %prog [options] fromfile tofile" - parser = optparse.OptionParser(usage) - parser.add_option("-c", action="store_true", default=False, help='Produce a context format diff (default)') - parser.add_option("-u", action="store_true", default=False, help='Produce a unified format diff') - parser.add_option("-m", action="store_true", default=False, help='Produce HTML side by side diff (can use -c and -l in conjunction)') - parser.add_option("-n", action="store_true", default=False, help='Produce a ndiff format diff') - parser.add_option("-l", "--lines", type="int", default=3, help='Set number of context lines (default 3)') - (options, args) = parser.parse_args() - - if len(args) == 0: - parser.print_help() - sys.exit(1) - if len(args) != 2: - parser.error("need to specify both a fromfile and tofile") + parser = argparse.ArgumentParser() + parser.add_argument('-c', action='store_true', default=False, + help='Produce a context format diff (default)') + parser.add_argument('-u', action='store_true', default=False, + help='Produce a unified format diff') + parser.add_argument('-m', action='store_true', default=False, + help='Produce HTML side by side diff ' + '(can use -c and -l in conjunction)') + parser.add_argument('-n', action='store_true', default=False, + help='Produce a ndiff format diff') + parser.add_argument('-l', '--lines', type=int, default=3, + help='Set number of context lines (default 3)') + parser.add_argument('fromfile') + parser.add_argument('tofile') + options = parser.parse_args() n = options.lines - fromfile, tofile = args + fromfile = options.fromfile + tofile = options.tofile fromdate = file_mtime(fromfile) todate = file_mtime(tofile) diff --git a/Tools/scripts/dutree.doc b/Tools/scripts/dutree.doc index 2a09426..97bd2e2 100644 --- a/Tools/scripts/dutree.doc +++ b/Tools/scripts/dutree.doc @@ -34,13 +34,13 @@ sometimes it's not worth it. I actually wrote a C program the other day : | 1 sm.bak At first I thought I could just keep one local list around -at once, but this seems inherently recursive. Which means +at once, but this seems inherently recursive. Which means I need an real recursive data structure. Maybe you could do it with one of the %assoc arrays Larry uses in the begat programs, but I broke down and got dirty. I think the hardest -part was matching Felix's desired output exactly. It's not +part was matching Felix's desired output exactly. It's not blazingly fast: I should probably inline the &childof routine, -but it *was* faster to write than I could have written the +but it *was* faster to write than I could have written the equivalent C program. diff --git a/Tools/scripts/eptags.py b/Tools/scripts/eptags.py index 671ff11..401ac7e 100755 --- a/Tools/scripts/eptags.py +++ b/Tools/scripts/eptags.py @@ -25,7 +25,7 @@ def treat_file(filename, outfp): """Append tags found in file named 'filename' to the open file 'outfp'""" try: fp = open(filename, 'r') - except: + except OSError: sys.stderr.write('Cannot open %s\n'%filename) return charno = 0 diff --git a/Tools/scripts/find_recursionlimit.py b/Tools/scripts/find_recursionlimit.py index 1171146..b2842a6 100755 --- a/Tools/scripts/find_recursionlimit.py +++ b/Tools/scripts/find_recursionlimit.py @@ -92,7 +92,7 @@ def test_cpickle(_cache={}): def test_compiler_recursion(): # The compiler uses a scaling factor to support additional levels # of recursion. This is a sanity check of that scaling to ensure - # it still raises RuntimeError even at higher recursion limits + # it still raises RecursionError even at higher recursion limits compile("()" * (10 * sys.getrecursionlimit()), "<single>", "single") def check_limit(n, test_func_name): @@ -107,7 +107,7 @@ def check_limit(n, test_func_name): # AttributeError can be raised because of the way e.g. PyDict_GetItem() # silences all exceptions and returns NULL, which is usually interpreted # as "missing attribute". - except (RuntimeError, AttributeError): + except (RecursionError, AttributeError): pass else: print("Yikes!") diff --git a/Tools/scripts/findnocoding.py b/Tools/scripts/findnocoding.py index 5f3795e..6c16b1c 100755 --- a/Tools/scripts/findnocoding.py +++ b/Tools/scripts/findnocoding.py @@ -32,7 +32,7 @@ except ImportError: "no sophisticated Python source file search will be done.", file=sys.stderr) -decl_re = re.compile(rb'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)') +decl_re = re.compile(rb'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)') blank_re = re.compile(rb'^[ \t\f]*(?:[#\r\n]|$)') def get_declaration(line): diff --git a/Tools/scripts/fixcid.py b/Tools/scripts/fixcid.py index 1e4c428..c66a0ac 100755 --- a/Tools/scripts/fixcid.py +++ b/Tools/scripts/fixcid.py @@ -88,9 +88,9 @@ def main(): sys.exit(bad) # Change this regular expression to select a different set of files -Wanted = '^[a-zA-Z0-9_]+\.[ch]$' +Wanted = r'^[a-zA-Z0-9_]+\.[ch]$' def wanted(name): - return re.match(Wanted, name) >= 0 + return re.match(Wanted, name) def recursedown(dirname): dbg('recursedown(%r)\n' % (dirname,)) @@ -168,6 +168,7 @@ def fix(filename): if filename == '-': return 0 # Done in filter mode f.close() if not g: return 0 # No changes + g.close() # Finishing touch -- move files @@ -193,21 +194,21 @@ def fix(filename): # Tokenizing ANSI C (partly) -Identifier = '\(struct \)?[a-zA-Z_][a-zA-Z0-9_]+' -String = '"\([^\n\\"]\|\\\\.\)*"' -Char = '\'\([^\n\\\']\|\\\\.\)*\'' -CommentStart = '/\*' -CommentEnd = '\*/' +Identifier = '(struct )?[a-zA-Z_][a-zA-Z0-9_]+' +String = r'"([^\n\\"]|\\.)*"' +Char = r"'([^\n\\']|\\.)*'" +CommentStart = r'/\*' +CommentEnd = r'\*/' Hexnumber = '0[xX][0-9a-fA-F]*[uUlL]*' Octnumber = '0[0-7]*[uUlL]*' Decnumber = '[1-9][0-9]*[uUlL]*' -Intnumber = Hexnumber + '\|' + Octnumber + '\|' + Decnumber +Intnumber = Hexnumber + '|' + Octnumber + '|' + Decnumber Exponent = '[eE][-+]?[0-9]+' -Pointfloat = '\([0-9]+\.[0-9]*\|\.[0-9]+\)\(' + Exponent + '\)?' +Pointfloat = r'([0-9]+\.[0-9]*|\.[0-9]+)(' + Exponent + r')?' Expfloat = '[0-9]+' + Exponent -Floatnumber = Pointfloat + '\|' + Expfloat -Number = Floatnumber + '\|' + Intnumber +Floatnumber = Pointfloat + '|' + Expfloat +Number = Floatnumber + '|' + Intnumber # Anything else is an operator -- don't list this explicitly because of '/*' @@ -225,15 +226,16 @@ def initfixline(): def fixline(line): global Program -## print '-->', repr(line) +## print('-->', repr(line)) i = 0 while i < len(line): - i = Program.search(line, i) - if i < 0: break - found = Program.group(0) -## if Program is InsideCommentProgram: print '...', -## else: print ' ', -## print found + match = Program.search(line, i) + if match is None: break + i = match.start() + found = match.group(0) +## if Program is InsideCommentProgram: print(end='... ') +## else: print(end=' ') +## print(found) if len(found) == 2: if found == '/*': Program = InsideCommentProgram @@ -247,15 +249,15 @@ def fixline(line): print('Found in comment:', found) i = i + n continue - if NotInComment.has_key(found): -## print 'Ignored in comment:', -## print found, '-->', subst -## print 'Line:', line, + if found in NotInComment: +## print(end='Ignored in comment: ') +## print(found, '-->', subst) +## print('Line:', line, end='') subst = found ## else: -## print 'Substituting in comment:', -## print found, '-->', subst -## print 'Line:', line, +## print(end='Substituting in comment: ') +## print(found, '-->', subst) +## print('Line:', line, end='') line = line[:i] + subst + line[i+n:] n = len(subst) i = i + n diff --git a/Tools/scripts/generate_opcode_h.py b/Tools/scripts/generate_opcode_h.py new file mode 100644 index 0000000..c62f9a5 --- /dev/null +++ b/Tools/scripts/generate_opcode_h.py @@ -0,0 +1,54 @@ +# This script generates the opcode.h header file. + +from __future__ import with_statement + +import sys +header = """/* Auto-generated by Tools/scripts/generate_opcode_h.py */ +#ifndef Py_OPCODE_H +#define Py_OPCODE_H +#ifdef __cplusplus +extern "C" { +#endif + + + /* Instruction opcodes for compiled code */ +""" + +footer = """ +/* EXCEPT_HANDLER is a special, implicit block type which is created when + entering an except handler. It is not an opcode but we define it here + as we want it to be available to both frameobject.c and ceval.c, while + remaining private.*/ +#define EXCEPT_HANDLER 257 + + +enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, + PyCmp_GT=Py_GT, PyCmp_GE=Py_GE, PyCmp_IN, PyCmp_NOT_IN, + PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD}; + +#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT) + +#ifdef __cplusplus +} +#endif +#endif /* !Py_OPCODE_H */ +""" + + +def main(opcode_py, outfile='Include/opcode.h'): + opcode = {} + exec(open(opcode_py).read(), opcode) + opmap = opcode['opmap'] + with open(outfile, 'w') as fobj: + fobj.write(header) + for name in opcode['opname']: + if name in opmap: + fobj.write("#define %-23s %3s\n" % (name, opmap[name])) + if name == 'POP_EXCEPT': # Special entry for HAVE_ARGUMENT + fobj.write("#define %-23s %3d\n" % + ('HAVE_ARGUMENT', opcode['HAVE_ARGUMENT'])) + fobj.write(footer) + + +if __name__ == '__main__': + main(sys.argv[1], sys.argv[2]) diff --git a/Tools/scripts/run_tests.py b/Tools/scripts/run_tests.py index a6c5da3..b582e13 100644 --- a/Tools/scripts/run_tests.py +++ b/Tools/scripts/run_tests.py @@ -33,8 +33,6 @@ def main(regrtest_args): # Allow user-specified interpreter options to override our defaults. args.extend(test.support.args_from_interpreter_flags()) - # Workaround for issue #20355 - os.environ.pop("PYTHONWARNINGS", None) # Workaround for issue #20361 args.extend(['-W', 'error::BytesWarning']) @@ -50,7 +48,11 @@ def main(regrtest_args): args.extend(['-u', 'all,-largefile,-audio,-gui']) args.extend(regrtest_args) print(' '.join(args)) - os.execv(sys.executable, args) + if sys.platform == 'win32': + from subprocess import call + sys.exit(call(args)) + else: + os.execv(sys.executable, args) if __name__ == '__main__': diff --git a/Tools/scripts/win_add2path.py b/Tools/scripts/win_add2path.py index c85bea5..1c9aedc 100644 --- a/Tools/scripts/win_add2path.py +++ b/Tools/scripts/win_add2path.py @@ -22,7 +22,8 @@ def modify(): scripts = os.path.join(pythonpath, "Scripts") appdata = os.environ["APPDATA"] if hasattr(site, "USER_SITE"): - userpath = site.USER_SITE.replace(appdata, "%APPDATA%") + usersite = site.USER_SITE.replace(appdata, "%APPDATA%") + userpath = os.path.dirname(usersite) userscripts = os.path.join(userpath, "Scripts") else: userscripts = None |
