Skip to content

Commit

Permalink
Automatic Python 3.5 transpilation (#104)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
rahularya50 committed Apr 2, 2019
1 parent 676b5c9 commit 6975057
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
10 changes: 5 additions & 5 deletions editor/local_server.py
Expand Up @@ -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
Expand Down Expand Up @@ -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()
17 changes: 5 additions & 12 deletions 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
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 5 additions & 7 deletions editor/ok_interface.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions 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

0 comments on commit 6975057

Please sign in to comment.