summaryrefslogtreecommitdiff
path: root/py/genlast.py
diff options
context:
space:
mode:
Diffstat (limited to 'py/genlast.py')
-rw-r--r--py/genlast.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/py/genlast.py b/py/genlast.py
index 5b195d23e..a3ac87128 100644
--- a/py/genlast.py
+++ b/py/genlast.py
@@ -12,8 +12,9 @@ import subprocess
from makeqstrdefs import qstr_unescape, QSTRING_BLACK_LIST
re_line = re.compile(r"#[line]*\s(\d+)\s\"([^\"]+)\"", re.DOTALL)
-re_qstr = re.compile(r'MP_QSTR_[_a-zA-Z0-9]+', re.DOTALL)
-re_translate = re.compile(r'translate\(\"((?:(?=(\\?))\2.)*?)\"\)', re.DOTALL)
+re_qstr = re.compile(r"MP_QSTR_[_a-zA-Z0-9]+", re.DOTALL)
+re_translate = re.compile(r"translate\(\"((?:(?=(\\?))\2.)*?)\"\)", re.DOTALL)
+
def write_out(fname, output_dir, output):
if output:
@@ -22,13 +23,14 @@ def write_out(fname, output_dir, output):
with open(output_dir + "/" + fname + ".qstr", "w") as f:
f.write("\n".join(output) + "\n")
+
def process_file(fname, output_dir, content):
- content = content.decode('utf-8', errors='ignore')
+ content = content.decode("utf-8", errors="ignore")
output = []
for match in re_qstr.findall(content):
- name = match.replace('MP_QSTR_', '')
+ name = match.replace("MP_QSTR_", "")
if name not in QSTRING_BLACK_LIST:
- output.append('Q(' + qstr_unescape(name) + ')')
+ output.append("Q(" + qstr_unescape(name) + ")")
for match in re_translate.findall(content):
output.append('TRANSLATE("' + match[0] + '")')
@@ -36,9 +38,10 @@ def process_file(fname, output_dir, content):
def checkoutput1(args):
- info = subprocess.run(args, check=True, stdout=subprocess.PIPE, input='')
+ info = subprocess.run(args, check=True, stdout=subprocess.PIPE, input="")
return info.stdout
+
def preprocess(command, output_dir, fn):
try:
output = checkoutput1(command + [fn])
@@ -46,27 +49,28 @@ def preprocess(command, output_dir, fn):
except Exception as e:
print(e, file=sys.stderr)
+
def maybe_preprocess(command, output_dir, fn):
# Preprocess the source file if it contains "MP_QSTR", "translate",
# or if it uses enum.h (which generates "MP_QSTR" strings.
if subprocess.call(["grep", "-lqE", r"(MP_QSTR|translate|enum\.h)", fn]) == 0:
preprocess(command, output_dir, fn)
-if __name__ == '__main__':
+if __name__ == "__main__":
- idx1 = sys.argv.index('--')
- idx2 = sys.argv.index('--', idx1+1)
+ idx1 = sys.argv.index("--")
+ idx2 = sys.argv.index("--", idx1 + 1)
output_dir = sys.argv[1]
check = sys.argv[2:idx1]
- always = sys.argv[idx1+1:idx2]
- command = sys.argv[idx2+1:]
+ always = sys.argv[idx1 + 1 : idx2]
+ command = sys.argv[idx2 + 1 :]
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
# Mac and Windows use 'spawn'. Uncomment this during testing to catch spawn-specific problems on Linux.
- #multiprocessing.set_start_method("spawn")
+ # multiprocessing.set_start_method("spawn")
executor = ProcessPoolExecutor(max_workers=multiprocessing.cpu_count() + 1)
executor.map(maybe_preprocess, itertools.repeat(command), itertools.repeat(output_dir), check)
executor.map(preprocess, itertools.repeat(command), itertools.repeat(output_dir), always)