102
102
103
103
104
104
# =============================================
105
-
# Data structures used in our requirements.json
105
+
# Data structures used in our shinylive_requirements.json
106
106
# =============================================
107
107
class RequirementsPackage(TypedDict):
108
108
name: str
@@ -111,7 +111,7 @@ class RequirementsPackage(TypedDict):
111
111
112
112
113
113
# ====================================================
114
-
# Data structures used in our extra_packages_lock.json
114
+
# Data structures used in our shinylive_lock.json
115
115
# ====================================================
116
116
class LockfileDependency(TypedDict):
117
117
name: str
@@ -214,6 +214,15 @@ class PyodidePackagesFile(TypedDict):
214
214
packages: dict[str, PyodidePackageInfo]
215
215
216
216
217
+
# =================================================
218
+
# Internal data structures
219
+
# =================================================
220
+
# This BasicPackageInfo type is used internally for package resolution.
221
+
class BasicPackageInfo(TypedDict):
222
+
name: str
223
+
depends: list[str]
224
+
225
+
217
226
# =============================================================================
218
227
# Functions for generating the lockfile from the requirements file.
219
228
# =============================================================================
@@ -241,6 +250,16 @@ def update_lockfile_local() -> None:
241
250
242
251
lockfile_info.update(required_package_info)
243
252
253
+
# If any dependencies in the lockfile_info are not in the union of {lockfile_info,
254
+
# orig_pyodide_lock()["packages"]}, then we need to add them to the lockfile_info.
255
+
# This can happen when a local package adds a new dependency.
256
+
print("Searching for new dependencies")
257
+
# basic_package_info is the union of lockfile_info and original pyodide packages.
258
+
basic_package_info = _to_basic_package_info(lockfile_info)
259
+
basic_package_info.update(_to_basic_package_info(orig_pyodide_lock()["packages"]))
260
+
_recurse_dependencies_lockfile(lockfile_info, basic_package_info)
261
+
262
+
print(f"Writing {package_lock_file}")
244
263
with open(package_lock_file, "w") as f:
245
264
json.dump(
246
265
_mark_no_indent(lockfile_info, _is_lockfile_dependency),
@@ -277,12 +296,15 @@ def generate_lockfile() -> None:
277
296
278
297
def _recurse_dependencies_lockfile(
279
298
pkgs: dict[str, LockfilePackageInfo],
299
+
pyodide_packages_info: dict[str, BasicPackageInfo] | None = None,
280
300
) -> None:
281
301
"""
282
302
Recursively find all dependencies of the given packages. This will mutate the object
283
303
passed in.
284
304
"""
285
-
pyodide_packages_info = orig_pyodide_lock()["packages"]
305
+
if pyodide_packages_info is None:
306
+
pyodide_packages_info = _to_basic_package_info(orig_pyodide_lock()["packages"])
307
+
286
308
i = 0
287
309
while i < len(pkgs):
288
310
pkg_info = pkgs[list(pkgs.keys())[i]]
@@ -506,6 +528,35 @@ def _dep_filter(dep_str: str) -> bool:
506
528
return list(res)
507
529
508
530
531
+
def _to_basic_package_info(
532
+
packages: dict[str, PyodidePackageInfo] | dict[str, LockfilePackageInfo]
533
+
) -> dict[str, BasicPackageInfo]:
534
+
"""
535
+
Convert Pyodide package information to a simplified format.
536
+
537
+
Args:
538
+
packages (dict[str, PyodidePackageInfo]): Original package information from Pyodide lock file
539
+
540
+
Returns:
541
+
dict[str, BasicPackageInfo]: Simplified package information with name and depends
542
+
"""
543
+
basic_info: dict[str, BasicPackageInfo] = {}
544
+
for pkg_name, pkg_data in packages.items():
545
+
depends = pkg_data["depends"]
546
+
depends_str_list: list[str] = []
547
+
for dep in depends:
548
+
if isinstance(dep, str):
549
+
depends_str_list.append(dep)
550
+
else:
551
+
depends_str_list.append(dep["name"])
552
+
553
+
basic_info[pkg_name.lower()] = {
554
+
"name": pkg_name,
555
+
"depends": depends_str_list,
556
+
}
557
+
return basic_info
558
+
559
+
509
560
# =============================================================================
510
561
# Functions for copying and downloading the wheel files.
511
562
# =============================================================================
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4