Skip to content

Commit 45e6e6d

Browse files
authored
more backport from #21 (#23)
1 parent 8af6ea6 commit 45e6e6d

File tree

5 files changed

+210
-5
lines changed

5 files changed

+210
-5
lines changed

docs/_static/jupyak-v0.schema.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,14 @@
12071207
"type": "string"
12081208
}
12091209
},
1210+
"patch_package_jsons": {
1211+
"type": "object",
1212+
"title": "patch_package_jsons",
1213+
"description": "patches to package.json to help resolvability",
1214+
"additionalProperties": {
1215+
"$ref": "#/$defs/PackageJsonPatches"
1216+
}
1217+
},
12101218
"tasks": {
12111219
"type": "object",
12121220
"title": "tasks",
@@ -1260,6 +1268,44 @@
12601268
}
12611269
}
12621270
},
1271+
"PackageJsonPatches": {
1272+
"title": "PackageJsonPatches",
1273+
"description": "a subset of package.json",
1274+
"properties": {
1275+
"dependencies": {
1276+
"type": "object",
1277+
"title": "dependencies",
1278+
"description": "dependencies to add before linking",
1279+
"additionalProperties": {
1280+
"type": "string"
1281+
}
1282+
},
1283+
"dev_dependencies": {
1284+
"type": "object",
1285+
"title": "dev_dependencies",
1286+
"description": "development dependencies to add before linking",
1287+
"additionalProperties": {
1288+
"type": "string"
1289+
}
1290+
},
1291+
"resolutions": {
1292+
"type": "object",
1293+
"title": "resolutions",
1294+
"description": "resolutions to add before linking",
1295+
"additionalProperties": {
1296+
"type": "string"
1297+
}
1298+
},
1299+
"scripts": {
1300+
"type": "object",
1301+
"title": "scripts",
1302+
"description": "scripts to overload to avoid bad effects",
1303+
"additionalProperties": {
1304+
"type": "string"
1305+
}
1306+
}
1307+
}
1308+
},
12631309
"PythonOptions": {
12641310
"title": "PythonOptions",
12651311
"description": "Python-related provisioning, building, and linking.",

docs/_static/jupyak-v0.schema.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,14 @@ description = "regular expressions for the npm `@org/pkg` names that should _not
11821182
["$defs".JSOptions.properties.link_exclude_patterns.items]
11831183
type = "string"
11841184

1185+
["$defs".JSOptions.properties.patch_package_jsons]
1186+
type = "object"
1187+
title = "patch_package_jsons"
1188+
description = "patches to package.json to help resolvability"
1189+
1190+
["$defs".JSOptions.properties.patch_package_jsons.additionalProperties]
1191+
"$ref" = "#/$defs/PackageJsonPatches"
1192+
11851193
["$defs".JSOptions.properties.tasks]
11861194
type = "object"
11871195
title = "tasks"
@@ -1225,6 +1233,42 @@ type = "string"
12251233
title = "gist"
12261234
description = "a gist ID on GitHub to use as JupyterLite contents and config"
12271235

1236+
["$defs".PackageJsonPatches]
1237+
title = "PackageJsonPatches"
1238+
description = "a subset of package.json"
1239+
1240+
["$defs".PackageJsonPatches.properties.dependencies]
1241+
type = "object"
1242+
title = "dependencies"
1243+
description = "dependencies to add before linking"
1244+
1245+
["$defs".PackageJsonPatches.properties.dependencies.additionalProperties]
1246+
type = "string"
1247+
1248+
["$defs".PackageJsonPatches.properties.dev_dependencies]
1249+
type = "object"
1250+
title = "dev_dependencies"
1251+
description = "development dependencies to add before linking"
1252+
1253+
["$defs".PackageJsonPatches.properties.dev_dependencies.additionalProperties]
1254+
type = "string"
1255+
1256+
["$defs".PackageJsonPatches.properties.resolutions]
1257+
type = "object"
1258+
title = "resolutions"
1259+
description = "resolutions to add before linking"
1260+
1261+
["$defs".PackageJsonPatches.properties.resolutions.additionalProperties]
1262+
type = "string"
1263+
1264+
["$defs".PackageJsonPatches.properties.scripts]
1265+
type = "object"
1266+
title = "scripts"
1267+
description = "scripts to overload to avoid bad effects"
1268+
1269+
["$defs".PackageJsonPatches.properties.scripts.additionalProperties]
1270+
type = "string"
1271+
12281272
["$defs".PythonOptions]
12291273
title = "PythonOptions"
12301274
description = "Python-related provisioning, building, and linking."

docs/_static/jupyak-v0.schema.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,12 @@ $defs:
905905
into this repo
906906
items:
907907
type: string
908+
patch_package_jsons:
909+
type: object
910+
title: patch_package_jsons
911+
description: patches to package.json to help resolvability
912+
additionalProperties:
913+
$ref: '#/$defs/PackageJsonPatches'
908914
tasks:
909915
type: object
910916
title: tasks
@@ -939,6 +945,34 @@ $defs:
939945
type: string
940946
title: gist
941947
description: a gist ID on GitHub to use as JupyterLite contents and config
948+
PackageJsonPatches:
949+
title: PackageJsonPatches
950+
description: a subset of package.json
951+
properties:
952+
dependencies:
953+
type: object
954+
title: dependencies
955+
description: dependencies to add before linking
956+
additionalProperties:
957+
type: string
958+
dev_dependencies:
959+
type: object
960+
title: dev_dependencies
961+
description: development dependencies to add before linking
962+
additionalProperties:
963+
type: string
964+
resolutions:
965+
type: object
966+
title: resolutions
967+
description: resolutions to add before linking
968+
additionalProperties:
969+
type: string
970+
scripts:
971+
type: object
972+
title: scripts
973+
description: scripts to overload to avoid bad effects
974+
additionalProperties:
975+
type: string
942976
PythonOptions:
943977
title: PythonOptions
944978
description: Python-related provisioning, building, and linking.

src/jupyak/tasks/_js.ipynb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,14 @@
171171
"\n",
172172
" install_deps += [yak.not_a_package_json]\n",
173173
"\n",
174+
" path_patches = {\n",
175+
" work_path / path / W.PACKAGE_JSON: patch_package_json\n",
176+
" for path, patch_package_json in js.patch_package_jsons.items()\n",
177+
" }\n",
178+
"\n",
174179
" link_deps = [yak.work_path / DEP_YML_PATTERN.format(dep) for dep in js.dependencies]\n",
175180
" install_deps += link_deps\n",
176181
" pre_install_actions = [\n",
177-
" A.git([\"reset\", \"--hard\", \"HEAD\"], in_repo),\n",
178182
" (\n",
179183
" _fix_js_resolutions,\n",
180184
" [\n",
@@ -183,12 +187,14 @@
183187
" yak.not_a_package_json,\n",
184188
" js.all_install_exclude_resolutions,\n",
185189
" js.link_exclude_patterns,\n",
190+
" path_patches,\n",
186191
" ],\n",
187192
" ),\n",
188193
" ]\n",
189194
"\n",
190195
" yield dict(\n",
191196
" name=f\"{repo.name}:yarn:install\",\n",
197+
" uptodate=[doit.tools.config_changed({\"config\": js.to_dict()})],\n",
192198
" doc=f\"> install npm dependencies of {repo.name}\",\n",
193199
" actions=[*pre_install_actions, A.run([*yak.env.run_args, \"yarn\"], in_repo)],\n",
194200
" file_dep=install_deps,\n",
@@ -250,6 +256,25 @@
250256
" )"
251257
]
252258
},
259+
{
260+
"cell_type": "code",
261+
"execution_count": null,
262+
"id": "a07c3dcf-c8eb-4372-850f-d1e23c681930",
263+
"metadata": {},
264+
"outputs": [],
265+
"source": [
266+
"def _patch_one_package_json(pkg_data: dict, patch_package_json: Y.PackageJsonPatches):\n",
267+
" sections = {\n",
268+
" \"dependencies\": patch_package_json.dependencies,\n",
269+
" \"scripts\": patch_package_json.scripts,\n",
270+
" \"devDependencies\": patch_package_json.dev_dependencies,\n",
271+
" }\n",
272+
" for section, values in sections.items():\n",
273+
" if not values:\n",
274+
" continue\n",
275+
" pkg_data[section].update(values)"
276+
]
277+
},
253278
{
254279
"cell_type": "code",
255280
"execution_count": null,
@@ -263,6 +288,7 @@
263288
" not_a_package_json: Path,\n",
264289
" install_exclude_resolutions: list[str],\n",
265290
" link_exclude_patterns: list[str],\n",
291+
" path_patches: dict[Path, Y.PackageJsonPatches],\n",
266292
"):\n",
267293
" print(f\" ... fixing resolutions for {package_json.parent.name}\")\n",
268294
" pkg_data = json.loads(package_json.read_text(encoding=\"utf-8\"))\n",
@@ -271,6 +297,11 @@
271297
" f\"\"\"link:{os.path.relpath(not_a_package_json.parent, package_json.parent)}\"\"\"\n",
272298
" )\n",
273299
"\n",
300+
" patches = path_patches.get(package_json)\n",
301+
" if patches:\n",
302+
" print(f\"\"\" ... patching {package_json.parent.name}#/{section}\"\"\")\n",
303+
" _patch_one_package_json(pkg_data, patches)\n",
304+
"\n",
274305
" for tgz_list in tgz_lists:\n",
275306
" resolutions = yaml.safe_load(tgz_list.read_text(encoding=\"utf-8\"))\n",
276307
" dest = package_json.parent.name\n",
@@ -303,6 +334,7 @@
303334
" not_a_package_json,\n",
304335
" install_exclude_resolutions,\n",
305336
" link_exclude_patterns,\n",
337+
" path_patches,\n",
306338
" )"
307339
]
308340
},

