Coverage for src/ensembl/utils/docs/switcher.py: 100%

2 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-09 09:43 +0000

1# See the NOTICE file distributed with this work for additional information 

2# regarding copyright ownership. 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15"""Update the switcher JSON file with a new version entry. 

16 

17Adds a new version to the PyData Sphinx Theme version switcher dropdown. 

18Usage: `update_docs_switcher --base-url <base_url> --version <version> <path_to_switcher_json>` 

19 

20""" 

21 

22import json 

23 

24from ensembl.utils import argparse 

25 

26 

27def main() -> None: 

28 """Script's main entry point.""" 

29 parser = argparse.ArgumentParser(description=__doc__) 

30 parser.add_argument("--base-url", required=True, help="Base URL of the documentation site") 

31 parser.add_argument("--version", required=True, help="Version to add to the switcher") 

32 parser.add_argument_src_path("switcher", help="Path to the switcher JSON file") 

33 args = parser.parse_args() 

34 # Avoid duplicates and remove "(latest)" from last version 

35 versions = json.loads(args.switcher.read_text()) if args.switcher.exists() else [] 

36 versions = [v for v in versions if v["version"] != args.version] 

37 if versions: 

38 versions[0]["name"] = versions[0]["version"] 

39 new_entry = { 

40 "name": f"{args.version} (latest)", 

41 "version": args.version, 

42 "url": f"{args.base_url.rstrip('/')}/{args.version}/", 

43 } 

44 versions.insert(0, new_entry) 

45 args.switcher.write_text(json.dumps(versions, indent=2))