66import argparse
77import json
88import os
9+ import re
910
1011
1112def main ():
@@ -21,31 +22,32 @@ def main():
2122 with open (switcher_path ) as f :
2223 switcher = json .load (f )
2324
24- # Find index of 'latest' entry
25- latest_index = None
25+ # first we get the version number of the previous version
2626 for i , version in enumerate (switcher ):
2727 if version ["version" ] == "latest" :
2828 latest_index = i
29+ previous_version = re .search (r"latest \(([v.\d]+)\)" , version ["name" ]).group (1 )
30+ if previous_version == args .version :
31+ print (f"Version { args .version } already is the latest version. Exiting." )
32+ return
33+
34+ # now replace the name of this one with the new version
35+ switcher [i ]["name" ] = f"latest ({ args .version } )"
2936 break
30- if latest_index is None :
37+ else :
3138 raise ValueError ("'latest' version not found in switcher.json" )
3239
33- # Add the new version to the list of versions (we always insert it after latest)
34- new_version = {
35- "version" : args .version ,
36- "url" : f"https://python-visualization.github.io/folium/{ args .version } /" ,
37- }
38-
39- # Update the latest version
40- switcher [latest_index ]["url" ] = new_version ["url" ]
41-
42- # Make sure version is unique
43- if any (version ["version" ] == args .version for version in switcher ):
40+ # Add the previous version to the list of versions (we always insert it after latest)
41+ if any (version ["version" ] == previous_version for version in switcher ):
4442 print (
45- f"Version { args . version } already exists in switcher.json. Not adding it again."
43+ f"Previous version { previous_version } already exists in switcher.json. Not adding it again."
4644 )
4745 else :
48- switcher .insert (latest_index + 1 , new_version )
46+ previous_version_entry = {
47+ "version" : previous_version ,
48+ "url" : f"https://python-visualization.github.io/folium/{ previous_version } /" ,
49+ }
50+ switcher .insert (latest_index + 1 , previous_version_entry )
4951
5052 # Write the updated switcher.json
5153 with open (switcher_path , "w" ) as f :
0 commit comments