Skip to content

Commit

Permalink
add patch_package_jsons
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl committed Dec 12, 2023
1 parent 9877b37 commit 2f5efe9
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 5 deletions.
46 changes: 46 additions & 0 deletions docs/_static/jupyak-v0.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,14 @@
"type": "string"
}
},
"patch_package_jsons": {
"type": "object",
"title": "patch_package_jsons",
"description": "patches to package.json to help resolvability",
"additionalProperties": {
"$ref": "#/$defs/PackageJsonPatches"
}
},
"tasks": {
"type": "object",
"title": "tasks",
Expand Down Expand Up @@ -1260,6 +1268,44 @@
}
}
},
"PackageJsonPatches": {
"title": "PackageJsonPatches",
"description": "a subset of package.json",
"properties": {
"dependencies": {
"type": "object",
"title": "dependencies",
"description": "dependencies to add before linking",
"additionalProperties": {
"type": "string"
}
},
"dev_dependencies": {
"type": "object",
"title": "dev_dependencies",
"description": "development dependencies to add before linking",
"additionalProperties": {
"type": "string"
}
},
"resolutions": {
"type": "object",
"title": "resolutions",
"description": "resolutions to add before linking",
"additionalProperties": {
"type": "string"
}
},
"scripts": {
"type": "object",
"title": "scripts",
"description": "scripts to overload to avoid bad effects",
"additionalProperties": {
"type": "string"
}
}
}
},
"PythonOptions": {
"title": "PythonOptions",
"description": "Python-related provisioning, building, and linking.",
Expand Down
44 changes: 44 additions & 0 deletions docs/_static/jupyak-v0.schema.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,14 @@ description = "regular expressions for the npm `@org/pkg` names that should _not
["$defs".JSOptions.properties.link_exclude_patterns.items]
type = "string"

["$defs".JSOptions.properties.patch_package_jsons]
type = "object"
title = "patch_package_jsons"
description = "patches to package.json to help resolvability"

["$defs".JSOptions.properties.patch_package_jsons.additionalProperties]
"$ref" = "#/$defs/PackageJsonPatches"

["$defs".JSOptions.properties.tasks]
type = "object"
title = "tasks"
Expand Down Expand Up @@ -1225,6 +1233,42 @@ type = "string"
title = "gist"
description = "a gist ID on GitHub to use as JupyterLite contents and config"

["$defs".PackageJsonPatches]
title = "PackageJsonPatches"
description = "a subset of package.json"

["$defs".PackageJsonPatches.properties.dependencies]
type = "object"
title = "dependencies"
description = "dependencies to add before linking"

["$defs".PackageJsonPatches.properties.dependencies.additionalProperties]
type = "string"

["$defs".PackageJsonPatches.properties.dev_dependencies]
type = "object"
title = "dev_dependencies"
description = "development dependencies to add before linking"

["$defs".PackageJsonPatches.properties.dev_dependencies.additionalProperties]
type = "string"

["$defs".PackageJsonPatches.properties.resolutions]
type = "object"
title = "resolutions"
description = "resolutions to add before linking"

["$defs".PackageJsonPatches.properties.resolutions.additionalProperties]
type = "string"

["$defs".PackageJsonPatches.properties.scripts]
type = "object"
title = "scripts"
description = "scripts to overload to avoid bad effects"

["$defs".PackageJsonPatches.properties.scripts.additionalProperties]
type = "string"

["$defs".PythonOptions]
title = "PythonOptions"
description = "Python-related provisioning, building, and linking."
Expand Down
34 changes: 34 additions & 0 deletions docs/_static/jupyak-v0.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,12 @@ $defs:
into this repo
items:
type: string
patch_package_jsons:
type: object
title: patch_package_jsons
description: patches to package.json to help resolvability
additionalProperties:
$ref: '#/$defs/PackageJsonPatches'
tasks:
type: object
title: tasks
Expand Down Expand Up @@ -939,6 +945,34 @@ $defs:
type: string
title: gist
description: a gist ID on GitHub to use as JupyterLite contents and config
PackageJsonPatches:
title: PackageJsonPatches
description: a subset of package.json
properties:
dependencies:
type: object
title: dependencies
description: dependencies to add before linking
additionalProperties:
type: string
dev_dependencies:
type: object
title: dev_dependencies
description: development dependencies to add before linking
additionalProperties:
type: string
resolutions:
type: object
title: resolutions
description: resolutions to add before linking
additionalProperties:
type: string
scripts:
type: object
title: scripts
description: scripts to overload to avoid bad effects
additionalProperties:
type: string
PythonOptions:
title: PythonOptions
description: Python-related provisioning, building, and linking.
Expand Down
3 changes: 3 additions & 0 deletions jupyak_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ link_exclude_patterns = [
"^@jupyterlab/(debugger(-extension)?|extensionmanager(-extension)?|hub-extension|nbconvert-css|pluginmanager-extension|terminal(-extension)?|template)$",
"^@jupyter-notebook/(documentsearch-extension|lab-extension|terminal-extension)$",
]

[repos.jupyterlite.js.patch_package_jsons."app/lab"]
dependencies = { "@jupyterlab/celltags-extension" = "*" }
34 changes: 33 additions & 1 deletion src/jupyak/tasks/_js.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,14 @@
"\n",
" install_deps += [yak.not_a_package_json]\n",
"\n",
" path_patches = {\n",
" work_path / path / W.PACKAGE_JSON: patch_package_json\n",
" for path, patch_package_json in js.patch_package_jsons.items()\n",
" }\n",
"\n",
" link_deps = [yak.work_path / DEP_YML_PATTERN.format(dep) for dep in js.dependencies]\n",
" install_deps += link_deps\n",
" pre_install_actions = [\n",
" A.git([\"reset\", \"--hard\", \"HEAD\"], in_repo),\n",
" (\n",
" _fix_js_resolutions,\n",
" [\n",
Expand All @@ -183,12 +187,14 @@
" yak.not_a_package_json,\n",
" js.all_install_exclude_resolutions,\n",
" js.link_exclude_patterns,\n",
" path_patches,\n",
" ],\n",
" ),\n",
" ]\n",
"\n",
" yield dict(\n",
" name=f\"{repo.name}:yarn:install\",\n",
" uptodate=[doit.tools.config_changed({\"config\": js.to_dict()})],\n",
" doc=f\"> install npm dependencies of {repo.name}\",\n",
" actions=[*pre_install_actions, A.run([*yak.env.run_args, \"yarn\"], in_repo)],\n",
" file_dep=install_deps,\n",
Expand Down Expand Up @@ -250,6 +256,25 @@
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a07c3dcf-c8eb-4372-850f-d1e23c681930",
"metadata": {},
"outputs": [],
"source": [
"def _patch_one_package_json(pkg_data: dict, patch_package_json: Y.PackageJsonPatches):\n",
" sections = {\n",
" \"dependencies\": patch_package_json.dependencies,\n",
" \"scripts\": patch_package_json.scripts,\n",
" \"devDependencies\": patch_package_json.dev_dependencies,\n",
" }\n",
" for section, values in sections.items():\n",
" if not values:\n",
" continue\n",
" pkg_data[section].update(values)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -263,6 +288,7 @@
" not_a_package_json: Path,\n",
" install_exclude_resolutions: list[str],\n",
" link_exclude_patterns: list[str],\n",
" path_patches: dict[Path, Y.PackageJsonPatches],\n",
"):\n",
" print(f\" ... fixing resolutions for {package_json.parent.name}\")\n",
" pkg_data = json.loads(package_json.read_text(encoding=\"utf-8\"))\n",
Expand All @@ -271,6 +297,11 @@
" f\"\"\"link:{os.path.relpath(not_a_package_json.parent, package_json.parent)}\"\"\"\n",
" )\n",
"\n",
" patches = path_patches.get(package_json)\n",
" if patches:\n",
" print(f\"\"\" ... patching {package_json.parent.name}#/{section}\"\"\")\n",
" _patch_one_package_json(pkg_data, patches)\n",
"\n",
" for tgz_list in tgz_lists:\n",
" resolutions = yaml.safe_load(tgz_list.read_text(encoding=\"utf-8\"))\n",
" dest = package_json.parent.name\n",
Expand Down Expand Up @@ -303,6 +334,7 @@
" not_a_package_json,\n",
" install_exclude_resolutions,\n",
" link_exclude_patterns,\n",
" path_patches,\n",
" )"
]
},
Expand Down
57 changes: 53 additions & 4 deletions src/jupyak/tasks/_yak.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,44 @@
" return as_dict"
]
},
{
"cell_type": "markdown",
"id": "c65b12e4-0b2b-4325-84ec-fc73c1569de8",
"metadata": {},
"source": [
"a subset of package.json"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3eb7d2c2-4b53-4420-9497-68dbcf277d8d",
"metadata": {},
"outputs": [],
"source": [
"class PackageJsonPatches(HasSchema):\n",
" dependencies = T.Dict(\n",
" key_trait=T.Unicode(),\n",
" value_trait=T.Unicode(),\n",
" help=\"dependencies to add before linking\",\n",
" )\n",
" dev_dependencies = T.Dict(\n",
" key_trait=T.Unicode(),\n",
" value_trait=T.Unicode(),\n",
" help=\"development dependencies to add before linking\",\n",
" )\n",
" resolutions = T.Dict(\n",
" key_trait=T.Unicode(),\n",
" value_trait=T.Unicode(),\n",
" help=\"resolutions to add before linking\",\n",
" )\n",
" scripts = T.Dict(\n",
" key_trait=T.Unicode(),\n",
" value_trait=T.Unicode(),\n",
" help=\"scripts to overload to avoid bad effects\",\n",
" )"
]
},
{
"cell_type": "markdown",
"id": "e5a4859f-7fb6-4641-8945-51a4c4be01b2",
Expand Down Expand Up @@ -682,14 +720,25 @@
" T.Unicode(),\n",
" help=\"regular expressions for the npm `@org/pkg` names that should _not_ be installed, ever, in this repo\",\n",
" )\n",
" patch_package_jsons = T.Dict(\n",
" key_trait=T.Unicode(),\n",
" value_trait=InstanceDict(PackageJsonPatches),\n",
" help=\"patches to package.json to help resolvability\",\n",
" )\n",
"\n",
" def to_dict(self):\n",
" as_dict = super().to_dict()\n",
" all_tasks = as_dict.get(\"tasks\", {})\n",
" if all_tasks:\n",
" tasks = as_dict.get(\"tasks\", {})\n",
" if tasks:\n",
" as_dict[\"tasks\"] = {\n",
" cwd: [task.to_dict() for task in path_tasks]\n",
" for cwd, path_tasks in all_tasks.items()\n",
" path: [path_task.to_dict() for path_task in path_tasks]\n",
" for path, path_tasks in tasks.items()\n",
" }\n",
" patch_package_jsons = as_dict.get(\"patch_package_jsons\", {})\n",
" if patch_package_jsons:\n",
" as_dict[\"patch_package_jsons\"] = {\n",
" path: pkg_json.to_dict()\n",
" for path, pkg_json in patch_package_jsons.items()\n",
" }\n",
" return as_dict\n",
"\n",
Expand Down

0 comments on commit 2f5efe9

Please sign in to comment.