4
4
import os
5
5
import re
6
6
import typing as t
7
- from os . path import join as pjoin
7
+ from pathlib import Path
8
8
9
9
from jupyter_client .utils import ensure_async # type:ignore[attr-defined]
10
10
from jupyter_core .application import base_aliases
36
36
37
37
from ._version import __version__
38
38
39
- HERE = os . path . dirname ( __file__ )
39
+ HERE = Path ( __file__ ). parent . resolve ( )
40
40
41
41
Flags = t .Dict [t .Union [str , t .Tuple [str , ...]], t .Tuple [t .Union [t .Dict [str , t .Any ], Config ], str ]]
42
42
43
- app_dir = get_app_dir ()
43
+ app_dir = Path ( get_app_dir () )
44
44
version = __version__
45
45
46
46
# mypy: disable-error-code="no-untyped-call"
@@ -72,7 +72,7 @@ def get_page_config(self) -> dict[str, t.Any]:
72
72
73
73
server_root = self .settings .get ("server_root_dir" , "" )
74
74
server_root = server_root .replace (os .sep , "/" )
75
- server_root = os .path .normpath (os . path . expanduser (server_root ))
75
+ server_root = os .path .normpath (Path ( server_root ). expanduser ())
76
76
try :
77
77
# Remove the server_root from pref dir
78
78
if self .serverapp .preferred_dir != server_root :
@@ -149,7 +149,7 @@ async def get(self, path: str = "") -> None:
149
149
150
150
tpl = self .render_template ("tree.html" , page_config = page_config )
151
151
return self .write (tpl )
152
- elif await ensure_async (cm .file_exists (path )):
152
+ if await ensure_async (cm .file_exists (path )):
153
153
# it's not a directory, we have redirecting to do
154
154
model = await ensure_async (cm .get (path , content = False ))
155
155
if model ["type" ] == "notebook" :
@@ -159,15 +159,15 @@ async def get(self, path: str = "") -> None:
159
159
url = ujoin (self .base_url , "files" , url_escape (path ))
160
160
self .log .debug ("Redirecting %s to %s" , self .request .path , url )
161
161
self .redirect (url )
162
- else :
163
- raise web .HTTPError (404 )
162
+ return None
163
+ raise web .HTTPError (404 )
164
164
165
165
166
166
class ConsoleHandler (NotebookBaseHandler ):
167
167
"""A console page handler."""
168
168
169
169
@web .authenticated
170
- def get (self , path : str | None = None ) -> t .Any :
170
+ def get (self , path : str | None = None ) -> t .Any : # noqa: ARG002
171
171
"""Get the console page."""
172
172
tpl = self .render_template ("consoles.html" , page_config = self .get_page_config ())
173
173
return self .write (tpl )
@@ -177,7 +177,7 @@ class TerminalHandler(NotebookBaseHandler):
177
177
"""A terminal page handler."""
178
178
179
179
@web .authenticated
180
- def get (self , path : str | None = None ) -> t .Any :
180
+ def get (self , path : str | None = None ) -> t .Any : # noqa: ARG002
181
181
"""Get the terminal page."""
182
182
tpl = self .render_template ("terminals.html" , page_config = self .get_page_config ())
183
183
return self .write (tpl )
@@ -187,7 +187,7 @@ class FileHandler(NotebookBaseHandler):
187
187
"""A file page handler."""
188
188
189
189
@web .authenticated
190
- def get (self , path : str | None = None ) -> t .Any :
190
+ def get (self , path : str | None = None ) -> t .Any : # noqa: ARG002
191
191
"""Get the file page."""
192
192
tpl = self .render_template ("edit.html" , page_config = self .get_page_config ())
193
193
return self .write (tpl )
@@ -197,7 +197,7 @@ class NotebookHandler(NotebookBaseHandler):
197
197
"""A notebook page handler."""
198
198
199
199
@web .authenticated
200
- def get (self , path : str | None = None ) -> t .Any :
200
+ def get (self , path : str | None = None ) -> t .Any : # noqa: ARG002
201
201
"""Get the notebook page."""
202
202
tpl = self .render_template ("notebooks.html" , page_config = self .get_page_config ())
203
203
return self .write (tpl )
@@ -214,13 +214,13 @@ def get(self) -> t.Any:
214
214
page_config = self .get_page_config ()
215
215
custom_css_file = f"{ page_config ['jupyterConfigDir' ]} /custom/custom.css"
216
216
217
- if not os . path . isfile (custom_css_file ):
217
+ if not Path (custom_css_file ). is_file ( ):
218
218
static_path_root = re .match ("^(.*?)static" , page_config ["staticDir" ])
219
219
if static_path_root is not None :
220
220
custom_dir = static_path_root .groups ()[0 ]
221
221
custom_css_file = f"{ custom_dir } custom/custom.css"
222
222
223
- with open (custom_css_file ) as css_f :
223
+ with Path (custom_css_file ). open ( ) as css_f :
224
224
return self .write (css_f .read ())
225
225
226
226
@@ -269,23 +269,23 @@ class JupyterNotebookApp(NotebookConfigShimMixin, LabServerApp): # type:ignore[
269
269
270
270
@default ("static_dir" )
271
271
def _default_static_dir (self ) -> str :
272
- return os . path . join (HERE , "static" )
272
+ return str (HERE / "static" )
273
273
274
274
@default ("templates_dir" )
275
275
def _default_templates_dir (self ) -> str :
276
- return os . path . join (HERE , "templates" )
276
+ return str (HERE / "templates" )
277
277
278
278
@default ("app_settings_dir" )
279
279
def _default_app_settings_dir (self ) -> str :
280
- return pjoin (app_dir , "settings" )
280
+ return str (app_dir / "settings" )
281
281
282
282
@default ("schemas_dir" )
283
283
def _default_schemas_dir (self ) -> str :
284
- return pjoin (app_dir , "schemas" )
284
+ return str (app_dir / "schemas" )
285
285
286
286
@default ("themes_dir" )
287
287
def _default_themes_dir (self ) -> str :
288
- return pjoin (app_dir , "themes" )
288
+ return str (app_dir / "themes" )
289
289
290
290
@default ("user_settings_dir" )
291
291
def _default_user_settings_dir (self ) -> str :
@@ -343,7 +343,7 @@ def initialize_handlers(self) -> None:
343
343
self .handlers .append (("/custom/custom.css" , CustomCssHandler ))
344
344
super ().initialize_handlers ()
345
345
346
- def initialize (self , argv : list [str ] | None = None ) -> None :
346
+ def initialize (self , argv : list [str ] | None = None ) -> None : # noqa: ARG002
347
347
"""Subclass because the ExtensionApp.initialize() method does not take arguments"""
348
348
super ().initialize ()
349
349
0 commit comments