about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorRobert Schütz <nix@dotlambda.de>2023-08-03 00:27:52 -0700
committerRobert Schütz <nix@dotlambda.de>2023-08-03 00:34:50 -0700
commit35aa2915806b604dc25e2c3842746c12614c2e07 (patch)
treefd84460451921e44a774a4886e9b0583bb6661a4 /pkgs
parent2cfcf60156b7bc15682174dd5ff3cde82410018f (diff)
downloadnixlib-35aa2915806b604dc25e2c3842746c12614c2e07.tar
nixlib-35aa2915806b604dc25e2c3842746c12614c2e07.tar.gz
nixlib-35aa2915806b604dc25e2c3842746c12614c2e07.tar.bz2
nixlib-35aa2915806b604dc25e2c3842746c12614c2e07.tar.lz
nixlib-35aa2915806b604dc25e2c3842746c12614c2e07.tar.xz
nixlib-35aa2915806b604dc25e2c3842746c12614c2e07.tar.zst
nixlib-35aa2915806b604dc25e2c3842746c12614c2e07.zip
python310Packages.experiment-utilities: unvendor ipynbname
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/development/python-modules/experiment-utilities/default.nix6
-rw-r--r--pkgs/development/python-modules/experiment-utilities/unvendor-ipynbname.patch117
2 files changed, 123 insertions, 0 deletions
diff --git a/pkgs/development/python-modules/experiment-utilities/default.nix b/pkgs/development/python-modules/experiment-utilities/default.nix
index 46c50e1e2ec0..5fd21994558e 100644
--- a/pkgs/development/python-modules/experiment-utilities/default.nix
+++ b/pkgs/development/python-modules/experiment-utilities/default.nix
@@ -5,6 +5,7 @@
 , fasteners
 , fetchFromGitLab
 , qgrid
+, ipynbname
 , ipywidgets
 , odfpy
 , scipy
@@ -28,6 +29,10 @@ buildPythonPackage rec {
     hash = "sha256-zjmmLUpGjUhpw2+stLJE6cImesnBSvrcid5bHMftX/Q=";
   };
 
+  patches = [
+    ./unvendor-ipynbname.patch
+  ];
+
   # This dependency constraint (<=7.6.5) was due to a bug in qgrid that has been patched in its
   # owned derivation
   postPatch = ''
@@ -39,6 +44,7 @@ buildPythonPackage rec {
     cloudpickle
     dill
     fasteners
+    ipynbname
     ipywidgets
     odfpy
     plotly
diff --git a/pkgs/development/python-modules/experiment-utilities/unvendor-ipynbname.patch b/pkgs/development/python-modules/experiment-utilities/unvendor-ipynbname.patch
new file mode 100644
index 000000000000..84f4467a8347
--- /dev/null
+++ b/pkgs/development/python-modules/experiment-utilities/unvendor-ipynbname.patch
@@ -0,0 +1,117 @@
+diff --git a/exputils/gui/jupyter/__init__.py b/exputils/gui/jupyter/__init__.py
+index 6e9aefb..fdfdd28 100644
+--- a/exputils/gui/jupyter/__init__.py
++++ b/exputils/gui/jupyter/__init__.py
+@@ -30,8 +30,8 @@ from exputils.gui.jupyter.misc import remove_children_from_widget
+ from exputils.gui.jupyter.misc import set_children_of_widget
+ from exputils.gui.jupyter.misc import generate_random_state_backup_name
+ 
+-from exputils.gui.jupyter.ipynbname import get_notebook_name
+-from exputils.gui.jupyter.ipynbname import get_notebook_path
++from ipynbname import name as get_notebook_name
++from ipynbname import path as get_notebook_path
+ 
+ DEFAULT_CONFIG_DIRECTORY = '.ipython_config'
+ 
+diff --git a/exputils/gui/jupyter/ipynbname.py b/exputils/gui/jupyter/ipynbname.py
+deleted file mode 100644
+index 51e21b7..0000000
+--- a/exputils/gui/jupyter/ipynbname.py
++++ /dev/null
+@@ -1,86 +0,0 @@
+-##
+-## This file is part of the exputils package.
+-##
+-## Copyright: INRIA
+-## Year: 2022, 2023
+-## Contact: chris.reinke@inria.fr
+-##
+-## exputils is provided under GPL-3.0-or-later
+-##
+-# Taken from https://pypi.org/project/ipynbname/
+-# TODO: add them to licence
+-
+-from notebook import notebookapp
+-import urllib, json, os, ipykernel, ntpath
+-
+-FILE_ERROR = "Can't identify the notebook {}."
+-CONN_ERROR = "Unable to access server;\n \
+-            + ipynbname requires either no security or token based security."
+-
+-def _get_kernel_id():
+-    """ Returns the kernel ID of the ipykernel.
+-    """
+-    connection_file = os.path.basename(ipykernel.get_connection_file())
+-    kernel_id = connection_file.split('-', 1)[1].split('.')[0]
+-    return kernel_id
+-
+-
+-def _get_sessions(srv):
+-    """ Given a server, returns sessions, or HTTPError if access is denied.
+-        NOTE: Works only when either there is no security or there is token
+-        based security. An HTTPError is raised if unable to connect to a
+-        server.
+-    """
+-    try:
+-        qry_str = ""
+-        token = srv['token']
+-        if token:
+-            qry_str = f"?token={token}"
+-        url = f"{srv['url']}api/sessions{qry_str}"
+-        req = urllib.request.urlopen(url)
+-        return json.load(req)
+-    except:
+-        raise urllib.error.HTTPError(CONN_ERROR)
+-
+-
+-def _get_nb_path(sess, kernel_id):
+-    """ Given a session and kernel ID, returns the notebook path for the
+-        session, or None if there is no notebook for the session.
+-    """
+-    if sess['kernel']['id'] == kernel_id:
+-        return sess['notebook']['path']
+-    return None
+-
+-
+-def get_notebook_name():
+-    """ Returns the short name of the notebook w/o the .ipynb extension,
+-        or raises a FileNotFoundError exception if it cannot be determined.
+-    """
+-    kernel_id = _get_kernel_id()
+-    for srv in notebookapp.list_running_servers():
+-        try:
+-            sessions = _get_sessions(srv)
+-            for sess in sessions:
+-                nb_path = _get_nb_path(sess, kernel_id)
+-                if nb_path:
+-                    return ntpath.basename(nb_path).replace('.ipynb', '')
+-        except:
+-            pass  # There may be stale entries in the runtime directory
+-    raise FileNotFoundError(FILE_ERROR.format('name'))
+-
+-
+-def get_notebook_path():
+-    """ Returns the absolute path of the notebook,
+-        or raises a FileNotFoundError exception if it cannot be determined.
+-    """
+-    kernel_id = _get_kernel_id()
+-    for srv in notebookapp.list_running_servers():
+-        try:
+-            sessions = _get_sessions(srv)
+-            for sess in sessions:
+-                nb_path = _get_nb_path(sess, kernel_id)
+-                if nb_path:
+-                    return os.path.join(srv['notebook_dir'], nb_path)
+-        except:
+-            pass  # There may be stale entries in the runtime directory
+-    raise FileNotFoundError(FILE_ERROR.format('path'))
+\ No newline at end of file
+diff --git a/setup.cfg b/setup.cfg
+index 9d9cbb0..6080ed6 100644
+--- a/setup.cfg
++++ b/setup.cfg
+@@ -25,3 +25,4 @@ install_requires =
+   tensorboard >= 1.15.0
+   fasteners >= 0.18
+   pyyaml >= 6.0
++  ipynbname