Skip to content

Commit 26b512e

Browse files
committed
py: Get makeqstrdata.py and makeversionhdr.py running under Python 2.6.
These scripts should run under as wide a range of Python versions as possible.
1 parent 7d8edef commit 26b512e

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

py/makeqstrdata.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
"""
2+
Process raw qstr file and output qstr data with length, hash and data bytes.
3+
4+
This script works with Python 2.6, 2.7, 3.3 and 3.4.
5+
"""
6+
17
from __future__ import print_function
28

3-
import argparse
49
import re
510
import sys
611

@@ -97,17 +102,5 @@ def do_work(infiles):
97102
qlen_str = ('\\x%02x' * cfg_bytes_len) % tuple(((qlen >> (8 * i)) & 0xff) for i in range(cfg_bytes_len))
98103
print('QDEF(MP_QSTR_%s, (const byte*)"\\x%02x\\x%02x%s" "%s")' % (ident, qhash & 0xff, (qhash >> 8) & 0xff, qlen_str, qdata))
99104

100-
return True
101-
102-
def main():
103-
arg_parser = argparse.ArgumentParser(description='Process raw qstr file and output qstr data with length, hash and data bytes')
104-
arg_parser.add_argument('files', nargs='+', help='input file(s)')
105-
args = arg_parser.parse_args()
106-
107-
result = do_work(args.files)
108-
if not result:
109-
print('exiting with error code', file=sys.stderr)
110-
exit(1)
111-
112105
if __name__ == "__main__":
113-
main()
106+
do_work(sys.argv[1:])

py/makeversionhdr.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# This script works with Python 2 and 3
1+
"""
2+
Generate header file with macros defining MicroPython version info.
3+
4+
This script works with Python 2.6, 2.7, 3.3 and 3.4.
5+
"""
26

37
from __future__ import print_function
48

@@ -8,6 +12,13 @@
812
import subprocess
913

1014
def get_version_info_from_git():
15+
# Python 2.6 doesn't have check_output, so check for that
16+
try:
17+
subprocess.check_output
18+
subprocess.check_call
19+
except AttributeError:
20+
return None
21+
1122
# Note: git describe doesn't work if no tag is available
1223
try:
1324
git_tag = subprocess.check_output(["git", "describe", "--dirty", "--always"], universal_newlines=True).strip()
@@ -89,4 +100,5 @@ def make_version_header(filename):
89100
with open(filename, 'w') as f:
90101
f.write(file_data)
91102

92-
make_version_header(sys.argv[1])
103+
if __name__ == "__main__":
104+
make_version_header(sys.argv[1])

0 commit comments

Comments
 (0)