Last active
April 28, 2025 21:34
-
-
Save zsol/d624b49a505e1041f6948df37d74398e to your computer and use it in GitHub Desktop.
Hermetic Notebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # --- | |
| # jupyter: | |
| # jupytext: | |
| # cell_metadata_filter: jupyter,-all | |
| # text_representation: | |
| # extension: .py | |
| # format_name: percent | |
| # format_version: '1.3' | |
| # jupytext_version: 1.17.1 | |
| # kernelspec: | |
| # display_name: Python 3 (ipykernel) | |
| # language: python | |
| # name: python3 | |
| # --- | |
| # %% jupyter={"source_hidden": true} | |
| # /// script | |
| # requires-python = ">=3.13" | |
| # dependencies = [ | |
| # "black", | |
| # "isort", | |
| # "jupyter", | |
| # "jupyter-lsp", | |
| # "jupyterlab-code-formatter", | |
| # "jupyterlab-lsp", | |
| # "jupytext", | |
| # "pylsp-mypy", | |
| # "python-lsp-ruff", | |
| # "python-lsp-server", | |
| # ] | |
| # /// | |
| if __name__ == "__main__": | |
| from notebook.app import JupyterNotebookApp | |
| if not JupyterNotebookApp._instance: | |
| from pathlib import Path | |
| from tempfile import TemporaryDirectory | |
| import json | |
| import sys | |
| import os | |
| this_file = Path(sys.argv[0]).as_posix() | |
| with TemporaryDirectory() as tmpdir: | |
| os.environ["JUPYTERLAB_SETTINGS_DIR"] = tmpdir | |
| settings = Path(tmpdir) / "@jupyterlab" | |
| docman = settings / "docmanager-extension/plugin.jupyterlab-settings" | |
| docman.parent.mkdir(parents=True, exist_ok=True) | |
| docman.write_text( | |
| json.dumps( | |
| { | |
| "autosave": True, | |
| "autosaveInterval": 120, | |
| "confirmClosingDocument": False, | |
| "lastModifiedCheckMargin": 500, | |
| "defaultViewers": {"python": "Jupytext Notebook"}, | |
| "renameUntitledFileOnSave": True, | |
| "maxNumberRecents": 10, | |
| } | |
| ) | |
| ) | |
| apputils = settings / "apputils-extension/notification.jupyterlab-settings" | |
| apputils.parent.mkdir(exist_ok=True, parents=True) | |
| apputils.write_text(json.dumps({"fetchNews": "false"})) | |
| JupyterNotebookApp.launch_instance( | |
| argv=[f"--JupyterNotebookApp.default_url=/doc/tree/{this_file}"] | |
| ) | |
| sys.exit(0) | |
| # %% | |
| def hello() -> str: | |
| return " ".join(["hello", "world"]) | |
| print(hello()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment