Coverage for apio/commands/apio_docs.py: 50%

18 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-07 05:08 +0000

1# This file is part of the Apio project 

2# (C) 2016-present FPGAwars 

3# Project authors: 

4# * Jesús Arroyo (Jesus89) (2016-2019) 

5# * Juan Gonzalez (obijuan) (2019-2024) 

6# * The Apio Team (2024-present) 

7# License: GPLv2 

8 

9"""Implementation of 'apio format' command""" 

10 

11import webbrowser 

12import click 

13from apio.common.apio_console import cout 

14from apio.apio_context import ( 

15 ApioContext, 

16 PackagesPolicy, 

17 ProjectPolicy, 

18 RemoteConfigPolicy, 

19) 

20from apio.utils import cmd_util 

21 

22 

23# -------------- apio format 

24 

25# -- Text in the rich-text format of the python rich library. 

26APIO_DOCS_HELP = """ 

27The command 'apio docs' opens the Apio documentation using the user's \ 

28default browser. 

29 

30Examples:[code] 

31 apio docs # Open the apio docs. 

32 apio docs --commands # Land on the commands list page. 

33""" 

34 

35commands_option = click.option( 

36 "commands", # Var name. 

37 "-c", 

38 "--commands", 

39 is_flag=True, 

40 help="Show the commands page.", 

41 cls=cmd_util.ApioOption, 

42) 

43 

44 

45@click.command( 

46 name="docs", 

47 cls=cmd_util.ApioCommand, 

48 short_help="Show Apio documentation.", 

49 help=APIO_DOCS_HELP, 

50) 

51@commands_option 

52def cli( 

53 *, 

54 # Options 

55 commands, 

56): 

57 """Implements the docs command which opens the apio documentation in 

58 the default browser. 

59 """ 

60 

61 # -- Create an apio context with a project object. 

62 _ = ApioContext( 

63 project_policy=ProjectPolicy.NO_PROJECT, 

64 remote_config_policy=RemoteConfigPolicy.CACHED_OK, 

65 packages_policy=PackagesPolicy.IGNORE_PACKAGES, 

66 ) 

67 

68 url = "https://fpgawars.github.io/apio/docs" 

69 

70 if commands: 

71 url += "/commands-list" 

72 

73 cout(f"URL: {url}") 

74 cout("Opening default browser") 

75 

76 default_browser = webbrowser.get() 

77 default_browser.open(url)