Your original statement is correct, @fomightez: my “solution” is not universal (actually, I had never tested it for binder bundles).
From your last test, I don’t even think this is the right approach since there is nothing in the psutil command output that can identify a ‘native’ JupyterLab string with ‘lab’ in it (as the user-defined base_url may be totally different than yours).
The function I gave, with the wrong indentation, which you caught, is part of another one which I use as a reminder depending on how I open an existing notebook:
def is_lab_notebook():
import re
import psutil
return any(re.search('jupyter-lab-script', x)
for x in psutil.Process().parent().cmdline())
def check_notebook():
"""
Util to check a Jupyter notebook environment:
a markdown cell in a jupyter lab notebook cannot render
variables: the cell text needs to be created with
IPython.display.Markdown.
"""
if is_lab_notebook():
# need to use Markdown if referencing variables:
from IPython.display import Markdown
msg = "This is a <span style=\"color:red;\">JupyterLab notebook </span>:<br>"
msg += "* Use `IPython.display.Markdown(F'x = {n}')` if referencing variables. "
msg += "Using {{n}} directly in a Markdown cell will not work."
return Markdown('### {}'.format(msg))
check_notebook()