/ .github / utils / update_haystack_dc_custom_nodes.py
update_haystack_dc_custom_nodes.py
 1  #!/usr/bin/env python3
 2  """
 3  Update the haystack-ai version in the deepset-cloud-custom-nodes uv.lock file.
 4  
 5  Fetches sdist/wheel hashes from PyPI and updates the haystack-ai package entry,
 6  preserving the existing lock file formatting.
 7  """
 8  
 9  import argparse
10  import json
11  import sys
12  import urllib.request
13  
14  import tomlkit
15  
16  if __name__ == "__main__":
17      parser = argparse.ArgumentParser()
18      parser.add_argument("version", help="Version to update to (e.g. 2.26.1-rc1)")
19      parser.add_argument("lock_file", help="Path to uv.lock")
20      args = parser.parse_args()
21  
22      # PEP 440 normalized version for filenames
23      new_version = args.version.replace("-", "")
24  
25      # Fetch hashes from PyPI
26      pypi_data = json.load(urllib.request.urlopen(f"https://pypi.org/pypi/haystack-ai/{args.version}/json"))
27      sdist_sha = wheel_sha = None
28      for u in pypi_data["urls"]:
29          if u["packagetype"] == "sdist":
30              sdist_sha = u["digests"]["sha256"]
31          elif u["packagetype"] == "bdist_wheel":
32              wheel_sha = u["digests"]["sha256"]
33      if not sdist_sha or not wheel_sha:
34          sys.exit("Could not find sdist or wheel hashes on PyPI")
35  
36      with open(args.lock_file) as f:
37          data = tomlkit.load(f)
38  
39      found = False
40      for pkg in data["package"]:
41          if pkg["name"] == "haystack-ai":
42              old_version = pkg["version"]
43  
44              pkg["version"] = new_version
45  
46              pkg["sdist"]["url"] = pkg["sdist"]["url"].replace(old_version, new_version)
47              pkg["sdist"]["hash"] = f"sha256:{sdist_sha}"
48  
49              wheel = pkg["wheels"][0]
50              wheel["url"] = wheel["url"].replace(old_version, new_version)
51              wheel["hash"] = f"sha256:{wheel_sha}"
52  
53              found = True
54              print(f"Updated haystack-ai from {old_version} to {new_version}")
55              break
56  
57      if not found:
58          sys.exit("haystack-ai package not found in uv.lock")
59  
60      with open(args.lock_file, "w") as f:
61          tomlkit.dump(data, f)