# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Multi-Stage Notebook
#
# > _Have a look at the [Starter Notebook](./Starter%20Notebook.ipynb) for a lot of the
# > basic ideas of using a
# > [Jupyter Kernel](https://jupyter.readthedocs.io/en/latest/projects/kernels.html) as a
# > Starter_
#
# Combining `continuing` with `copy`, a notebook starter can incrementally build up a
# directory.

# +
import json
import os
import pathlib
import random
import re
import sys

here = pathlib.Path.cwd()
this = here / "_jupyter_starter_.ipynb"
live = this.exists()
if not live:
    this = here / "Multi-Stage Starter Notebook.ipynb"
it = json.loads(this.read_text())
# -

meta = it["metadata"]["jupyter_starters"]
body = meta.setdefault("body", {})

if "T" not in locals():
    T = 0

previous = f"move_{T}"
if live and previous in body and body[previous]:
    new_file = here / f"""file for {body["name"]} {T}.txt"""
    new_file.write_text(f"""Hi, {body["name"]}! This is file number {T}.""")

    meta["copy"] = True
    meta["starter"]["commands"] = [
        {
            "id": "filebrowser:open-path",
            "args": {"path": f"""{meta["path"]}/{new_file.name}"""},
        }
    ]

T += 1
move = f"move_{T}"
meta["starter"]["schema"]["properties"][move] = {
    "title": f"""Create `file for {body["name"]} {T}.txt`?""",
    "description": "I'll just keep creating files until you say stop",
    "type": "boolean",
    "default": True,
}

meta["starter"]["schema"]["properties"]["done"] = {
    "title": f"""I am done""",
    "description": "Make it stop!",
    "type": "boolean",
    "default": False,
}

if body.get("done"):
    meta["status"] = "done"
else:
    meta["status"] = "continuing"

# Write out files.

if live:
    this.write_text(json.dumps(it))

StarcoderdataJupyterScriptsDedupFiltered