Skip to content

Commit

Permalink
no plugins if python <3.8
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Johnson <[email protected]>
  • Loading branch information
najohnsn committed May 6, 2022
1 parent 5882154 commit eda3c10
Showing 1 changed file with 60 additions and 53 deletions.
113 changes: 60 additions & 53 deletions tnz/zti.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
import time
import traceback

from importlib.metadata import entry_points

from . import _sigx as sigx
from ._termlib import Term as curses
from ._util import session_ps_14bit
Expand Down Expand Up @@ -158,57 +156,7 @@ def __init__(self, stdin=None, stdout=None):
if self._zti is None:
Zti._zti = self

plugins = []
zti_plugins = entry_points().get("zti.commands", [])
for entry in zti_plugins:
name = entry.name
plugins.append(name)

def do_plugin(arg, entry=entry, **kwargs):
plugin = entry.load()
self.__bg_wait_end()
tb_count = self.__tb_count
plugin_goto = self.__plugin_goto
self.__plugin_goto = ""
kwargs.update(**self.__plugin_kwargs)
self.__plugin_kwargs.clear()
try:
try:
self.__tb_count = len(traceback.extract_stack())
except Exception:
pass

with ati.ati.new_program(share_sessions=True):
plugin(arg, **kwargs)

except _ZtiAbort:
pass

except Exception:
ati.say(f"{name} failed")
self.print_stack(exc=True)

else:
if plugin_goto:
self.cmdqueue.append(f"GOTO {plugin_goto}\n")

finally:
self.__tb_count = tb_count

sessions = ati.ati.sessions.split()
if sessions:
if ati.ati.session not in sessions:
ati.ati.session = sessions[0]

def help_plugin(entry=entry):
plugin = entry.load()
self.__shell_mode()
plugin("--help")

setattr(self, f"do_{name}", do_plugin)
setattr(self, f"help_{name}", help_plugin)

self.plugins = " ".join(plugins)
self.__install_plugins()

# Methods

Expand Down Expand Up @@ -1972,6 +1920,65 @@ def __endwin(self):

curses.endwin()

def __install_plugins(self):
try:
from importlib.metadata import entry_points
except ImportError: # must be Python <3.8
self.plugins = ""
return

plugins = []
zti_plugins = entry_points().get("zti.commands", [])
for entry in zti_plugins:
name = entry.name
plugins.append(name)

def do_plugin(arg, entry=entry, **kwargs):
plugin = entry.load()
self.__bg_wait_end()
tb_count = self.__tb_count
plugin_goto = self.__plugin_goto
self.__plugin_goto = ""
kwargs.update(**self.__plugin_kwargs)
self.__plugin_kwargs.clear()
try:
try:
self.__tb_count = len(traceback.extract_stack())
except Exception:
pass

with ati.ati.new_program(share_sessions=True):
plugin(arg, **kwargs)

except _ZtiAbort:
pass

except Exception:
ati.say(f"{name} failed")
self.print_stack(exc=True)

else:
if plugin_goto:
self.cmdqueue.append(f"GOTO {plugin_goto}\n")

finally:
self.__tb_count = tb_count

sessions = ati.ati.sessions.split()
if sessions:
if ati.ati.session not in sessions:
ati.ati.session = sessions[0]

def help_plugin(entry=entry):
plugin = entry.load()
self.__shell_mode()
plugin("--help")

setattr(self, f"do_{name}", do_plugin)
setattr(self, f"help_{name}", help_plugin)

self.plugins = " ".join(plugins)

def __key_data(self, tns, data):
try:
tns.key_data(data, zti=self)
Expand Down

0 comments on commit eda3c10

Please sign in to comment.