Skip to content

Command Line Interface Entry Point

flyvis_cli.flyvis_cli

CLI entry point and pipeline manager for ensemble operations.

Example usage
# Run a pipeline of operations
flyvis         --ensemble_id 0001         --task_name flow         train         validate         record         analysis         notebook_per_model         notebook_per_ensemble
run_script
run_script(script_path, args)

Run a Python script with the given arguments.

Parameters:

Name Type Description Default
script_path Path

Path to the script to run.

required
args List[str]

List of command-line arguments to pass to the script.

required
Source code in flyvis_cli/flyvis_cli.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def run_script(script_path: Path, args: List[str]) -> None:
    """
    Run a Python script with the given arguments.

    Args:
        script_path: Path to the script to run.
        args: List of command-line arguments to pass to the script.
    """
    cmd = [sys.executable, str(script_path)] + args
    try:
        subprocess.run(cmd, check=True)
    except subprocess.CalledProcessError as e:
        print(f"Error running {script_path}: {e}", file=sys.stderr)
        sys.exit(1)
filter_args
filter_args(argv, allowed_commands)

Filter out commands from command line arguments.

Parameters:

Name Type Description Default
argv List[str]

List of command line arguments (typically sys.argv[1:])

required
commands

List of commands to filter out

required

Returns:

Type Description
Tuple[List[str], List[str]]

List of arguments with commands removed

Source code in flyvis_cli/flyvis_cli.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def filter_args(
    argv: List[str], allowed_commands: List[str]
) -> Tuple[List[str], List[str]]:
    """
    Filter out commands from command line arguments.

    Args:
        argv: List of command line arguments (typically sys.argv[1:])
        commands: List of commands to filter out

    Returns:
        List of arguments with commands removed
    """
    selected_commands = []
    other_args = []
    for arg in argv:
        if arg in allowed_commands:
            selected_commands.append(arg)
        else:
            other_args.append(arg)

    return selected_commands, other_args
handle_help_request
handle_help_request(argv)

Check if help is requested for a specific command and handle it.

Parameters:

Name Type Description Default
argv List[str]

Command line arguments (typically sys.argv)

required

Returns:

Type Description
bool

True if help was handled, False otherwise

Source code in flyvis_cli/flyvis_cli.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def handle_help_request(argv: List[str]) -> bool:
    """
    Check if help is requested for a specific command and handle it.

    Args:
        argv: Command line arguments (typically sys.argv)

    Returns:
        True if help was handled, False otherwise
    """
    if len(argv) > 1 and argv[1] in SCRIPT_COMMANDS:
        help_flags = {"-h", "--help"}
        if any(flag in argv[2:] for flag in help_flags):
            command = argv[1]
            run_script(SCRIPT_COMMANDS[command], argv[2:])
            return True
    return False