MCPcopy
hub / github.com/pyodide/pyodide / get_lockfile_url_from_makefile

Function get_lockfile_url_from_makefile

tools/create_lockfile_diff.py:42–110  ·  view source on GitHub ↗

Get the PYODIDE_PREBUILT_PACKAGES_LOCKFILE URL from the Makefile. Args: branch: If provided, get the URL from this git branch. If None, use the current branch. Returns: The URL to the lockfile.

(branch: str | None = None)

Source from the content-addressed store, hash-verified

40
41
42def get_lockfile_url_from_makefile(branch: str | None = None) -> str:
43 """
44 Get the PYODIDE_PREBUILT_PACKAGES_LOCKFILE URL from the Makefile.
45
46 Args:
47 branch: If provided, get the URL from this git branch. If None, use the current branch.
48
49 Returns:
50 The URL to the lockfile.
51 """
52 if branch:
53 # Get the Makefile.envs content from the specified branch
54 result = subprocess.run(
55 ["git", "show", f"{branch}:Makefile.envs"],
56 capture_output=True,
57 text=True,
58 check=True,
59 )
60 makefile_content = result.stdout
61
62 # First pass: collect all variable definitions
63 variables = {}
64 for line in makefile_content.split("\n"):
65 line = line.strip()
66 if line.startswith("export ") and "=" in line:
67 # Remove 'export ' prefix and split on first '='
68 var_line = line[7:] # Remove 'export '
69 var_name, var_value = var_line.split("=", 1)
70 variables[var_name.strip()] = var_value.strip()
71
72 # Second pass: resolve variable references
73 import re
74
75 max_iterations = 10 # Prevent infinite loops
76 for _ in range(max_iterations):
77 changed = False
78 for var_name, var_value in list(variables.items()):
79 for match in re.finditer(r"\$\(([^)]+)\)", var_value):
80 ref_var = match.group(1)
81 if ref_var in variables:
82 new_value = var_value.replace(
83 match.group(0), variables[ref_var]
84 )
85 if new_value != var_value:
86 variables[var_name] = new_value
87 changed = True
88 if not changed:
89 break
90
91 if "PYODIDE_PREBUILT_PACKAGES_LOCKFILE" not in variables:
92 raise ValueError(
93 f"Could not find PYODIDE_PREBUILT_PACKAGES_LOCKFILE in {branch} branch"
94 )
95
96 return variables["PYODIDE_PREBUILT_PACKAGES_LOCKFILE"]
97 else:
98 # Get the URL from the current branch using make env
99 result = subprocess.run(

Callers 1

get_lockfile_pathFunction · 0.85

Calls 2

itemsMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…