Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
holoviz
GitHub Repository: holoviz/panel
Path: blob/main/scripts/jupyterlite/patch_lock.py
2011 views
1
import hashlib
2
import json
3
import os.path
4
5
from glob import glob
6
7
from packaging.utils import parse_wheel_filename
8
9
10
def calculate_sha256(file_path):
11
sha256_hash = hashlib.sha256()
12
13
with open(file_path, "rb") as file:
14
for byte_block in iter(lambda: file.read(4096), b""):
15
sha256_hash.update(byte_block)
16
17
return sha256_hash.hexdigest()
18
19
20
with open("package-lock.json") as f:
21
package = json.load(f)
22
pyodide_version = package["packages"]["node_modules/pyodide"]["version"]
23
24
path = "pyodide-lock.json"
25
url = f"https://cdn.jsdelivr.net/pyodide/v{pyodide_version}/full"
26
27
with open(path) as f:
28
data = json.load(f)
29
30
for p in data["packages"].values():
31
if not p["file_name"].startswith("http"):
32
p["file_name"] = f'{url}/{p["file_name"]}'
33
34
35
whl_files = glob("../../dist/*.whl")
36
for whl_file in whl_files:
37
name, version, *_ = parse_wheel_filename(os.path.basename(whl_file))
38
39
package = data["packages"][name]
40
package["version"] = str(version)
41
package["file_name"] = os.path.basename(whl_file)
42
package["sha256"] = calculate_sha256(whl_file)
43
package["imports"] = [name]
44
45
# Can be removed when micropip 0.9.0 is part of pyodide
46
bokeh_req = data["packages"]["bokeh"]["depends"]
47
if "narwhals" not in bokeh_req:
48
bokeh_req.append("narwhals")
49
50
51
with open(path, "w") as f:
52
data = json.dump(data, f)
53
54