From f37b67a92bf979ea9ffcc1ba6e2e022282022d30 Mon Sep 17 00:00:00 2001 From: addisonwurtz Date: Wed, 18 Dec 2024 14:17:18 -0800 Subject: [PATCH 01/10] add /venv to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b25c15b8..0436db98 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *~ +/venv From 0cd754fafc73586240e04901de52eae8f5e895c2 Mon Sep 17 00:00:00 2001 From: addisonwurtz Date: Wed, 18 Dec 2024 14:03:02 -0800 Subject: [PATCH 02/10] Modify start_jupyter to launch jupyterlab instead of jupyter notebook, add jupyter lab to requiremnts.txt --- .../.ipynb_checkpoints/readme-checkpoint.txt | 3 +++ requirements.txt | 1 + start_jupyter | 15 +++++++++------ 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 notebooks/.ipynb_checkpoints/readme-checkpoint.txt diff --git a/notebooks/.ipynb_checkpoints/readme-checkpoint.txt b/notebooks/.ipynb_checkpoints/readme-checkpoint.txt new file mode 100644 index 00000000..9e11c4b4 --- /dev/null +++ b/notebooks/.ipynb_checkpoints/readme-checkpoint.txt @@ -0,0 +1,3 @@ +Files in this folder will not be stored. Restarting the app may result in data loss. + +Is your ContentsManager configured correctly? diff --git a/requirements.txt b/requirements.txt index 7f5130b2..a9ffb554 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ sqlalchemy[postgresql]==1.3 # https://stackoverflow.com/questions/62688256/sqlal psycopg2-binary==2.9.9 # latest alembic==1.13.2 # latest jupyter_server==1.23.5 # https://github.com/jupyter/notebook/issues/6702 +jupyterlab git+https://github.com/ipython-contrib/jupyter_contrib_nbextensions.git diff --git a/start_jupyter b/start_jupyter index 73b7f628..5277697d 100755 --- a/start_jupyter +++ b/start_jupyter @@ -18,11 +18,14 @@ echo "Nbextensions configurator enabled" # terminal interface a little prettier: export PS1='\[\033[01;34m\]\w\[\033[00m\]\$' -echo "Starting Jupyter Notebook" +echo "Starting Jupyter Lab" # NOTE: With allow_origin='*', anyone with the URL and password can potentially access your notebook, # so be careful w/ the URL and password. Don't put sensitive data up here. -jupyter notebook \ - --no-browser --no-mathjax --ip=0.0.0.0 --port=$PORT \ - --NotebookApp.allow_origin='*' --NotebookApp.allow_credentials=True \ - $JUPYTER_NOTEBOOK_ARGS \ - notebooks +jupyter lab \ + --no-browser --ip=0.0.0.0 --port=$PORT \ + --notebook-dir="./notebooks" \ + --config="/app/jupyter_server_config.py" \ + --preferred-dir=None +# --NotebookApp.allow_origin='*' --NotebookApp.allow_credentials=True \ +# $JUPYTER_NOTEBOOK_ARGS \ +# notebooks From 837acfcfa719a2ececc308031d91d5822d4f9892 Mon Sep 17 00:00:00 2001 From: addisonwurtz Date: Wed, 18 Dec 2024 17:17:25 -0800 Subject: [PATCH 03/10] Changed pgcontents dependency to personal fork (addisonwurtz/pgconents...eventually replace with Heroku fork) that fixes pgcontents implementation of ContentsManager class to be compatible with Jupyter Lab --- requirements.txt | 3 ++- start_jupyter | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index a9ffb554..534aa1c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,8 @@ ipython==7.32.0 # https://github.com/NetApp/netapp-dataops-toolkit/issues/13 # ipython==8.27.0 # fixed I think? notebook==6.5.7 # latest 6.* version -git+https://github.com/quantopian/pgcontents.git # https://github.com/quantopian/pgcontents/issues/80 +#git+https://github.com/quantopian/pgcontents.git # https://github.com/quantopian/pgcontents/issues/80 +git+https://github.com/addisonwurtz/pgcontents.git # pgcontents==0.6 sqlalchemy[postgresql]==1.3 # https://stackoverflow.com/questions/62688256/sqlalchemy-exc-nosuchmoduleerror-cant-load-plugin-sqlalchemy-dialectspostgre psycopg2-binary==2.9.9 # latest diff --git a/start_jupyter b/start_jupyter index 5277697d..b0d15675 100755 --- a/start_jupyter +++ b/start_jupyter @@ -24,8 +24,8 @@ echo "Starting Jupyter Lab" jupyter lab \ --no-browser --ip=0.0.0.0 --port=$PORT \ --notebook-dir="./notebooks" \ - --config="/app/jupyter_server_config.py" \ - --preferred-dir=None +# --config="/app/jupyter_server_config.py" \ +# --preferred-dir='' # --NotebookApp.allow_origin='*' --NotebookApp.allow_credentials=True \ # $JUPYTER_NOTEBOOK_ARGS \ # notebooks From 4ebe773b165c91bc9e6c7629228f73a77d684245 Mon Sep 17 00:00:00 2001 From: addisonwurtz Date: Thu, 19 Dec 2024 15:22:42 -0800 Subject: [PATCH 04/10] Set notebook version >= 7 and remove jupyter server version --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 534aa1c4..23a495a2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,12 @@ ipython==7.32.0 # https://github.com/NetApp/netapp-dataops-toolkit/issues/13 # ipython==8.27.0 # fixed I think? -notebook==6.5.7 # latest 6.* version +notebook>=7 #git+https://github.com/quantopian/pgcontents.git # https://github.com/quantopian/pgcontents/issues/80 git+https://github.com/addisonwurtz/pgcontents.git # pgcontents==0.6 sqlalchemy[postgresql]==1.3 # https://stackoverflow.com/questions/62688256/sqlalchemy-exc-nosuchmoduleerror-cant-load-plugin-sqlalchemy-dialectspostgre psycopg2-binary==2.9.9 # latest alembic==1.13.2 # latest -jupyter_server==1.23.5 # https://github.com/jupyter/notebook/issues/6702 +jupyter_server #==1.23.5 # https://github.com/jupyter/notebook/issues/6702 jupyterlab git+https://github.com/ipython-contrib/jupyter_contrib_nbextensions.git From 672f1a7a78a37750949d75055976a93d9d2d2824 Mon Sep 17 00:00:00 2001 From: addisonwurtz Date: Mon, 30 Dec 2024 13:54:23 -0800 Subject: [PATCH 05/10] Migrate jupyter notebook config to jupyter server config (NotebookApp is being deprecated) --- ...notebook_config.py => jupyter_server_config.py} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename .jupyter/{jupyter_notebook_config.py => jupyter_server_config.py} (81%) diff --git a/.jupyter/jupyter_notebook_config.py b/.jupyter/jupyter_server_config.py similarity index 81% rename from .jupyter/jupyter_notebook_config.py rename to .jupyter/jupyter_server_config.py index d267e904..e8ca78a1 100644 --- a/.jupyter/jupyter_notebook_config.py +++ b/.jupyter/jupyter_server_config.py @@ -11,19 +11,19 @@ # http://jupyter-notebook.readthedocs.io/en/latest/security.html if os.environ.get('JUPYTER_NOTEBOOK_PASSWORD_DISABLED') != 'DangerZone!': passwd = os.environ['JUPYTER_NOTEBOOK_PASSWORD'] - c.NotebookApp.password = IPython.lib.passwd(passwd) + c.ServerApp.password = IPython.lib.passwd(passwd) else: - c.NotebookApp.token = '' - c.NotebookApp.password = '' + c.ServerApp.token = '' + c.ServerApp.password = '' ### Make it so the default shell is bash & the prompt is not awful: - c.NotebookApp.terminado_settings = {'shell_command': ['/bin/bash']} + c.ServerApp.terminado_settings = {'shell_command': ['/bin/bash']} ### PostresContentsManager ### database_url = os.getenv('DATABASE_URL', None) if database_url: # Tell IPython to use PostgresContentsManager for all storage. - c.NotebookApp.contents_manager_class = pgcontents.PostgresContentsManager + c.ServerApp.contents_manager_class = pgcontents.PostgresContentsManager # Set the url for the database used to store files. See # http://docs.sqlalchemy.org/en/rel_0_9/core/engines.html#postgresql @@ -44,8 +44,8 @@ if vcap_application_json: vcap_application = json.loads(vcap_application_json) uri = vcap_application['uris'][0] - c.NotebookApp.allow_origin = 'https://{}'.format(uri) - c.NotebookApp.websocket_url = 'wss://{}:4443'.format(uri) + c.ServerApp.allow_origin = 'https://{}'.format(uri) + c.ServerApp.websocket_url = 'wss://{}:4443'.format(uri) except Exception: traceback.print_exc() From 9e1d12ba410975c2a8f25a70d72610aa798f99fb Mon Sep 17 00:00:00 2001 From: addisonwurtz Date: Tue, 7 Jan 2025 11:20:49 -0800 Subject: [PATCH 06/10] Add env variable JUPYTER_NOTEBOOK_OR_LAB to allow user to choose which application to launch, and add JUPYTER_NOTEBOOK_ARGS for additional command line options. --- app.json | 6 ++++++ start_jupyter | 10 +++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app.json b/app.json index 1e879c56..18f69b36 100644 --- a/app.json +++ b/app.json @@ -10,8 +10,14 @@ } ], "env": { + "JUPYTER_NOTEBOOK_OR_LAB": { + "description": "Set to 'notebook' to launch Jupyter Notebook 7, 'lab' to launch Jupyter Lab." + }, "JUPYTER_NOTEBOOK_PASSWORD": { "description": "IMPORTANT! Set a secure password." + }, + "JUPYTER_NOTEBOOK_ARGS": { + "description": "Add command line arguments here (optional)." } }, "addons": [ diff --git a/start_jupyter b/start_jupyter index b0d15675..ead4ecff 100755 --- a/start_jupyter +++ b/start_jupyter @@ -21,11 +21,7 @@ export PS1='\[\033[01;34m\]\w\[\033[00m\]\$' echo "Starting Jupyter Lab" # NOTE: With allow_origin='*', anyone with the URL and password can potentially access your notebook, # so be careful w/ the URL and password. Don't put sensitive data up here. -jupyter lab \ +jupyter $JUPYTER_NOTEBOOK_OR_LAB \ --no-browser --ip=0.0.0.0 --port=$PORT \ - --notebook-dir="./notebooks" \ -# --config="/app/jupyter_server_config.py" \ -# --preferred-dir='' -# --NotebookApp.allow_origin='*' --NotebookApp.allow_credentials=True \ -# $JUPYTER_NOTEBOOK_ARGS \ -# notebooks + --ServerApp.allow_origin='*' --ServerApp.allow_credentials=True \ + $JUPYTER_NOTEBOOK_ARGS \ From e212edf0656dc906222c73bb7826083b0f368633 Mon Sep 17 00:00:00 2001 From: addisonwurtz Date: Tue, 7 Jan 2025 13:25:40 -0800 Subject: [PATCH 07/10] set root_dir in config file --- .jupyter/jupyter_server_config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.jupyter/jupyter_server_config.py b/.jupyter/jupyter_server_config.py index e8ca78a1..aaccee86 100644 --- a/.jupyter/jupyter_server_config.py +++ b/.jupyter/jupyter_server_config.py @@ -7,6 +7,9 @@ c = get_config() + # Root directory for notebook + c.ServerApp.root_dir='/' + ### Password protection ### # http://jupyter-notebook.readthedocs.io/en/latest/security.html if os.environ.get('JUPYTER_NOTEBOOK_PASSWORD_DISABLED') != 'DangerZone!': From 07f33952aa3b19cac51a3512f7a9a24a29f03d53 Mon Sep 17 00:00:00 2001 From: addisonwurtz Date: Tue, 7 Jan 2025 13:26:16 -0800 Subject: [PATCH 08/10] remove Cloud Foundry specific settings --- .jupyter/jupyter_server_config.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.jupyter/jupyter_server_config.py b/.jupyter/jupyter_server_config.py index aaccee86..ccae5fc8 100644 --- a/.jupyter/jupyter_server_config.py +++ b/.jupyter/jupyter_server_config.py @@ -9,7 +9,7 @@ # Root directory for notebook c.ServerApp.root_dir='/' - + ### Password protection ### # http://jupyter-notebook.readthedocs.io/en/latest/security.html if os.environ.get('JUPYTER_NOTEBOOK_PASSWORD_DISABLED') != 'DangerZone!': @@ -42,14 +42,6 @@ # Set a maximum file size, if desired. #c.PostgresContentsManager.max_file_size_bytes = 1000000 # 1MB File cap - ### CloudFoundry specific settings - vcap_application_json = os.getenv('VCAP_APPLICATION', None) - if vcap_application_json: - vcap_application = json.loads(vcap_application_json) - uri = vcap_application['uris'][0] - c.ServerApp.allow_origin = 'https://{}'.format(uri) - c.ServerApp.websocket_url = 'wss://{}:4443'.format(uri) - except Exception: traceback.print_exc() # if an exception occues, notebook normally would get started From e31fc2ca55c2648ea2abe940ec15eedda91b2c7f Mon Sep 17 00:00:00 2001 From: addisonwurtz Date: Tue, 7 Jan 2025 15:15:27 -0800 Subject: [PATCH 09/10] Update readme to include JUPYTER_NOTEBOOK_OR_LAB env variable --- README.md | 7 +++++-- start_jupyter | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index de09d5ee..ec318b6a 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ The fastest & easiest way to get started is to choose option 1 below: automatic First, click on this handy dandy button: [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) -Go through the form that the ^^ above button leads you to, and choose an app name & password. Then click the purple 'deploy app' button at the bottom of the form. +Go through the form that the ^^ above button leads you to, and choose an app name, password, and whether to run Jupyter notebook or Jupyter lab. Then click the purple 'deploy app' button at the bottom of the form. -It will take a couple of minutes for your app to deploy, and then you'll be able to click links to 1) manage your app, and 2) view your live, interactive jupyter notebook running on a heroku dyno (with persistant storage!). +It will take a couple of minutes for your app to deploy, and then you'll be able to click links to 1) manage your app, and 2) view your live, interactive jupyter application running on a heroku dyno (with persistant storage!). Note: If you choose later to fork this repository, you can link your new repo to your heroku app afterwards. @@ -31,6 +31,8 @@ To create a new app, run: ``` export APP_NAME= export JUPYTER_NOTEBOOK_PASSWORD= +# set to 'notebook' or 'lab' to choose which jupyter application to launch: +export JUPYTER_NOTEBOOK_OR_LAB= # if you don't have git: brew install git @@ -46,6 +48,7 @@ heroku stack:set heroku-24 --app $APP_NAME # Set your required config variable: heroku config:set JUPYTER_NOTEBOOK_PASSWORD=$JUPYTER_NOTEBOOK_PASSWORD -a $APP_NAME +heroku congif:set JUPYTER_NOTEBOOK_OR_LAB=$JUPYTER_NOTEBOOK_OR_LAB -a $APP_NAME # Specify the buildpacks it should use: heroku buildpacks:add --index 1 heroku-community/apt -a $APP_NAME diff --git a/start_jupyter b/start_jupyter index ead4ecff..3e942f06 100755 --- a/start_jupyter +++ b/start_jupyter @@ -18,7 +18,7 @@ echo "Nbextensions configurator enabled" # terminal interface a little prettier: export PS1='\[\033[01;34m\]\w\[\033[00m\]\$' -echo "Starting Jupyter Lab" +echo "Starting Jupyter ${JUPYTER_NOTEBOOK_OR_LAB}" # NOTE: With allow_origin='*', anyone with the URL and password can potentially access your notebook, # so be careful w/ the URL and password. Don't put sensitive data up here. jupyter $JUPYTER_NOTEBOOK_OR_LAB \ From 6e5984bba46fb327ac19d3474f2c5af95273ab78 Mon Sep 17 00:00:00 2001 From: addisonwurtz Date: Tue, 7 Jan 2025 15:15:58 -0800 Subject: [PATCH 10/10] Set default value of JUPYTER_NOTEBOOK_OR_LAB to `lab` --- app.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app.json b/app.json index 18f69b36..8673538d 100644 --- a/app.json +++ b/app.json @@ -11,7 +11,8 @@ ], "env": { "JUPYTER_NOTEBOOK_OR_LAB": { - "description": "Set to 'notebook' to launch Jupyter Notebook 7, 'lab' to launch Jupyter Lab." + "description": "Set to 'notebook' to launch Jupyter Notebook 7, 'lab' to launch Jupyter Lab.", + "value": "lab" }, "JUPYTER_NOTEBOOK_PASSWORD": { "description": "IMPORTANT! Set a secure password."