src/jupyak/tasks/_yak.ipynb

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,44 @@
644644
" return as_dict"
645645
]
646646
},
647+
{
648+
"cell_type": "markdown",
649+
"id": "c65b12e4-0b2b-4325-84ec-fc73c1569de8",
650+
"metadata": {},
651+
"source": [
652+
"a subset of package.json"
653+
]
654+
},
655+
{
656+
"cell_type": "code",
657+
"execution_count": null,
658+
"id": "3eb7d2c2-4b53-4420-9497-68dbcf277d8d",
659+
"metadata": {},
660+
"outputs": [],
661+
"source": [
662+
"class PackageJsonPatches(HasSchema):\n",
663+
" dependencies = T.Dict(\n",
664+
" key_trait=T.Unicode(),\n",
665+
" value_trait=T.Unicode(),\n",
666+
" help=\"dependencies to add before linking\",\n",
667+
" )\n",
668+
" dev_dependencies = T.Dict(\n",
669+
" key_trait=T.Unicode(),\n",
670+
" value_trait=T.Unicode(),\n",
671+
" help=\"development dependencies to add before linking\",\n",
672+
" )\n",
673+
" resolutions = T.Dict(\n",
674+
" key_trait=T.Unicode(),\n",
675+
" value_trait=T.Unicode(),\n",
676+
" help=\"resolutions to add before linking\",\n",
677+
" )\n",
678+
" scripts = T.Dict(\n",
679+
" key_trait=T.Unicode(),\n",
680+
" value_trait=T.Unicode(),\n",
681+
" help=\"scripts to overload to avoid bad effects\",\n",
682+
" )"
683+
]
684+
},
647685
{
648686
"cell_type": "markdown",
649687
"id": "e5a4859f-7fb6-4641-8945-51a4c4be01b2",
@@ -682,14 +720,25 @@
682720
" T.Unicode(),\n",
683721
" help=\"regular expressions for the npm `@org/pkg` names that should _not_ be installed, ever, in this repo\",\n",
684722
" )\n",
723+
" patch_package_jsons = T.Dict(\n",
724+
" key_trait=T.Unicode(),\n",
725+
" value_trait=InstanceDict(PackageJsonPatches),\n",
726+
" help=\"patches to package.json to help resolvability\",\n",
727+
" )\n",
685728
"\n",
686729
" def to_dict(self):\n",
687730
" as_dict = super().to_dict()\n",
688-
" all_tasks = as_dict.get(\"tasks\", {})\n",
689-
" if all_tasks:\n",
731+
" tasks = as_dict.get(\"tasks\", {})\n",
732+
" if tasks:\n",
690733
" as_dict[\"tasks\"] = {\n",
691-
" cwd: [task.to_dict() for task in path_tasks]\n",
692-
" for cwd, path_tasks in all_tasks.items()\n",
734+
" path: [path_task.to_dict() for path_task in path_tasks]\n",
735+
" for path, path_tasks in tasks.items()\n",
736+
" }\n",
737+
" patch_package_jsons = as_dict.get(\"patch_package_jsons\", {})\n",
738+
" if patch_package_jsons:\n",
739+
" as_dict[\"patch_package_jsons\"] = {\n",
740+
" path: pkg_json.to_dict()\n",
741+
" for path, pkg_json in patch_package_jsons.items()\n",
693742
" }\n",
694743
" return as_dict\n",
695744
"\n",

0 commit comments

Comments
 (0)