Skip to content

Commit

Permalink
software: remove Python 3.7 compatibility shims.
Browse files Browse the repository at this point in the history
We dropped support for Python 3.7 some time ago, so these shims were
completely unused.
  • Loading branch information
whitequark committed Oct 4, 2023
1 parent 62e27d9 commit ef1efe2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
11 changes: 2 additions & 9 deletions software/glasgow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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="<command>",
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
Expand Down
15 changes: 3 additions & 12 deletions software/glasgow/support/arepl.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit ef1efe2

Please sign in to comment.