From 67a5a91c435cc9397d4b59d83a0e3c74e987d5ba Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Wed, 13 Mar 2024 18:13:28 +0000 Subject: [PATCH] Revert PR #378 (Simplify NotebookNotary._data_dir_default) --- nbformat/sign.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/nbformat/sign.py b/nbformat/sign.py index 06b1abe..42c9072 100644 --- a/nbformat/sign.py +++ b/nbformat/sign.py @@ -14,8 +14,6 @@ from hmac import HMAC from pathlib import Path -from jupyter_core.paths import jupyter_data_dir - try: import sqlite3 @@ -41,7 +39,7 @@ def convert_datetime(val): from jupyter_core.application import JupyterApp, base_flags from traitlets import Any, Bool, Bytes, Callable, Enum, Instance, Integer, Unicode, default, observe -from traitlets.config import LoggingConfigurable +from traitlets.config import LoggingConfigurable, MultipleInstanceError from . import NO_CONVERT, __version__, read, reads @@ -343,7 +341,17 @@ class NotebookNotary(LoggingConfigurable): @default("data_dir") def _data_dir_default(self): - return jupyter_data_dir() + app = None + try: + if JupyterApp.initialized(): + app = JupyterApp.instance() + except MultipleInstanceError: + pass + if app is None: + # create an app, without the global instance + app = JupyterApp() + app.initialize(argv=[]) + return app.data_dir store_factory = Callable( help="""A callable returning the storage backend for notebook signatures.