From 8af6ea6a929bd4d82e6af5964b5649d50b076da3 Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Tue, 12 Dec 2023 09:44:20 -0600 Subject: [PATCH] Improve lite gist handling (#22) --- .github/ISSUE_TEMPLATE/bug_report.md | 40 +++++ .github/ISSUE_TEMPLATE/docs.md | 22 +++ .github/ISSUE_TEMPLATE/feature_request.md | 22 +++ .github/pull_request_template.md | 66 ++++++++ src/jupyak/tasks/_lite.ipynb | 176 ++++++++++++---------- src/jupyak/tasks/_self.ipynb | 32 +--- 6 files changed, 253 insertions(+), 105 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/docs.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/pull_request_template.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..55575a3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,40 @@ +--- +name: bug report +about: create a report to help us improve +labels: bug +--- + + + +### references + + + +## description + + + +## reproduce + + + +1. go to '...' +2. click on '...' +3. scroll down to '...' +4. see error '...' + + + +## expected behavior + + + +## context + + + +- operating system and version: +- browser and version: diff --git a/.github/ISSUE_TEMPLATE/docs.md b/.github/ISSUE_TEMPLATE/docs.md new file mode 100644 index 0000000..366c644 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/docs.md @@ -0,0 +1,22 @@ +--- +name: documentation request +about: ask for clarification in documentation +labels: documentation +--- + + + +## what I am trying to do... + + + +## how I would like to learn how to do it... + + + +## how the project might keep the docs accurate... + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..0d9289a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,22 @@ +--- +name: request a future roadmap item +about: help us build future features +labels: enhancement +--- + + + +## elevator pitch + + + +## motivation + + + +## design ideas + + diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..48c00ce --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,66 @@ + + +## what kind of request is this? + + + +- [x] a preview site on ReadTheDocs + - [x] it only adds a `jupyak_config.toml` +- [ ] a `jupyak` code change + - [ ] it adds new features, described below + +## for preview sites + +### how should a visitor use the preview site? + + + +1. go to `{readthedocs url}/_static/work/lite/lab/?path={file to open}` +2. navigate to ... +3. see ... + +### where is the main discussion? + + + +--- + + + +## for `jupyak` code changes + +### references + + + +### code changes + + + +### user-facing changes + + + + + +### backwards-incompatible changes + + diff --git a/src/jupyak/tasks/_lite.ipynb b/src/jupyak/tasks/_lite.ipynb index b9659ad..32a29b7 100644 --- a/src/jupyak/tasks/_lite.ipynb +++ b/src/jupyak/tasks/_lite.ipynb @@ -41,38 +41,22 @@ " lite = yak.lite.work_path\n", " build_conf = yak.lite.build_config_path\n", " in_work_lite = {\"cwd\": lite}\n", - " run_args = yak.env.run_args\n", - " lite_args = [*run_args, \"jupyter\", \"lite\"]\n", + " lite_args = [*yak.env.run_args, \"jupyter\", \"lite\"]\n", "\n", - " all_deps = cli_deps, build_deps, run_deps = _find_lite_deps(yak)\n", - "\n", - " gist_dep = []\n", - "\n", - " if yak.lite.gist:\n", - " gist_dep += [yak.lite.gist_path / \".git/refs/heads\" / W.WORK_BRANCH]\n", - "\n", - " self_dist = os.environ.get(W.ENV_VAR_SELF_DIST)\n", - "\n", - " if self_dist:\n", - " run_deps += [Path(self_dist)]\n", + " all_deps = cli_deps, conf_deps, conf_targets, build_deps = _find_lite_deps(yak)\n", "\n", " yield dict(\n", " name=\"config\",\n", " doc=\"> configure jupyterlite\",\n", - " file_dep=[*build_deps, *run_deps, *gist_dep],\n", - " actions=[(_make_lite_config, [build_deps, run_deps, yak])],\n", - " targets=[build_conf],\n", + " file_dep=[*conf_deps, *build_deps],\n", + " actions=[(_make_lite_config, [yak, *all_deps])],\n", + " targets=sorted(set(conf_targets)),\n", " )\n", "\n", " yield dict(\n", " name=\"build\",\n", " doc=\"> build lite site archive\",\n", - " file_dep=[\n", - " *sum(all_deps, []),\n", - " *gist_dep,\n", - " build_conf,\n", - " yak.env.lab_share / \"static\" / W.PACKAGE_JSON,\n", - " ],\n", + " file_dep=[*conf_targets, *build_deps, *cli_deps],\n", " actions=[\n", " A.run([*lite_args, \"build\"], in_work_lite),\n", " A.run([*lite_args, \"archive\"], in_work_lite),\n", @@ -89,28 +73,66 @@ "outputs": [], "source": [ "def _find_lite_deps(yak: Y.Yak):\n", - " cli_deps = []\n", - " build_deps = []\n", - " run_deps = []\n", + " all_deps = cli_deps, conf_deps, conf_targets, build_deps = [], [], [], []\n", + "\n", + " cli_deps += [yak.env.lab_share / \"static\" / W.PACKAGE_JSON]\n", + "\n", " for name, repo in yak.py_repos.items():\n", - " if not repo.lite:\n", - " continue\n", - "\n", - " cli_deps += [\n", - " yak.env.py_site_packages / P._pth_path(pth) for pth in repo.lite.needs_pth\n", - " ]\n", - " for ext_js_path, ext in repo.py.lab_extensions.items():\n", - " build_deps += [repo.work_path / t for t in ext.targets]\n", - " if repo.lite.wheel:\n", - " for ppt in repo.py.pyproject_tomls:\n", - " ppt_path = repo.work_path / ppt\n", - " if any(\n", - " re.match(swp, ppt_path.parent.name)\n", - " for swp in repo.lite.skip_wheel_patterns\n", - " ):\n", - " continue\n", - " run_deps += [ppt_path.parent / \"dist\" / W.SHA256SUMS]\n", - " return cli_deps, build_deps, run_deps" + " if repo.lite:\n", + " _add_repo_deps(repo, *all_deps)\n", + "\n", + " if yak.lite.gist:\n", + " _add_gist_deps(yak, *all_deps)\n", + "\n", + " self_dist = os.environ.get(W.ENV_VAR_SELF_DIST)\n", + "\n", + " if self_dist:\n", + " build_deps += [Path(self_dist)]\n", + "\n", + " return all_deps" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "29acfebf-d3fd-4d27-b319-4aeb7d7d6aba", + "metadata": {}, + "outputs": [], + "source": [ + "def _add_gist_deps(yak: Y.Yak, cli_deps, conf_deps, conf_targets, build_deps):\n", + " gist_path = yak.lite.gist_path\n", + " work_path = yak.lite.work_path\n", + " conf_deps += [gist_path / \".git/refs/heads\" / W.WORK_BRANCH]\n", + " conf_targets += [yak.lite.build_config_path]\n", + " if yak.lite.gist_path.exists():\n", + " gist_files = [p for p in gist_path.glob(\"*\") if not p.is_dir()]\n", + " conf_deps += gist_files\n", + " conf_targets += [work_path / p.name for p in gist_files]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e5e053b3-5ad6-4f40-a115-c04d9dbf6de9", + "metadata": {}, + "outputs": [], + "source": [ + "def _add_repo_deps(repo: Y.Repo, cli_deps, conf_deps, conf_targets, build_deps):\n", + " cli_deps += [\n", + " repo.parent.env.py_site_packages / P._pth_path(pth)\n", + " for pth in repo.lite.needs_pth\n", + " ]\n", + " for ext_js_path, ext in repo.py.lab_extensions.items():\n", + " build_deps += [repo.work_path / t for t in ext.targets]\n", + " if repo.lite.wheel:\n", + " for ppt in repo.py.pyproject_tomls:\n", + " ppt_path = repo.work_path / ppt\n", + " if any(\n", + " re.match(swp, ppt_path.parent.name)\n", + " for swp in repo.lite.skip_wheel_patterns\n", + " ):\n", + " continue\n", + " build_deps += [ppt_path.parent / \"dist\" / W.SHA256SUMS]" ] }, { @@ -120,13 +142,19 @@ "metadata": {}, "outputs": [], "source": [ - "def _make_lite_config(build_deps, run_deps, yak: Y.Yak, config=None):\n", + "def _make_lite_config(yak: Y.Yak, cli_deps, conf_deps, conf_targets, build_deps):\n", " work_path = yak.lite.work_path\n", - " work_path.mkdir(exist_ok=True, parents=True)\n", - " contents = []\n", - " config = config or {}\n", + " config = {}\n", + " if yak.lite.gist_path.exists():\n", + " A.copy(yak.lite.gist_path, work_path)\n", + " if yak.lite.build_config_path.exists():\n", + " config = json.loads(yak.lite.build_config_path.read_text(encoding=\"utf-8\"))\n", + " else:\n", + " work_path.mkdir(exist_ok=True, parents=True)\n", + "\n", " lbc = config.setdefault(\"LiteBuildConfig\", {})\n", " pla = config.setdefault(\"PipliteAddon\", {})\n", + "\n", " pkg_jsons = [\n", " p\n", " for p in build_deps\n", @@ -135,51 +163,39 @@ " ]\n", " whl_deps = [\n", " p\n", - " for p in run_deps\n", + " for p in build_deps\n", " if p.name == W.SHA256SUMS and p.parent.glob(f\"*{W.NOARCH_WHL}\")\n", " ]\n", "\n", - " if yak.lite.gist:\n", - " contents = [os.path.relpath(yak.lite.gist_path, work_path)]\n", - " gist_config_path = yak.lite.gist_path / W.JUPYTER_LITE_CONFIG\n", - " if gist_config_path.exists():\n", - " gist_config = json.loads(gist_config_path.read_text(encoding=\"utf-8\"))\n", - " for has_traits, trait_values in gist_config.items():\n", - " config.setdefault(has_traits, {}).update(trait_values)\n", - " for run_path in [W.JUPYTER_LITE_JSON, W.JUPYTER_LITE_IPYNB]:\n", - " src = yak.lite.gist_path / run_path\n", - " if not src.exists():\n", - " continue\n", - " dest = work_path / run_path\n", - " dest.write_text(src.read_text(encoding=\"utf-8\"), encoding=\"utf-8\")\n", - "\n", " lbc.update(\n", " cache_dir=\"../.cache/lite\",\n", - " contents=contents,\n", + " contents=[\".\"],\n", " output_dir=os.path.relpath(yak.lite.app_path, work_path),\n", - " ignore_sys_prefix=[\"federated_extensions\"],\n", - " federated_extensions=[\n", - " os.path.relpath(pkg_json.parent, work_path) for pkg_json in pkg_jsons\n", - " ],\n", + " federated_extensions=sorted(\n", + " [\n", + " *lbc.get(\"federated_extensions\", []),\n", + " *[\n", + " os.path.relpath(pkg_json.parent, work_path)\n", + " for pkg_json in pkg_jsons\n", + " ],\n", + " ]\n", + " ),\n", " )\n", "\n", " pla.update(\n", - " piplite_urls=[\n", - " *pla.get(\"piplite_urls\", []),\n", - " *[os.path.relpath(whl_shas.parent, work_path) for whl_shas in whl_deps],\n", - " ]\n", + " piplite_urls=sorted(\n", + " [\n", + " *pla.get(\"piplite_urls\", []),\n", + " *[os.path.relpath(whl_shas.parent, work_path) for whl_shas in whl_deps],\n", + " ]\n", + " ),\n", " )\n", "\n", - " yak.lite.build_config_path.write_text(json.dumps(config, indent=2, sort_keys=True))" + " yak.lite.build_config_path.write_text(\n", + " json.dumps(config, indent=2, sort_keys=True),\n", + " encoding=\"utf-8\",\n", + " )" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ad28a139-cf16-4f22-84cc-7b1a8afc63ad", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/src/jupyak/tasks/_self.ipynb b/src/jupyak/tasks/_self.ipynb index 13a1144..44c8cd0 100644 --- a/src/jupyak/tasks/_self.ipynb +++ b/src/jupyak/tasks/_self.ipynb @@ -495,29 +495,6 @@ ")" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "e5659817-c8a3-412a-a626-03fb9a059a39", - "metadata": {}, - "outputs": [], - "source": [ - "ROOT = PPT.parent.resolve()\n", - "TESTS = ROOT / \"tests\"\n", - "GH = ROOT / \".github\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "13d97782-cde3-44e0-84b2-dd90488ac441", - "metadata": {}, - "outputs": [], - "source": [ - "ALL_TEST_PY = sorted(p for p in TESTS.rglob(\"*.py\") if not re.search(W.IPYNBC, str(p)))\n", - "ALL_SRC_PY = sorted(p for p in SRC.rglob(\"*.py\") if not re.search(W.IPYNBC, str(p)))" - ] - }, { "cell_type": "markdown", "id": "1bb36ed7-21f9-45ba-a963-473828e13dee", @@ -548,10 +525,13 @@ { "cell_type": "code", "execution_count": null, - "id": "28ae8295-1724-4437-bb85-3ac1d28000e6", + "id": "2f34a488-180d-45bb-8b81-c1f299c738ae", "metadata": {}, "outputs": [], "source": [ + "ROOT = PPT.parent.resolve()\n", + "TESTS = ROOT / \"tests\"\n", + "GH = ROOT / \".github\"\n", "BUILD = ROOT / \"build\"\n", "DIST = ROOT / \"dist\"\n", "README = ROOT / \"README.md\"\n", @@ -745,11 +725,13 @@ "metadata": {}, "outputs": [], "source": [ + "ALL_TEST_PY = sorted(p for p in TESTS.rglob(\"*.py\") if not re.search(W.IPYNBC, str(p)))\n", + "ALL_SRC_PY = sorted(p for p in SRC.rglob(\"*.py\") if not re.search(W.IPYNBC, str(p)))\n", "ALL_JS = [*JS.glob(\"*.js\")]\n", "ALL_TS = [*JS_SRC.rglob(\"*.ts\"), *JS_SRC.rglob(\"*.tsx\")]\n", "ALL_IPYNB = sorted([*TASKS.glob(\"*.ipynb\"), *DOCS.glob(\"*.ipynb\")])\n", "ALL_PY = sorted([*ROOT.glob(\"*.py\"), *ALL_SRC_PY, *ALL_DOCS_PY, *ALL_TEST_PY])\n", - "ALL_MD = [README]\n", + "ALL_MD = [README, *GH.rglob(\"*.md\")]\n", "ALL_JSON = [*ALL_DEMO_JSON, JS_PACKAGE, JS_PACKAGE_ROOT, DOCS_SCHEMA, *ALL_DEMO_JSON]\n", "ALL_YAML = [\n", " *GH.rglob(\"*.yml\"),\n",