Skip to content

Deprecation warning when running with recent IPython #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
psychemedia opened this issue Nov 4, 2015 · 3 comments
Open

Deprecation warning when running with recent IPython #47

psychemedia opened this issue Nov 4, 2015 · 3 comments

Comments

@psychemedia
Copy link

I'm getting the following warning against IPython installed from a current pip install of jupyter:

%load_ext sql

/usr/local/lib/python3.4/dist-packages/IPython/config.py:13: ShimWarning: The `IPython.config` package has been deprecated. You should import from traitlets.config instead.
  "You should import from traitlets.config instead.", ShimWarning)
/usr/local/lib/python3.4/dist-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
  warn("IPython.utils.traitlets has moved to a top-level traitlets package.")

[Ah - I see this has been addressed in https://github.com//pull/42 - but not accepted yet?]

@EntilZha
Copy link

I am getting the same thing. Any idea when #42 is getting merged?

@debu999
Copy link

debu999 commented Dec 29, 2017

Its still the same error after 2 years. Not sure when we can expect the fix to be incorporated.

@wayne676
Copy link

import os
import sys
import json
import socket
import threading

activate_this = os.environ.get("SUBLIMEREPL_ACTIVATE_THIS", None)

turn off pager

os.environ['TERM'] = 'emacs'

if activate_this:
with open(activate_this, "r") as f:
exec(f.read(), {"file": activate_this})

try:
import IPython
IPYTHON = True
version = IPython.version_info[0]
except ImportError:
IPYTHON = False

if not IPYTHON:
# for virtualenvs w/o IPython
import code
code.InteractiveConsole().interact()

IPython 4

if version > 3:
from traitlets.config.loader import Config

all other versions

else:
from IPython.config.loader import Config

editor = "subl -w"

cfg = Config()
cfg.ZMQTerminalInteractiveShell.simple_prompt = True
cfg.InteractiveShell.readline_use = False
cfg.InteractiveShell.autoindent = False
cfg.InteractiveShell.colors = "NoColor"
cfg.InteractiveShell.editor = os.environ.get("SUBLIMEREPL_EDITOR", editor)

IPython 4.0.0

if version > 3:
try:
from jupyter_console.app import ZMQTerminalIPythonApp

    def kernel_client(zmq_shell):
        return zmq_shell.kernel_client
except ImportError:
    raise ImportError("jupyter_console required for IPython 4")

IPython 2-3

elif version > 1:
from IPython.terminal.console.app import ZMQTerminalIPythonApp

def kernel_client(zmq_shell):
    return zmq_shell.kernel_client

else:
# Ipython 1.0
from IPython.frontend.terminal.console.app import ZMQTerminalIPythonApp

def kernel_client(zmq_shell):
    return zmq_shell.kernel_manager

embedded_shell = ZMQTerminalIPythonApp(config=cfg, user_ns={})
embedded_shell.initialize()

if os.name == "nt":
# OMG what a fugly hack
import IPython.utils.io as io
io.stdout = io.IOStream(sys.stdout, fallback=io.devnull)
io.stderr = io.IOStream(sys.stderr, fallback=io.devnull)
embedded_shell.shell.show_banner() # ... my eyes, oh my eyes..

ac_port = int(os.environ.get("SUBLIMEREPL_AC_PORT", "0"))
ac_ip = os.environ.get("SUBLIMEREPL_AC_IP", "127.0.0.1")
if ac_port:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ac_ip, ac_port))

def read_netstring(s):
size = 0
while True:
ch = s.recv(1)
if ch == b':':
break
size = size * 10 + int(ch)
msg = b""
while size != 0:
msg += s.recv(size)
size -= len(msg)
ch = s.recv(1)
assert ch == b','
return msg

def send_netstring(sock, msg):
payload = b"".join([str(len(msg)).encode("ascii"), b':', msg.encode("utf-8"), b','])
sock.sendall(payload)

def complete(zmq_shell, req):
kc = kernel_client(zmq_shell)
# Ipython 4
if version > 3:
msg_id = kc.complete(req['line'], req['cursor_pos'])
# Ipython 1-3
else:
msg_id = kc.shell_channel.complete(**req)
msg = kc.shell_channel.get_msg(timeout=50)
# end new stuff
if msg['parent_header']['msg_id'] == msg_id:
return msg["content"]["matches"]
return []

def handle():
while True:
msg = read_netstring(s).decode("utf-8")
try:
req = json.loads(msg)
completions = complete(embedded_shell, req)
result = (req["text"], completions)
res = json.dumps(result)
send_netstring(s, res)
except Exception:
send_netstring(s, b"[]")

if ac_port:
t = threading.Thread(target=handle)
t.start()

embedded_shell.start()

if ac_port:
s.close()

replace your ipy_repl.py to above code @debu999

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants