Skip to content

Commit d2ae127

Browse files
committed
Remove some of ipython_genutils no-op.
ipython_genutils is complicated to package on some linux distro because of nose, and in general not useful as it mostly offered python 2/3 compat layer. Goal always has been to remove any usage of ipython_genutils
1 parent 15d3782 commit d2ae127

File tree

12 files changed

+31
-39
lines changed

12 files changed

+31
-39
lines changed

jupyter_server/base/handlers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
from traitlets.config import Application
2828
from ipython_genutils.path import filefind
29-
from ipython_genutils.py3compat import string_types
3029

3130
from jupyter_core.paths import is_hidden
3231
import jupyter_server
@@ -785,7 +784,7 @@ def set_headers(self):
785784
def initialize(self, path, default_filename=None, no_cache_paths=None):
786785
self.no_cache_paths = no_cache_paths or []
787786

788-
if isinstance(path, string_types):
787+
if isinstance(path, str):
789788
path = [path]
790789

791790
self.root = tuple(

jupyter_server/serverapp.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
Any, Dict, Unicode, Integer, List, Bool, Bytes, Instance,
9696
TraitError, Type, Float, observe, default, validate
9797
)
98-
from ipython_genutils import py3compat
9998
from jupyter_core.paths import jupyter_runtime_dir, jupyter_path
10099
from jupyter_server._sysinfo import get_sys_info
101100

@@ -201,7 +200,7 @@ def init_settings(self, jupyter_app, kernel_manager, contents_manager,
201200
"template_path",
202201
jupyter_app.template_file_path,
203202
)
204-
if isinstance(_template_path, py3compat.string_types):
203+
if isinstance(_template_path, str):
205204
_template_path = (_template_path,)
206205
template_path = [os.path.expanduser(path) for path in _template_path]
207206

@@ -229,7 +228,7 @@ def init_settings(self, jupyter_app, kernel_manager, contents_manager,
229228
now = utcnow()
230229

231230
root_dir = contents_manager.root_dir
232-
home = py3compat.str_to_unicode(os.path.expanduser('~'), encoding=sys.getfilesystemencoding())
231+
home = os.path.expanduser("~")
233232
if root_dir.startswith(home + os.path.sep):
234233
# collapse $HOME to ~
235234
root_dir = '~' + root_dir[len(home):]
@@ -953,8 +952,6 @@ def _default_allow_remote(self):
953952
# Address is a hostname
954953
for info in socket.getaddrinfo(self.ip, self.port, 0, socket.SOCK_STREAM):
955954
addr = info[4][0]
956-
if not py3compat.PY3:
957-
addr = addr.decode('ascii')
958955

959956
try:
960957
parsed = ipaddress.ip_address(addr.split('%')[0])
@@ -1281,7 +1278,7 @@ def _default_root_dir(self):
12811278
self._root_dir_set = True
12821279
return os.path.dirname(os.path.abspath(self.file_to_run))
12831280
else:
1284-
return py3compat.getcwd()
1281+
return os.getcwd()
12851282

12861283
@validate('root_dir')
12871284
def _root_dir_validate(self, proposal):

jupyter_server/services/config/handlers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import errno
99
from tornado import web
1010

11-
from ipython_genutils.py3compat import PY3
1211
from ...base.handlers import APIHandler
1312

1413
class ConfigHandler(APIHandler):

jupyter_server/services/contents/filecheckpoints.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from anyio import run_sync_in_worker_thread
1818
from jupyter_core.utils import ensure_dir_exists
19-
from ipython_genutils.py3compat import getcwd
2019
from traitlets import Unicode
2120

2221
from jupyter_server import _tz as tz
@@ -48,7 +47,7 @@ def _root_dir_default(self):
4847
try:
4948
return self.parent.root_dir
5049
except AttributeError:
51-
return getcwd()
50+
return os.getcwd()
5251

5352
# ContentsManager-dependent checkpoint API
5453
def create_checkpoint(self, contents_mgr, path):

jupyter_server/services/contents/fileio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
)
2222
import nbformat
2323

