Skip to content

Commit a3999f7

Browse files
committed
Changes to Jupyter server for iOS
1 parent 76209cd commit a3999f7

7 files changed

+423
-32
lines changed

packages/Fiona

Submodule Fiona updated from 19581c4 to ef96fa3

packages/iphone-osx.meson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ endian='little'
66

77
[constants]
88
# Meson does not read environment variables. So we use sed.
9-
prefix = '/Users/holzschu/src/Xcode_iPad/a-Shell/cpython'
9+
prefix = '/Users/holzschu/src/Xcode_iPad/Carnets/cpython'
1010
pandas = prefix + '/packages/pandas-2.0.3'
1111
toolchain = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk'
1212
common_flags = ['-isysroot', toolchain, '-arch', 'arm64', '-miphoneos-version-min=14.0', '-I' + prefix, '-I' + prefix + '/Frameworks_iphoneos/include/', '-I' + pandas + '/pandas/_libs/src/', '-DCYTHON_PEP489_MULTI_PHASE_INIT=0', '-DCYTHON_USE_DICT_VERSIONS=0', '-falign-functions=8', '-F' + prefix + '/Frameworks_iphoneos']

packages/jupyter_server_nbconvert_handlers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tornado import web
1313
from tornado.log import app_log
1414

15-
from jupyter_server.auth import authorized
15+
from jupyter_server.auth.decorator import authorized
1616

1717
from ..base.handlers import FilesRedirectHandler, JupyterHandler, path_regex
1818

@@ -188,6 +188,7 @@ async def post(self, format):
188188
exporter = get_exporter(format, config=self.config)
189189

190190
model = self.get_json_body()
191+
assert model is not None
191192
name = model.get("name", "notebook.ipynb")
192193
nbnode = from_dict(model["content"])
193194

packages/jupyter_server_services_contents_filecheckpoints.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ class FileCheckpoints(FileManagerMixin, Checkpoints):
4343
root_dir = Unicode(config=True)
4444

4545
def _root_dir_default(self):
46-
try:
47-
return self.parent.root_dir
48-
except AttributeError:
46+
if not self.parent:
4947
return os.getcwd()
48+
return self.parent.root_dir
5049

5150
# ContentsManager-dependent checkpoint API
5251
def create_checkpoint(self, contents_mgr, path):
@@ -108,11 +107,7 @@ def checkpoint_path(self, checkpoint_id, path):
108107
parent, name = ("/" + path).rsplit("/", 1)
109108
parent = parent.strip("/")
110109
basename, ext = os.path.splitext(name)
111-
filename = "{name}-{checkpoint_id}{ext}".format(
112-
name=basename,
113-
checkpoint_id=checkpoint_id,
114-
ext=ext,
115-
)
110+
filename = f"{basename}-{checkpoint_id}{ext}"
116111
os_path = self._get_os_path(path=parent)
117112
cp_dir = os.path.join(os_path, self.checkpoint_dir)
118113
# iOS, move checkpoint directory to ~/Documents if local dir is not writeable

packages/jupyter_server_services_contents_fileio.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from tornado.web import HTTPError
1616
from traitlets import Bool
1717
from traitlets.config import Configurable
18+
from traitlets.config.configurable import LoggingConfigurable
1819

1920
from jupyter_server.utils import ApiPath, to_api_path, to_os_path
2021

@@ -165,7 +166,7 @@ def _simple_writing(path, text=True, encoding="utf-8", log=None, **kwargs):
165166
fileobj.close()
166167

167168

168-
class FileManagerMixin(Configurable):
169+
class FileManagerMixin(LoggingConfigurable, Configurable):
169170
"""
170171
Mixin for ContentsAPI classes that interact with the filesystem.
171172
@@ -187,7 +188,7 @@ class FileManagerMixin(Configurable):
187188
True,
188189
config=True,
189190
help="""By default notebooks are saved on disk on a temporary file and then if succefully written, it replaces the old ones.
190-
This procedure, namely 'atomic_writing', causes some bugs on file system whitout operation order enforcement (like some networked fs).
191+
This procedure, namely 'atomic_writing', causes some bugs on file system without operation order enforcement (like some networked fs).
191192
If set to False, the new notebook is written directly on the old one which could fail (eg: full filesystem or quota )""",
192193
)
193194

@@ -214,7 +215,7 @@ def atomic_writing(self, os_path, *args, **kwargs):
214215
return
215216

216217
with self.perm_to_403(os_path):
217-
kwargs["log"] = self.log # type:ignore
218+
kwargs["log"] = self.log
218219
if self.use_atomic_writing:
219220
with atomic_writing(os_path, *args, **kwargs) as f:
220221
yield f
@@ -234,7 +235,7 @@ def perm_to_403(self, os_path=""):
234235
# but nobody should be doing that anyway.
235236
if not os_path:
236237
os_path = e.filename or "unknown file"
237-
path = to_api_path(os_path, root=self.root_dir) # type:ignore
238+
path = to_api_path(os_path, root=self.root_dir) # type:ignore[attr-defined]
238239
# iOS: better error message
239240
import sys
240241
if (sys.platform == "darwin" and os.uname().machine.startswith("iP")):
@@ -249,7 +250,7 @@ def _copy(self, src, dest):
249250
250251
like shutil.copy2, but log errors in copystat
251252
"""
252-
copy2_safe(src, dest, log=self.log) # type:ignore
253+
copy2_safe(src, dest, log=self.log)
253254

254255
def _get_os_path(self, path):
255256
"""Given an API path, return its file system path.
@@ -268,7 +269,8 @@ def _get_os_path(self, path):
268269
------
269270
404: if path is outside root
270271
"""
271-
root = os.path.abspath(self.root_dir) # type:ignore
272+
self.log.debug("Reading path from disk: %s", path)
273+
root = os.path.abspath(self.root_dir) # type:ignore[attr-defined]
272274
# to_os_path is not safe if path starts with a drive, since os.path.join discards first part
273275
if os.path.splitdrive(path)[0]:
274276
raise HTTPError(404, "%s is not a relative API path" % path)
@@ -375,7 +377,7 @@ async def _copy(self, src, dest):
375377
376378
like shutil.copy2, but log errors in copystat
377379
"""
378-
await async_copy2_safe(src, dest, log=self.log) # type:ignore
380+
await async_copy2_safe(src, dest, log=self.log)
379381

380382
async def _read_notebook(self, os_path, as_version=4, capture_validation_error=None):
381383
"""Read a notebook from an os path."""

0 commit comments

Comments
 (0)