Skip to content

Commit

Permalink
update to better support newer versions of IPYTHON (why can't they al…
Browse files Browse the repository at this point in the history
…l just get along?)
  • Loading branch information
atlas0fd00m committed Aug 28, 2023
1 parent 497f891 commit 6e17f4e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 36 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0
2.0.1
80 changes: 46 additions & 34 deletions rflib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,52 +216,64 @@ def interactive(idx=0, DongleClass=RfCat, intro='', safemode=False):
lcls = locals()
interact(lcls, gbls)

def interact(lcls, gbls):
shellexception = None
STYPE_NONE = 0
STYPE_IPYTHON = 1
STYPE_IPYTHON811P = 2
STYPE_CODE_INTERACT = 3

def interact(lcls, gbls, intro=""):
shelltype = STYPE_NONE
try:
import IPython
if IPython.core.getipython.get_ipython() is None:
ipsh = IPython.terminal.embed.InteractiveShellEmbed.instance()
else:
ipsh = IPython.terminal.embed.InteractiveShellEmbed()

ipsh.user_global_ns.update(gbls)
ipsh.user_global_ns.update(lcls)
ipsh.autocall = 2 # don't require parenthesis around *everything*. be smart!
ipsh.mainloop()
except ImportError as e:
shellexception = e
from IPython.terminal.embed import embed
print(intro)
shelltype = STYPE_IPYTHON811P

if shellexception:
except ImportError as e:
try:
import IPython.Shell
ipsh = IPython.Shell.IPShell(argv=[''], user_ns=lcls, user_global_ns=gbls)
ipsh.mainloop()
print(intro)
shelltype = STYPE_IPYTHON

except ImportError as e:
shellexception = e

if shellexception:
try:
import IPython
if IPython.core.getipython.get_ipython() is None:
ipsh = IPython.terminal.embed.InteractiveShellEmbed.instance()
else:
ipsh = IPython.terminal.embed.InteractiveShellEmbed()
ipsh.user_global_ns.update(gbls)
ipsh.user_global_ns.update(lcls)
ipsh.autocall = 2 # don't require parenthesis around *everything*. be smart!

ipsh.mainloop()
except ImportError as e:
shellexception = e
try:
from IPython.terminal.interactiveshell import TerminalInteractiveShell
ipsh = TerminalInteractiveShell()
ipsh.user_global_ns.update(gbls)
ipsh.user_global_ns.update(lcls)
ipsh.autocall = 2 # don't require parenthesis around *everything*. be smart!
shelltype = STYPE_IPYTHON
print(intro)

except ImportError as e:
try:
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
ipsh = TerminalInteractiveShell()
ipsh.user_global_ns.update(gbls)
ipsh.user_global_ns.update(lcls)
ipsh.autocall = 2 # don't require parenthesis around *everything*. be smart!
shelltype = STYPE_IPYTHON

print(intro)
except ImportError as e:
print(e)
shell = code.InteractiveConsole(gbls)
shelltype = STYPE_IPYTHON
print(intro)

if shelltype == STYPE_IPYTHON811P:
embed()

elif shelltype == STYPE_IPYTHON:
ipsh.mainloop()

if shellexception:
elif shelltype == STYPE_CODE_INTERACT:
print("falling back to straight Python... (%r)" % shellexception)
shell = code.InteractiveConsole(gbls)
shell.interact()

else:
print("SORRY, NO INTERACTIVE OPTIONS AVAILABLE!! wtfo?")


if __name__ == "__main__":
idx = 0
Expand Down
2 changes: 1 addition & 1 deletion rflib/rflib_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
RFLIB_VERSION=629
RFLIB_VERSION=630

0 comments on commit 6e17f4e

Please sign in to comment.