11import argparse
22import json
3+ import re
34import sys
5+ from base64 import b64decode
46from concurrent .futures import ThreadPoolExecutor
57from pathlib import Path
68
@@ -11,12 +13,31 @@ def read_json(path):
1113 return path .stem , data ["feedstocks" ]
1214
1315
14- def main (sources_dir , output_json ):
16+ def fetch_cdts ():
17+ import requests
18+
19+ r = requests .get ("https://api.github.com/repos/conda-forge/cdt-builds/contents/README.md" )
20+ r .raise_for_status ()
21+ data = r .json ()
22+ text = b64decode (data ["content" ]).decode ()
23+ seen = set ()
24+ for result in re .finditer (r"\(https://anaconda\.org/conda-forge/([a-z0-9_\-\.\+]+)\)" , text ):
25+ if result and result .group (1 ) not in seen :
26+ seen .add (result .group (1 ))
27+ yield result .group (1 )
28+
29+
30+ def main (sources_dir , output_json , with_cdts = False ):
1531 jsons = Path (sources_dir ).glob ("**/*.json" )
1632
1733 with ThreadPoolExecutor (4 ) as executor :
1834 all_packages = {pkg : repos for (pkg , repos ) in executor .map (read_json , jsons )}
1935 print (f"Processed { len (all_packages )} packages." )
36+
37+ if with_cdts :
38+ for cdt in fetch_cdts ():
39+ all_packages .setdefault (cdt , []).append ("cdt-builds" )
40+
2041 output_json = Path (output_json )
2142 output_json .parent .mkdir (exist_ok = True , parents = True )
2243 with open (output_json , "w" ) as f :
@@ -27,6 +48,7 @@ def main(sources_dir, output_json):
2748 parser = argparse .ArgumentParser ()
2849 parser .add_argument ("sources_dir" )
2950 parser .add_argument ("output_json" )
51+ parser .add_argument ("--with-cdts" , action = "store_true" )
3052 args = parser .parse_args ()
3153
32- sys .exit (main (args .sources_dir , args .output_json ))
54+ sys .exit (main (args .sources_dir , args .output_json , with_cdts = args . with_cdts ))
0 commit comments