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,34 @@ 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 (
30
+ r"latest \(([v.\d]+)\)" , version ["name" ]
31
+ ).group (1 )
32
+ if previous_version == args .version :
33
+ print (f"Version { args .version } already is the latest version. Exiting." )
34
+ return
35
+
36
+ # now replace the name of this one with the new version
37
+ switcher [i ]["name" ] = f"latest ({ args .version } )"
29
38
break
30
- if latest_index is None :
39
+ else :
31
40
raise ValueError ("'latest' version not found in switcher.json" )
32
41
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 ):
42
+ # Add the previous version to the list of versions (we always insert it after latest)
43
+ if any (version ["version" ] == previous_version for version in switcher ):
44
44
print (
45
- f"Version { args . version } already exists in switcher.json. Not adding it again."
45
+ f"Previous version { previous_version } already exists in switcher.json. Not adding it again."
46
46
)
47
47
else :
48
- switcher .insert (latest_index + 1 , new_version )
48
+ previous_version_entry = {
49
+ "version" : previous_version ,
50
+ "url" : f"https://python-visualization.github.io/folium/{ previous_version } /" ,
51
+ }
52
+ switcher .insert (latest_index + 1 , previous_version_entry )
49
53
50
54
# Write the updated switcher.json
51
55
with open (switcher_path , "w" ) as f :
0 commit comments