6
6
import argparse
7
7
import json
8
8
import os
9
+ import re
9
10
10
11
11
12
def main ():
@@ -21,31 +22,32 @@ def main():
21
22
with open (switcher_path ) as f :
22
23
switcher = json .load (f )
23
24
24
- # Find index of 'latest' entry
25
- latest_index = None
25
+ # first we get the version number of the previous version
26
26
for i , version in enumerate (switcher ):
27
27
if version ["version" ] == "latest" :
28
28
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 } )"
29
36
break
30
- if latest_index is None :
37
+ else :
31
38
raise ValueError ("'latest' version not found in switcher.json" )
32
39
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 ):
44
42
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."
46
44
)
47
45
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 )
49
51
50
52
# Write the updated switcher.json
51
53
with open (switcher_path , "w" ) as f :
0 commit comments