Coverage for src/pytribeam/command_line.py: 0%

41 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2026-06-16 18:30 +0000

1""" 

2Command Line Entry Points Module 

3================================ 

4 

5This module provides command line entry points for various functions and utilities. 

6It serves as the interface between the command line and the underlying functionality 

7of the application. 

8""" 

9 

10from typing import Final 

11import argparse 

12from pathlib import Path 

13 

14# import pkg_resources # part of setup tools 

15from importlib.metadata import version 

16import pytribeam.constants as cs 

17import pytribeam.GUI.runner as runner 

18import pytribeam.workflow as workflow 

19 

20CLI_DOCS: Final[str] = """ 

21-------- 

22pytribeam 

23-------- 

24 

25pytribeam 

26 (this command) 

27 

28pytribeam_info 

29 Prints the module version and ThermoFisher Scientific Autoscript and Laser 

30 API version requirements. 

31 

32pytribeam_gui 

33 Launches GUI for creating configuration .yml files and to control 

34 experimental collection. 

35 

36pytribeam_exp <path_to_file>.yml 

37 Runs 3D data collection workflow based off of input .yml file. 

38 

39 Example: 

40 path/to/experiment/directory> pytribeam_exp path/to/config/file.yml 

41 

42""" 

43 

44 

45def pytribeam(): 

46 """ 

47 Prints the command line documentation to the command window. 

48 

49 This function prints the contents of the global variable `CLI_DOCS` to the 

50 command window. It is assumed that `CLI_DOCS` contains the necessary 

51 documentation in string format. 

52 

53 Parameters 

54 ---------- 

55 None 

56 

57 Returns 

58 ------- 

59 None 

60 """ 

61 print(CLI_DOCS) 

62 

63 

64def module_info() -> None: 

65 """ 

66 Prints the module version and the yml_schema_version. 

67 

68 This function retrieves the version of the module and the YAML schema version 

69 from the `Constants` class in the `cs` module (constants.py). It prints these 

70 versions to the command window and returns the module version. 

71 

72 Parameters 

73 ---------- 

74 None 

75 

76 Returns 

77 ------- 

78 None 

79 """ 

80 

81 # ver = pkg_resources.require("recon3d")[0].version 

82 module_name = cs.Constants().module_short_name 

83 ver = version(module_name) 

84 autoscript_version = cs.Constants().autoscript_version 

85 laser_api_version = cs.Constants().laser_api_version 

86 yml_schema_version = cs.Constants().yml_schema_version 

87 print(f"{module_name} module version: v{ver}") 

88 print(f" Maximum supported .yml schema version: v{yml_schema_version}") 

89 print( 

90 f" Maximum supported Thermo Fisher Autoscript version: v{autoscript_version}" 

91 ) 

92 print(f" Maximum supported Laser API version: v{laser_api_version}") 

93 return None 

94 

95 

96def launch_gui(): 

97 # work_in_progress() 

98 app = runner.MainApplication() 

99 app.mainloop() 

100 

101 

102def run_experiment(): 

103 """run experiment from command line""" 

104 

105 def _positive_integer(prompt): 

106 """Helper function to get valid integer input""" 

107 while True: 

108 try: 

109 # Ask for input 

110 value = int(input(prompt)) 

111 if value > 0: 

112 return value # Return the valid integer 

113 print("Invalid input. Please enter an integer greater than 0.") 

114 except ValueError: 

115 print("Invalid input. Please enter a valid integer.") 

116 

117 # Create the parser 

118 parser = argparse.ArgumentParser(description="Process a file.") 

119 

120 # Add the file path argument 

121 parser.add_argument("file_path", type=str, help="Path to the file to process") 

122 

123 # Parse the arguments 

124 args = parser.parse_args() 

125 

126 start_slice = _positive_integer("Starting slice: ") 

127 start_step = _positive_integer("Starting step: ") 

128 

129 # Call the main function with the provided file path 

130 workflow.run_experiment_cli( 

131 start_slice=start_slice, start_step=start_step, yml_path=Path(args.file_path) 

132 ) 

133 

134 

135def work_in_progress(): 

136 """ 

137 Prints the 'Work in Progress (WIP)' warning message. 

138 

139 This function prints a warning message indicating that the function is a 

140 work in progress and has not yet been implemented. 

141 

142 Parameters 

143 ---------- 

144 None 

145 

146 Returns 

147 ------- 

148 None 

149 """ 

150 print("Warning: Work in progress (WIP), function not yet implemented.")