Skip to content

Commit 6f2b8d9

Browse files
committed
Merge pull request #105 from minrk/deprecate-find-connection-file
deprecate find_connection_file
2 parents a105276 + 7492c3c commit 6f2b8d9

1 file changed

Lines changed: 34 additions & 31 deletions

File tree

ipykernel/connect.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import json
99
import sys
1010
from subprocess import Popen, PIPE
11+
import warnings
1112

1213
from IPython.core.profiledir import ProfileDir
1314
from IPython.paths import get_ipython_dir
@@ -37,18 +38,9 @@ def get_connection_file(app=None):
3738

3839

3940
def find_connection_file(filename='kernel-*.json', profile=None):
40-
"""find a connection file, and return its absolute path.
41-
42-
The current working directory and the profile's security
43-
directory will be searched for the file if it is not given by
44-
absolute path.
45-
46-
If profile is unspecified, then the current running application's
47-
profile will be used, or 'default', if not run from IPython.
48-
49-
If the argument does not match an existing file, it will be interpreted as a
50-
fileglob, and the matching file in the profile's security dir with
51-
the latest access time will be used.
41+
"""DEPRECATED: find a connection file, and return its absolute path.
42+
43+
THIS FUNCION IS DEPRECATED. Use juptyer_client.find_connection_file instead.
5244
5345
Parameters
5446
----------
@@ -62,6 +54,10 @@ def find_connection_file(filename='kernel-*.json', profile=None):
6254
-------
6355
str : The absolute path of the connection file.
6456
"""
57+
58+
import warnings
59+
warnings.warn("""ipykernel.find_connection_file is deprecated, use jupyter_client.find_connection_file""",
60+
DeprecationWarning, stacklevel=2)
6561
from IPython.core.application import BaseIPythonApplication as IPApp
6662
try:
6763
# quick check for absolute path, before going through logic
@@ -85,6 +81,28 @@ def find_connection_file(filename='kernel-*.json', profile=None):
8581
return jupyter_client.find_connection_file(filename, path=['.', security_dir])
8682

8783

84+
def _find_connection_file(connection_file, profile=None):
85+
"""Return the absolute path for a connection file
86+
87+
- If nothing specified, return current Kernel's connection file
88+
- If profile specified, show deprecation warning about finding connection files in profiles
89+
- Otherwise, call jupyter_client.find_connection_file
90+
"""
91+
if connection_file is None:
92+
# get connection file from current kernel
93+
return get_connection_file()
94+
else:
95+
# connection file specified, allow shortnames:
96+
if profile is not None:
97+
warnings.warn(
98+
"Finding connection file by profile is deprecated.",
99+
DeprecationWarning, stacklevel=3,
100+
)
101+
return find_connection_file(connection_file, profile=profile)
102+
else:
103+
return jupyter_client.find_connection_file(connection_file)
104+
105+
88106
def get_connection_info(connection_file=None, unpack=False, profile=None):
89107
"""Return the connection information for the current Kernel.
90108
@@ -100,22 +118,14 @@ def get_connection_info(connection_file=None, unpack=False, profile=None):
100118
unpack : bool [default: False]
101119
if True, return the unpacked dict, otherwise just the string contents
102120
of the file.
103-
profile : str [optional]
104-
The name of the profile to use when searching for the connection file,
105-
if different from the current IPython session or 'default'.
106-
121+
profile : DEPRECATED
107122
108123
Returns
109124
-------
110125
The connection dictionary of the current kernel, as string or dict,
111126
depending on `unpack`.
112127
"""
113-
if connection_file is None:
114-
# get connection file from current kernel
115-
cf = get_connection_file()
116-
else:
117-
# connection file specified, allow shortnames:
118-
cf = find_connection_file(connection_file, profile=profile)
128+
cf = _find_connection_file(connection_file, profile)
119129

120130
with open(cf) as f:
121131
info = f.read()
@@ -144,22 +154,15 @@ def connect_qtconsole(connection_file=None, argv=None, profile=None):
144154
IPython Kernel will be used, which is only allowed from inside a kernel.
145155
argv : list [optional]
146156
Any extra args to be passed to the console.
147-
profile : str [optional]
148-
The name of the profile to use when searching for the connection file,
149-
if different from the current IPython session or 'default'.
150-
157+
profile : DEPRECATED
151158
152159
Returns
153160
-------
154161
:class:`subprocess.Popen` instance running the qtconsole frontend
155162
"""
156163
argv = [] if argv is None else argv
157164

158-
if connection_file is None:
159-
# get connection file from current kernel
160-
cf = get_connection_file()
161-
else:
162-
cf = find_connection_file(connection_file, profile=profile)
165+
cf = _find_connection_file(connection_file, profile)
163166

164167
cmd = ';'.join([
165168
"from IPython.qt.console import qtconsoleapp",

0 commit comments

Comments
 (0)