24-
from ipython_genutils.py3compat import str_to_unicode
2524

2625
from traitlets.config import Configurable
2726
from traitlets import Bool
@@ -231,7 +230,7 @@ def perm_to_403(self, os_path=''):
231230
# this may not work perfectly on unicode paths on Python 2,
232231
# but nobody should be doing that anyway.
233232
if not os_path:
234-
os_path = str_to_unicode(e.filename or 'unknown file')
233+
os_path = e.filename or "unknown file"
235234
path = to_api_path(os_path, root=self.root_dir)
236235
raise HTTPError(403, u'Permission denied: %s' % path) from e
237236
else:

jupyter_server/services/contents/filemanager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
from ipython_genutils.importstring import import_item
2424
from traitlets import Any, Unicode, Bool, TraitError, observe, default, validate
25-
from ipython_genutils.py3compat import getcwd, string_types
2625

2726
from jupyter_core.paths import exists, is_hidden, is_file_hidden
2827
from jupyter_server import _tz as tz
@@ -47,7 +46,7 @@ def _default_root_dir(self):
4746
try:
4847
return self.parent.root_dir
4948
except AttributeError:
50-
return getcwd()
49+
return os.getcwd()
5150

5251
post_save_hook = Any(None, config=True, allow_none=True,
5352
help="""Python callable or importstring thereof
@@ -70,7 +69,7 @@ def _default_root_dir(self):
7069
@validate('post_save_hook')
7170
def _validate_post_save_hook(self, proposal):
7271
value = proposal['value']
73-
if isinstance(value, string_types):
72+
if isinstance(value, str):
7473
value = import_item(value)
7574
if not callable(value):
7675
raise TraitError("post_save_hook must be callable")

jupyter_server/services/contents/manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
validate,
3030
default,
3131
)
32-
from ipython_genutils.py3compat import string_types
3332
from jupyter_server.transutils import _i18n
3433
from jupyter_server.utils import ensure_async
3534

@@ -106,7 +105,7 @@ def _notary_default(self):
106105
@validate('pre_save_hook')
107106
def _validate_pre_save_hook(self, proposal):
108107
value = proposal['value']
109-
if isinstance(value, string_types):
108+
if isinstance(value, str):
110109
value = import_item(self.pre_save_hook)
111110
if not callable(value):
112111
raise TraitError("pre_save_hook must be callable")

jupyter_server/services/kernels/kernelmanager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
from jupyter_server.utils import to_os_path, ensure_async
2727
from jupyter_server._tz import utcnow, isoformat
28-
from ipython_genutils.py3compat import getcwd
2928

3029
from jupyter_server.prometheus.metrics import KERNEL_CURRENTLY_RUNNING_TOTAL
3130

@@ -58,7 +57,7 @@ def _default_root_dir(self):
5857
try:
5958
return self.parent.root_dir
6059
except AttributeError:
61-
return getcwd()
60+
return os.getcwd()
6261

6362
@validate('root_dir')
6463
def _update_root_dir(self, proposal):

jupyter_server/services/sessions/sessionmanager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from tornado import web
1515

1616
from traitlets.config.configurable import LoggingConfigurable
17-
from ipython_genutils.py3compat import unicode_type
1817
from traitlets import Instance
1918

2019
from jupyter_server.utils import ensure_async
@@ -81,7 +80,7 @@ async def session_exists(self, path):
8180

8281
def new_session_id(self):
8382
"Create a uuid for a new session"
84-
return unicode_type(uuid.uuid4())
83+
return str(uuid.uuid4())
8584

8685
async def create_session(self, path=None, name=None, type=None, kernel_name=None, kernel_id=None):
8786
"""Creates a session and returns its model"""

jupyter_server/tests/nbconvert/test_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
new_notebook, new_markdown_cell, new_code_cell, new_output,
99
)
1010

11-
from ipython_genutils.py3compat import which
11+
from shutil import which
1212

1313

1414
from base64 import encodebytes

0 commit comments

Comments
 (0)