MCPcopy Create free account
hub / github.com/python-visualization/folium / main

Function main

docs/update_switcher.py:11–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9
10
11def main():
12 # Define CLI arguments
13 parser = argparse.ArgumentParser(description="Update switcher.json")
14 parser.add_argument(
15 "--version", "-v", required=True, type=str, help="The new version to add"
16 )
17 args = parser.parse_args()
18 # drop the "v" prefix
19 new_version_without_prefix = args.version[1:]
20
21 # Setup path to switcher.json (relative to this script) and load it
22 switcher_path = os.path.join(os.path.dirname(__file__), "_static", "switcher.json")
23 with open(switcher_path) as f:
24 switcher = json.load(f)
25
26 # first we get the version number of the previous version
27 for i, version in enumerate(switcher):
28 if version.get("name", "").startswith("latest"):
29 latest_index = i
30 previous_version = version["version"]
31 if previous_version == new_version_without_prefix:
32 print(
33 f"Version {new_version_without_prefix} already is the latest version. Exiting."
34 )
35 return
36
37 # now replace the name and version of this one with the new version
38 switcher[i]["name"] = f"latest ({new_version_without_prefix})"
39 switcher[i]["version"] = new_version_without_prefix
40 break
41 else:
42 raise ValueError("'latest' version not found in switcher.json")
43
44 # Add the previous version to the list of versions (we always insert it after latest)
45 if any(version["version"] == previous_version for version in switcher):
46 print(
47 f"Previous version {previous_version} already exists in switcher.json. Not adding it again."
48 )
49 else:
50 previous_version_entry = {
51 "version": previous_version,
52 "url": f"https://python-visualization.github.io/folium/v{previous_version}/",
53 }
54 switcher.insert(latest_index + 1, previous_version_entry)
55
56 # Write the updated switcher.json
57 with open(switcher_path, "w") as f:
58 json.dump(switcher, f, indent=2)
59
60
61if __name__ == "__main__":

Callers 1

update_switcher.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…