Skip to content

Commit 6fd70d3

Browse files
ryanking13agriyakhetarpalpre-commit-ci[bot]
authored
DOC Use pregenerated lockfile to make package list (pyodide#5036)
Co-authored-by: Agriya Khetarpal <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent fa7063b commit 6fd70d3

File tree

2 files changed

+50
-37
lines changed

2 files changed

+50
-37
lines changed

Makefile.envs

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ export PYODIDE_ABI_VERSION ?= 2024_0
55

66
export PYTHON_ARCHIVE_SHA256=73ac8fe780227bf371add8373c3079f42a0dc62deff8d612cd15a618082ab623
77

8+
# URL to the prebuilt packages
9+
export PYODIDE_PREBUILT_PACKAGES_BASE=https://github.com/pyodide/pyodide-recipes/releases/download/20250107
10+
export PYODIDE_PREBUILT_PACKAGES_URL=$(PYODIDE_PREBUILT_PACKAGES_BASE)/packages.tar.bz2
11+
export PYODIDE_PREBUILT_PACKAGES_LOCKFILE=$(PYODIDE_PREBUILT_PACKAGES_BASE)/pyodide-lock.json
12+
export ENABLE_PREBUILT_PACKAGES ?= 0
13+
814
ifdef CPYTHON_DEBUG
915
export CPYTHON_ABI_FLAGS=d
1016
endif

docs/sphinx_pyodide/sphinx_pyodide/packages.py

+44-37
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
import json
12
import pathlib
2-
import sys
3+
import re
4+
import subprocess
35
from typing import Any
6+
from urllib.request import urlopen
47

58
from docutils import nodes
69
from docutils.parsers.rst import Directive
10+
from pyodide_lock import PackageSpec, PyodideLockSpec
711
from sphinx import addnodes
812

913
base_dir = pathlib.Path(__file__).resolve().parents[3]
10-
sys.path.append(str(base_dir / "pyodide-build"))
11-
12-
from pyodide_build.io import MetaConfig
13-
14-
PYODIDE_TESTONLY = "pyodide.test"
1514

1615

1716
def get_packages_summary_directive(app):
@@ -21,56 +20,64 @@ class PyodidePackagesSummary(Directive):
2120
required_arguments = 1
2221

2322
def run(self):
24-
packages_root = base_dir / self.arguments[0]
25-
packages_list = self.get_package_metadata_list(packages_root)
23+
url = self.parse_lockfile_url()
24+
resp = urlopen(url)
25+
lockfile_json = resp.read().decode("utf-8")
26+
27+
lockfile = PyodideLockSpec(**json.loads(lockfile_json))
28+
lockfile_packages = lockfile.packages
2629

27-
packages = {}
28-
for package in packages_list:
30+
python_packages = {}
31+
for package in lockfile_packages.values():
2932
try:
30-
name, version, is_package, tag, disabled = self.parse_package_info(
31-
package
32-
)
33+
name, version, is_package = self.parse_package_info(package)
3334
except Exception:
3435
print(f"Warning: failed to parse package config for {package}")
3536

36-
# skip libraries (e.g. libxml, libyaml, ...) and test only packages
37-
if not is_package or PYODIDE_TESTONLY in tag or disabled:
37+
if not is_package or name.endswith("-tests"):
3838
continue
3939

40-
packages[name] = {
40+
python_packages[name] = {
4141
"name": name,
4242
"version": version,
4343
}
4444

4545
result = []
4646
columns = ("name", "version")
47-
table_markup = self.format_packages_table(packages, columns)
47+
table_markup = self.format_packages_table(python_packages, columns)
4848
result.extend(table_markup)
4949

5050
return result
5151

52-
def parse_package_info(
53-
self, config: pathlib.Path
54-
) -> tuple[str, str, bool, list[str], bool]:
55-
yaml_data = MetaConfig.from_yaml(config)
56-
57-
name = yaml_data.package.name
58-
version = yaml_data.package.version
59-
tag = yaml_data.package.tag
60-
is_package = yaml_data.build.package_type == "package"
61-
disabled = yaml_data.package.disabled
62-
63-
return name, version, is_package, tag, disabled
64-
65-
def get_package_metadata_list(
66-
self, directory: pathlib.Path
67-
) -> list[pathlib.Path]:
68-
"""Return metadata files of packages in alphabetical order (case insensitive)"""
69-
return sorted(
70-
directory.glob("**/meta.yaml"),
71-
key=lambda path: path.parent.name.lower(),
52+
def parse_lockfile_url(self) -> str:
53+
envs = subprocess.run(
54+
["make", "-f", str(base_dir / "Makefile.envs"), ".output_vars"],
55+
capture_output=True,
56+
text=True,
57+
env={"PYODIDE_ROOT": str(base_dir)},
58+
check=False,
7259
)
7360

61+
if envs.returncode != 0:
62+
raise RuntimeError("Failed to parse Makefile.envs")
63+
64+
pattern = re.search(r"PYODIDE_PREBUILT_PACKAGES_LOCKFILE=(.*)", envs.stdout)
65+
if not pattern:
66+
raise RuntimeError("Failed to find lockfile URL in Makefile.envs")
67+
68+
url = pattern.group(1)
69+
return url
70+
71+
def parse_package_info(
72+
self,
73+
package: PackageSpec,
74+
) -> tuple[str, str, bool]:
75+
name = package.name
76+
version = package.version
77+
is_package = package.package_type == "package"
78+
79+
return name, version, is_package
80+
7481
def format_packages_table(
7582
self, packages: dict[str, Any], columns: tuple[str, ...]
7683
) -> list[Any]:

0 commit comments

Comments
 (0)