cpython: a6ea34c8b413 (original) (raw)
Mercurial > cpython
changeset 105384:a6ea34c8b413
Reintroduce Python2 support in generate_opcode_h.py Issue #28821. Add also a message to show that the command did something :-) [#28821]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Mon, 28 Nov 2016 18:13:52 +0100 |
parents | 48fb6a4cb5f8 |
children | c085f2e0e1af |
files | Tools/scripts/generate_opcode_h.py |
diffstat | 1 files changed, 9 insertions(+), 3 deletions(-)[+] [-] Tools/scripts/generate_opcode_h.py 12 |
line wrap: on
line diff
--- a/Tools/scripts/generate_opcode_h.py +++ b/Tools/scripts/generate_opcode_h.py @@ -1,6 +1,8 @@
This script generates the opcode.h header file.
import sys +import tokenize + header = """/* Auto-generated by Tools/scripts/generate_opcode_h.py / #ifndef Py_OPCODE_H #define Py_OPCODE_H @@ -32,12 +34,14 @@ enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py #endif / !Py_OPCODE_H */ """ -import tokenize - def main(opcode_py, outfile='Include/opcode.h'): opcode = {}
- if hasattr(tokenize, 'open'):
fp = tokenize.open(opcode_py) # Python 3.2+[](#l1.23)
- else:
fp = open(opcode_py) # Python 2.7[](#l1.25)
- with fp: code = fp.read() exec(code, opcode) opmap = opcode['opmap'] @@ -51,6 +55,8 @@ def main(opcode_py, outfile='Include/opc ('HAVE_ARGUMENT', opcode['HAVE_ARGUMENT'])) fobj.write(footer)