Skip to content

Commit d118ac1

Browse files
committed
Drop ipynbname
1 parent 37a0453 commit d118ac1

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

filter_functions/util.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
:func:`abs2`
2727
Absolute value squared
2828
:func:`get_indices_from_identifiers`
29-
The the indices of a subset of identifiers within a list of
30-
identifiers.
29+
The indices of a subset of identifiers within a list of identifiers.
3130
:func:`tensor`
3231
Fast, flexible tensor product of an arbitrary number of inputs using
3332
:func:`~numpy.einsum`
@@ -70,6 +69,7 @@
7069
import functools
7170
import inspect
7271
import operator
72+
import os
7373
import string
7474
from itertools import zip_longest
7575
from typing import Callable, Iterable, List, Optional, Sequence, Tuple, Union
@@ -79,17 +79,25 @@
7979

8080
from .types import Operator, State
8181

82-
try:
83-
import ipynbname
84-
_NOTEBOOK_NAME = ipynbname.name()
85-
except (ImportError, IndexError, FileNotFoundError):
86-
_NOTEBOOK_NAME = ''
8782

88-
if _NOTEBOOK_NAME:
89-
from tqdm.notebook import tqdm as _tqdm
83+
def _in_notebook_kernel():
84+
# https://github.com/jupyterlab/jupyterlab/issues/16282
85+
return 'JPY_SESSION_NAME' in os.environ and os.environ['JPY_SESSION_NAME'].endswith('.ipynb')
86+
87+
88+
def _in_jupyter_kernel():
89+
# https://discourse.jupyter.org/t/how-to-know-from-python-script-if-we-are-in-jupyterlab/23993
90+
return 'JPY_PARENT_PID' in os.environ
91+
92+
93+
if not _in_notebook_kernel():
94+
if _in_jupyter_kernel():
95+
# (10/24) Autonotebook gets confused in jupyter consoles
96+
from tqdm.std import tqdm
97+
else:
98+
from tqdm.autonotebook import tqdm
9099
else:
91-
# Either not running notebook or not able to determine
92-
from tqdm import tqdm as _tqdm
100+
from tqdm.notebook import tqdm
93101

94102
__all__ = ['paulis', 'abs2', 'all_array_equal', 'dot_HS', 'get_sample_frequencies',
95103
'hash_array_along_axis', 'mdot', 'oper_equiv', 'progressbar', 'remove_float_errors',
@@ -1067,7 +1075,7 @@ def progressbar(iterable: Iterable, *args, **kwargs):
10671075
for i in progressbar(range(10)):
10681076
do_something()
10691077
"""
1070-
return _tqdm(iterable, *args, **kwargs)
1078+
return tqdm(iterable, *args, **kwargs)
10711079

10721080

10731081
def progressbar_range(*args, show_progressbar: bool = True, **kwargs):

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def extract_version(version_file):
1818

1919
extras_require = {'plotting': ['matplotlib'],
2020
'bloch_sphere_visualization': ['qutip', 'matplotlib'],
21-
'fancy_progressbar': ['ipynbname', 'jupyter'],
2221
'doc': ['jupyter', 'nbsphinx', 'numpydoc', 'sphinx', 'sphinx_rtd_theme',
2322
'ipympl', 'qutip-qip', 'qutip-qtrl'],
2423
'tests': ['pytest>=4.6', 'pytest-cov', 'codecov']}

tests/test_extras.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,11 @@
3131

3232
from . import matplotlib
3333

34-
all_extras = ['fancy_progressbar', 'plotting', 'bloch_sphere_visualization']
34+
all_extras = ['plotting', 'bloch_sphere_visualization']
3535

3636

3737
class MissingExtrasTest(testutil.TestCase):
3838

39-
@pytest.mark.skipif(
40-
'fancy_progressbar' in os.environ.get('INSTALL_EXTRAS', all_extras),
41-
reason='Skipping tests for missing fancy progressbar extra in build with ipynbname')
42-
def test_fancy_progressbar_not_available(self):
43-
from tqdm import tqdm
44-
45-
from filter_functions import util
46-
self.assertEqual(util._NOTEBOOK_NAME, '')
47-
self.assertIs(tqdm, util._tqdm)
48-
4939
@pytest.mark.skipif(
5040
any(extra in os.environ.get('INSTALL_EXTRAS', all_extras)
5141
for extra in ['plotting', 'bloch_sphere_visualization']),

0 commit comments

Comments
 (0)