Coverage for apio / commands / apio.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-24 01:53 +0000

1"""Apio top level click command.""" 

2 

3# -*- coding: utf-8 -*- 

4# -- This file is part of the Apio project 

5# -- (C) 2016-2019 FPGAwars 

6# -- Author Jesús Arroyo 

7# -- License GPLv2 

8 

9 

10import click 

11from click.exceptions import NoArgsIsHelpError 

12from apio.utils.cmd_util import ApioSubgroup, ApioGroup 

13from apio.utils import util 

14 

15# -- Import sub commands. 

16from apio.commands import ( 

17 apio_api, 

18 apio_boards, 

19 apio_build, 

20 apio_clean, 

21 apio_create, 

22 apio_devices, 

23 apio_docs, 

24 apio_drivers, 

25 apio_examples, 

26 apio_format, 

27 apio_fpgas, 

28 apio_graph, 

29 apio_info, 

30 apio_lint, 

31 apio_packages, 

32 apio_preferences, 

33 apio_raw, 

34 apio_report, 

35 apio_sim, 

36 apio_test, 

37 apio_upgrade, 

38 apio_upload, 

39) 

40 

41 

42# -- The subcommands of this command, grouped by category. 

43SUBGROUPS = [ 

44 ApioSubgroup( 

45 "Build commands", 

46 [ 

47 apio_build.cli, 

48 apio_upload.cli, 

49 apio_clean.cli, 

50 ], 

51 ), 

52 ApioSubgroup( 

53 "Verification commands", 

54 [ 

55 apio_lint.cli, 

56 apio_format.cli, 

57 apio_sim.cli, 

58 apio_test.cli, 

59 apio_report.cli, 

60 apio_graph.cli, 

61 ], 

62 ), 

63 ApioSubgroup( 

64 "Setup commands", 

65 [ 

66 apio_create.cli, 

67 apio_preferences.cli, 

68 apio_packages.cli, 

69 apio_drivers.cli, 

70 apio_devices.cli, 

71 ], 

72 ), 

73 ApioSubgroup( 

74 "Utility commands", 

75 [ 

76 apio_boards.cli, 

77 apio_fpgas.cli, 

78 apio_examples.cli, 

79 apio_docs.cli, 

80 apio_info.cli, 

81 apio_raw.cli, 

82 apio_api.cli, 

83 apio_upgrade.cli, 

84 ], 

85 ), 

86] 

87 

88 

89def context_settings(): 

90 """Return a common Click command settings that adds 

91 the alias -h to --help. This applies also to all the sub 

92 commands such as apio build. 

93 """ 

94 

95 # -- This causes no args help commands such as 'apio' to return 

96 # -- error code 0 instead of 2. 

97 # -- Per https://tinyurl.com/click-help-no-args-error 

98 NoArgsIsHelpError.exit_code = 0 

99 

100 # Per https://click.palletsprojects.com/en/8.1.x/documentation/ 

101 # #help-parameter-customization 

102 return {"help_option_names": ["-h", "--help"]} 

103 

104 

105# --------------------------- 

106# -- Top click command node. 

107# --------------------------- 

108 

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

110APIO_HELP = """ 

111[b]WORK WITH FPGAs WITH EASE.[/b] 

112 

113Apio is an easy to use and open-source command-line suite designed to \ 

114streamline FPGA programming. It supports a wide range of tasks, including \ 

115linting, building, simulation, unit testing, and programming FPGA boards. 

116 

117An Apio project consists of a directory containing a configuration file \ 

118named 'apio.ini', along with FPGA source files, testbenches, and pin \ 

119definition files. 

120 

121Apio commands are intuitive and perform their intended functionalities right \ 

122out of the box. For example, the command apio upload automatically compiles \ 

123the design in the current directory and uploads it to the FPGA board. 

124 

125For detailed information about any Apio command, append the -h flag to view \ 

126its help text. For example: 

127 

128[code]apio build -h 

129apio drivers ftdi install -h[/code] 

130 

131To check the apio version type: 

132[code] 

133apio --version[/code] 

134 

135For more information about the Apio project, visit the official Apio Wiki \ 

136https://github.com/FPGAwars/apio/wiki/Apio 

137""" 

138 

139 

140@click.group( 

141 name="apio", 

142 cls=ApioGroup, 

143 subgroups=SUBGROUPS, 

144 help=APIO_HELP, 

145 short_help="Work with FPGAs with ease", 

146 context_settings=context_settings(), 

147) 

148# NOTE: Without this explicit version value, click has difficulty 

149# determining the version when running under pyinstaller. 

150@click.version_option(util.get_apio_version_str(), "-v", "--version") 

151def apio_top_cli(): 

152 """The top level command group of apio commands""" 

153 

154 # pass