Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve lite gist handling #22

Merged
merged 7 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: bug report
about: create a report to help us improve
labels: bug
---

<!--
welcome! before creating a new issue, please look for relevant issues, documentation,
pull requests, and discussions.
-->

### references

<!-- note related issue numbers or pull requests -->

## description

<!-- describe the bug clearly and concisely. include screenshots (or even better - gifs) if possible -->

## reproduce

<!-- describe step-by-step instructions to reproduce the behavior -->

1. go to '...'
2. click on '...'
3. scroll down to '...'
4. see error '...'

<!-- describe how you diagnosed the issue. -->

## expected behavior

<!-- describe what you expected to happen -->

## context

<!-- complete the following for context, and add any other relevant context -->

- operating system and version:
- browser and version:
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: documentation request
about: ask for clarification in documentation
labels: documentation
---

<!--
welcome! before creating a new issue, please look for relevant issues, documentation,
pull requests, and discussions.
-->

## what I am trying to do...

<!-- describe what you are trying to do, and how the current docs aren't helping you achieve it-->

## how I would like to learn how to do it...

<!-- describe what would help you understand what you are trying to do, e.g. tutorials, code comments, screencasts, etc. -->

## how the project might keep the docs accurate...

<!-- describe how this documentation can be kept up-to-date: testing, link checking, etc. -->
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: request a future roadmap item
about: help us build future features
labels: enhancement
---

<!--
welcome! before creating a new issue, please look for relevant issues, documentation,
pull requests, and discussions.
-->

## elevator pitch

<!-- In no more than three sentences, what would you like to see implemented? -->

## motivation

<!-- Why do you want this feature? -->

## design ideas

<!-- Share any kind of design ideas (e.g. ASCII art, links, screenshots) that might help us understand -->
66 changes: 66 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!--
thanks for using (or contributing) to jupyak!
please fill out the following items when submitting a pull request.
-->

## what kind of request is this?

<!-- please just choose one! no request that adds a jupyak_config will be merged. -->

- [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?

<!-- please describe the steps one should follow to evaluate -->

1. go to `{readthedocs url}/_static/work/lite/lab/?path={file to open}`
2. navigate to ...
3. see ...

### where is the main discussion?

<!--
please provide a link to an issue, discussion, or other pull request
where people are talking about the feature.

the jupyak maintainers are happy to host your discussion here, but will likely
ignore them.
-->

---

<!--
feel free to delete the section below if not making changes

see the contributing guidelines for more information:
https://github.com/deathbeds/jupyak/main/CONTRIBUTING.md
-->

## for `jupyak` code changes

### references

<!--
note issue numbers this pull request addresses (should be at least one, see contributing guidelines above).

note any other pull requests that address this issue and how this pull request is different.
-->

### code changes

<!-- describe the code changes and how they address the issue. -->

### user-facing changes

<!-- describe any visual or user interaction changes and how they address the issue. -->

<!-- for visual changes, include before and after screenshots here. -->

### backwards-incompatible changes

<!-- describe any backwards-incompatible changes to jupyak public APIs. -->
176 changes: 96 additions & 80 deletions src/jupyak/tasks/_lite.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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]"
]
},
{
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
Loading