From 697505721d3e4000c28901c1aebd9cfc492bcf90 Mon Sep 17 00:00:00 2001 From: Rahul Arya Date: Tue, 2 Apr 2019 14:12:15 -0700 Subject: [PATCH] Automatic Python 3.5 transpilation (#104) * Added a script that does everything automatically. * Removed some imports that don't work with 3.5. * Made json happy. * Moved okpy imports. * Fixed webserver. * Updated script. * Removed old debugging tools. --- editor/local_server.py | 10 +++++----- editor/log.py | 17 +++++------------ editor/ok_interface.py | 12 +++++------- strip_annotations | 6 ++++++ 4 files changed, 21 insertions(+), 24 deletions(-) create mode 100644 strip_annotations diff --git a/editor/local_server.py b/editor/local_server.py index 25da0a44..6c2cacbf 100644 --- a/editor/local_server.py +++ b/editor/local_server.py @@ -168,7 +168,7 @@ def handle_post_thread(self, data, path): elif path == "/save_state": global state - for key, val in json.loads(data[b"state"][0]).items(): + for key, val in json.loads(data[b"state"][0].decode("utf-8")).items(): if key == "states": if "states" not in state: state["states"] = val @@ -289,7 +289,7 @@ def start(file_args, port, open_browser): PORT = port print(f"http://localhost:{PORT}") socketserver.TCPServer.allow_reuse_address = True - with ThreadedHTTPServer(("localhost", PORT), Handler) as httpd: - if open_browser: - webbrowser.open(f"http://localhost:{PORT}", new=0, autoraise=True) - httpd.serve_forever() + httpd = ThreadedHTTPServer(("localhost", PORT), Handler) + if open_browser: + webbrowser.open(f"http://localhost:{PORT}", new=0, autoraise=True) + httpd.serve_forever() diff --git a/editor/log.py b/editor/log.py index adf52cde..6bb4e9f8 100644 --- a/editor/log.py +++ b/editor/log.py @@ -1,4 +1,4 @@ -from enum import Enum, auto +from enum import Enum from typing import List, Union, Dict, Tuple, TYPE_CHECKING from datamodel import Expression, ValueHolder, Pair, Nil, Symbol, Undefined, Promise, NilType, UndefinedType @@ -14,10 +14,10 @@ class HolderState(Enum): - UNEVALUATED = auto() - EVALUATING = auto() - EVALUATED = auto() - APPLYING = auto() + UNEVALUATED = 1 + EVALUATING = 2 + EVALUATED = 3 + APPLYING = 4 class VisualExpression: @@ -100,13 +100,6 @@ def setroot(cls, root: Holder): cls.root = root -def silence(*args): pass - - -def print_announce(message, local, root): - print(f"{message:10}: {repr(local):50} {repr(root):20}") - - def limited(f): def g(*args, **kwargs): if not logger.log_op() and not kwargs.get("force", False): diff --git a/editor/ok_interface.py b/editor/ok_interface.py index 88130fe3..4890b163 100644 --- a/editor/ok_interface.py +++ b/editor/ok_interface.py @@ -17,13 +17,6 @@ FAILURE_SETUP_FOOTER = "; Raw ok output over" -############## -# OKPY IMPORTS -# noinspection PyUnresolvedReferences -from client.api import assignment - -import logging - class PrintCapture: def __init__(self): @@ -206,6 +199,11 @@ def process_case(case): def run_tests(): + # noinspection PyUnresolvedReferences + from client.api import assignment + + import logging + LOGGING_FORMAT = '%(levelname)s | %(filename)s:%(lineno)d | %(message)s' logging.basicConfig(format=LOGGING_FORMAT) log = logging.getLogger('client') # Get top-level logger diff --git a/strip_annotations b/strip_annotations new file mode 100644 index 00000000..e12d354c --- /dev/null +++ b/strip_annotations @@ -0,0 +1,6 @@ +#!/bin/bash +cp -r ./editor ./compiled +for file in editor/*.py +do + py-backwards -i "$file" -t 3.5 -o compiled -d +done \ No newline at end of file