1717def usage ():
1818 print ("Usage: repartition-index.py [-i options <FILENAME> ...] [options <OUTPUT> ...]" )
1919 print ()
20- print (" -i <FILENAME> One or more files to read existing entries from." )
20+ print (" --windows-default Implies default output files and configurations." )
21+ print ()
22+ print (" -i <FILENAME> One or more files or URLs to read existing entries from." )
2123 print (" -i -n/--no-recurse Do not follow 'next' info" )
24+ print ("If no files are provided, uses the current online index" )
2225 print ()
2326 print (" <OUTPUT> Filename to write entries into" )
2427 print (" -d/--allow-dup Include entries written in previous outputs" )
28+ print (" --only-dup Only include entries written in previous outputs" )
2529 print (" --pre Include entries marked as prereleases" )
26- print (" -t/--tag TAG Include entries matching the specified tag " )
27- print (" -r/--range RANGE Include entries included within the specified range" )
28- print (" --latest-micro Include entries that are the latest x.y.z version" )
30+ print (" -t/--tag TAG Include only the specified tags (comma-separated) " )
31+ print (" -r/--range RANGE Include only the specified range (comma-separated) " )
32+ print (" --latest-micro Include only the latest x.y.z version" )
2933 print ()
3034 print ("An output of 'nul' is permitted to drop entries." )
3135 print ("Providing the same inputs and outputs is permitted, as all inputs are read" )
@@ -80,12 +84,14 @@ def _sort_key(self, v):
8084
8185 def execute (self , versions , context ):
8286 versions .sort (key = self ._sort_key )
87+ print ("Processing {} entries" .format (len (versions )))
8388
8489
8590class SplitToFile :
8691 def __init__ (self ):
8792 self .target = None
8893 self .allow_dup = False
94+ self .only_dup = False
8995 self .pre = False
9096 self .tag_or_range = None
9197 self ._expect_tag_or_range = False
@@ -102,6 +108,10 @@ def add_arg(self, arg):
102108 if arg in ("-d" , "--allow-dup" ):
103109 self .allow_dup = True
104110 return False
111+ if arg == "--only-dup" :
112+ self .allow_dup = True
113+ self .only_dup = True
114+ return False
105115 if arg == "--pre" :
106116 self .pre = True
107117 return False
@@ -115,6 +125,7 @@ def add_arg(self, arg):
115125
116126 def execute (self , versions , context ):
117127 written = context .setdefault ("written" , set ())
128+ written_now = set ()
118129 outputs = context .setdefault ("outputs" , {})
119130 if self .target != "nul" :
120131 try :
@@ -131,6 +142,9 @@ def execute(self, versions, context):
131142 for i in versions :
132143 k = i ["id" ].casefold (), i ["sort-version" ].casefold ()
133144 v = Version (i ["sort-version" ])
145+ if self .only_dup and k not in written_now :
146+ written_now .add (k )
147+ continue
134148 if not self .allow_dup and k in written :
135149 continue
136150 if not self .pre and v .is_prerelease :
@@ -145,8 +159,8 @@ def execute(self, versions, context):
145159 if k2 in latest_micro_skip :
146160 continue
147161 latest_micro_skip .add (k2 )
148- output .append (i )
149162 written .add (k )
163+ output .append (i )
150164
151165
152166class WriteFiles :
@@ -173,6 +187,9 @@ def execute(self, versions, context):
173187 data ["next" ] = next_target
174188 with open (target , "w" , encoding = "utf-8" ) as f :
175189 json .dump (data , f , indent = self .indent )
190+ print ("Wrote {} ({} entries, {} bytes)" .format (
191+ target , len (data ["versions" ]), Path (target ).stat ().st_size
192+ ))
176193
177194
178195def parse_cli (args ):
@@ -182,7 +199,16 @@ def parse_cli(args):
182199 action = None
183200 write = WriteFiles ()
184201 for a in args :
185- if a == "-i" :
202+ if a == "--windows-default" :
203+ plan_split = [SplitToFile (), SplitToFile (), SplitToFile ()]
204+ plan_split [0 ].target = "index-windows.json"
205+ plan_split [1 ].target = "index-windows-recent.json"
206+ plan_split [2 ].target = "index-windows-legacy.json"
207+ plan_split [0 ].pre = plan_split [1 ].pre = plan_split [2 ].pre = True
208+ plan_split [0 ].latest_micro = True
209+ plan_split [0 ].tag_or_range = tag_or_range (">=3.11.0" )
210+ plan_split [1 ].tag_or_range = tag_or_range (">=3.11.0" )
211+ elif a == "-i" :
186212 action = ReadFile ()
187213 plan_read .append (action )
188214 elif a .startswith ("-s-" ):
@@ -200,6 +226,12 @@ def parse_cli(args):
200226 except ValueError :
201227 pass
202228 usage ()
229+ if not plan_read :
230+ action = ReadFile ()
231+ action .source = "https://www.python.org/ftp/python/index-windows.json"
232+ plan_read .append (action )
233+ if not plan_split :
234+ usage ()
203235 return [* plan_read , sort , * plan_split , write ]
204236
205237
0 commit comments