diff --git a/software/glasgow/cli.py b/software/glasgow/cli.py index 2178de40a..e8e43ac04 100644 --- a/software/glasgow/cli.py +++ b/software/glasgow/cli.py @@ -11,10 +11,6 @@ import importlib.metadata from vcd import VCDWriter from datetime import datetime -try: - from ast import PyCF_ALLOW_TOP_LEVEL_AWAIT # Python 3.8+ -except ImportError: - PyCF_ALLOW_TOP_LEVEL_AWAIT = 0 # Python 3.7- from fx2 import FX2Config, FX2Device, FX2DeviceError, VID_CYPRESS, PID_FX2 from fx2.format import input_data, diff_data @@ -490,9 +486,6 @@ async def _main(): args = get_argparser().parse_args() create_logger(args) - if sys.version_info < (3, 8) and os.name == "nt": - logger.warn("Ctrl+C on Windows is only supported on Python 3.8+") - device = None try: if args.action not in ("build", "test", "tool", "factory", "list"): @@ -637,10 +630,10 @@ async def run_applet(): elif args.action == "script": if args.script_file: code = compile(args.script_file.read(), filename=args.script_file.name, - mode="exec", flags=PyCF_ALLOW_TOP_LEVEL_AWAIT) + mode="exec", flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT) else: code = compile(args.script_cmd, filename="", - mode="exec", flags=PyCF_ALLOW_TOP_LEVEL_AWAIT) + mode="exec", flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT) future = eval(code, {"iface":iface, "device":device, "args":args}) if future is not None: await future diff --git a/software/glasgow/support/arepl.py b/software/glasgow/support/arepl.py index f93daa8b3..41a91fe49 100644 --- a/software/glasgow/support/arepl.py +++ b/software/glasgow/support/arepl.py @@ -1,14 +1,11 @@ import os import sys +import ast import codeop import signal import asyncio import builtins import traceback -try: - from ast import PyCF_ALLOW_TOP_LEVEL_AWAIT # Python 3.8+ -except ImportError: - PyCF_ALLOW_TOP_LEVEL_AWAIT = 0 # Python 3.7- try: import readline import rlcompleter @@ -25,7 +22,7 @@ def __init__(self, locals, *, run_callback=None): self._buffer = [] self._compile = codeop.CommandCompiler() - self._compile.compiler.flags |= PyCF_ALLOW_TOP_LEVEL_AWAIT + self._compile.compiler.flags |= ast.PyCF_ALLOW_TOP_LEVEL_AWAIT if readline is not None: self._init_readline() @@ -48,13 +45,7 @@ def _save_readline(self): async def _run_code(self, code): try: future = eval(code, self.locals) - if PyCF_ALLOW_TOP_LEVEL_AWAIT == 0: # compat shim - future = getattr(builtins, "_", None) - if asyncio.iscoroutine(future): - result = await future - builtins._ = result - print(repr(result)) - elif asyncio.iscoroutine(future): + if asyncio.iscoroutine(future): await future if self.run_callback is not None: await self.run_callback()