Coverage for src\pytribeam\command_line.py: 32%
41 statements
« prev ^ index » next coverage.py v7.5.1, created at 2025-03-04 17:41 -0800
« prev ^ index » next coverage.py v7.5.1, created at 2025-03-04 17:41 -0800
1"""
2Command Line Entry Points Module
3================================
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"""
10from typing import Final
11import argparse
12from pathlib import Path
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
20CLI_DOCS: Final[
21 str
22] = """
23--------
24pytribeam
25--------
27pytribeam
28 (this command)
30pytribeam_info
31 Prints the module version and ThermoFisher Scientific Autoscript and Laser
32 API version requirements.
34pytribeam_gui
35 Launches GUI for creating configuration .yml files and to control
36 experimental collection.
38pytribeam_exp <path_to_file>.yml
39 Runs 3D data collection workflow based off of input .yml file.
41 Example:
42 path/to/experiment/directory> pytribeam_exp path/to/config/file.yml
44"""
47def pytribeam():
48 """
49 Prints the command line documentation to the command window.
51 This function prints the contents of the global variable `CLI_DOCS` to the
52 command window. It is assumed that `CLI_DOCS` contains the necessary
53 documentation in string format.
55 Parameters
56 ----------
57 None
59 Returns
60 -------
61 None
62 """
63 print(CLI_DOCS)
66def module_info() -> None:
67 """
68 Prints the module version and the yml_schema_version.
70 This function retrieves the version of the module and the YAML schema version
71 from the `Constants` class in the `cs` module (constants.py). It prints these
72 versions to the command window and returns the module version.
74 Parameters
75 ----------
76 None
78 Returns
79 -------
80 None
81 """
83 # ver = pkg_resources.require("recon3d")[0].version
84 module_name = cs.Constants().module_short_name
85 ver = version(module_name)
86 autoscript_version = cs.Constants().autoscript_version
87 laser_api_version = cs.Constants().laser_api_version
88 yml_schema_version = cs.Constants().yml_schema_version
89 print(f"{module_name} module version: v{ver}")
90 print(f" Maximum supported .yml schema version: v{yml_schema_version}")
91 print(
92 f" Maximum supported Thermo Fisher Autoscript version: v{autoscript_version}"
93 )
94 print(f" Maximum supported Laser API version: v{laser_api_version}")
95 return None
98def launch_gui():
99 # work_in_progress()
100 app = runner.MainApplication()
101 app.mainloop()
104def run_experiment():
105 """run experiment from command line"""
107 def _positive_integer(prompt):
108 """Helper function to get valid integer input"""
109 while True:
110 try:
111 # Ask for input
112 value = int(input(prompt))
113 if value > 0:
114 return value # Return the valid integer
115 else:
116 print("Invalid input. Please enter an integer greater than 0.")
117 except ValueError:
118 print("Invalid input. Please enter a valid integer.")
120 # Create the parser
121 parser = argparse.ArgumentParser(description="Process a file.")
123 # Add the file path argument
124 parser.add_argument("file_path", type=str, help="Path to the file to process")
126 # Parse the arguments
127 args = parser.parse_args()
129 start_slice = _positive_integer("Starting slice: ")
130 start_step = _positive_integer("Starting step: ")
132 # Call the main function with the provided file path
133 workflow.run_experiment_cli(
134 start_slice=start_slice, start_step=start_step, yml_path=Path(args.file_path)
135 )
138def work_in_progress():
139 """
140 Prints the 'Work in Progress (WIP)' warning message.
142 This function prints a warning message indicating that the function is a
143 work in progress and has not yet been implemented.
145 Parameters
146 ----------
147 None
149 Returns
150 -------
151 None
152 """
153 print("Warning: Work in progress (WIP), function not yet implemented.")