Skip to content

Commit b4d3403

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 36218db commit b4d3403

File tree

12 files changed

+32
-39
lines changed

12 files changed

+32
-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
@@ -723,7 +722,7 @@ def set_headers(self):
723722
def initialize(self, path, default_filename=None, no_cache_paths=None):
724723
self.no_cache_paths = no_cache_paths or []
725724

726-
if isinstance(path, string_types):
725+
if isinstance(path, str):
727726
path = [path]
728727

729728
self.root = tuple(

jupyter_server/serverapp.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
Any, Dict, Unicode, Integer, List, Bool, Bytes, Instance,
9999
TraitError, Type, Float, observe, default, validate
100100
)
101-
from ipython_genutils import py3compat
102101
from jupyter_core.paths import jupyter_runtime_dir, jupyter_path
103102
from jupyter_server._sysinfo import get_sys_info
104103

@@ -195,7 +194,7 @@ def init_settings(self, jupyter_app, kernel_manager, contents_manager,
195194
"template_path",
196195
jupyter_app.template_file_path,
197196
)
198-
if isinstance(_template_path, py3compat.string_types):
197+
if isinstance(_template_path, str):
199198
_template_path = (_template_path,)
200199
template_path = [os.path.expanduser(path) for path in _template_path]
201200

@@ -223,7 +222,7 @@ def init_settings(self, jupyter_app, kernel_manager, contents_manager,
223222
now = utcnow()
224223

225224
root_dir = contents_manager.root_dir
226-
home = py3compat.str_to_unicode(os.path.expanduser('~'), encoding=sys.getfilesystemencoding())
225+
home = os.path.expanduser("~")
227226
if root_dir.startswith(home + os.path.sep):
228227
# collapse $HOME to ~
229228
root_dir = '~' + root_dir[len(home):]
@@ -925,8 +924,6 @@ def _default_allow_remote(self):
925924
# Address is a hostname
926925
for info in socket.getaddrinfo(self.ip, self.port, 0, socket.SOCK_STREAM):
927926
addr = info[4][0]
928-
if not py3compat.PY3:
929-
addr = addr.decode('ascii')
930927

931928
try:
932929
parsed = ipaddress.ip_address(addr.split('%')[0])
@@ -1258,7 +1255,7 @@ def _default_root_dir(self):
12581255
self._root_dir_set = True
12591256
return os.path.dirname(os.path.abspath(self.file_to_run))
12601257
else:
1261-
return py3compat.getcwd()
1258+
return os.getcwd()
12621259

12631260
@validate('root_dir')
12641261
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
File-based Checkpoints implementations.
33
"""
44
import os
5+
from os import getcwd
56
import shutil
67

78
from tornado.web import HTTPError
@@ -16,7 +17,6 @@
1617

1718
from anyio import run_sync_in_worker_thread
1819
from jupyter_core.utils import ensure_dir_exists
19-
from ipython_genutils.py3compat import getcwd
2020
from traitlets import Unicode
2121

2222
from jupyter_server import _tz as tz

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

@@ -56,7 +55,7 @@ def _default_root_dir(self):
5655
try:
5756
return self.parent.root_dir
5857
except AttributeError:
59-
return getcwd()
58+
return os.getcwd()
6059

6160
@validate('root_dir')
6261
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)