-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for CLI scaffolding. (#4)
- Loading branch information
Showing
6 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Scaffolding placeholder for prediction code.""" | ||
|
||
|
||
def run(args): | ||
"""Placeholder for prediction code. | ||
Parameters | ||
---------- | ||
args : argparse.Namespace | ||
The parsed command line arguments. | ||
""" | ||
|
||
print("Prending to run prediction...") | ||
print(f"Runtime config: {args.runtime_config}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Scaffolding placeholder for training code.""" | ||
|
||
|
||
def run(args): | ||
"""Placeholder for training code. | ||
Parameters | ||
---------- | ||
args : argparse.Namespace | ||
The parsed command line arguments. | ||
""" | ||
|
||
print("Prending to run training...") | ||
print(f"Runtime config: {args.runtime_config}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import argparse | ||
import shutil | ||
import subprocess | ||
import sys | ||
from importlib.metadata import version | ||
|
||
|
||
def main(): | ||
"""Primary entry point for the Fibad CLI. This handles dispatching to the various | ||
Fibad actions. The actions are defined in the pyproject.toml project.scripts | ||
section. | ||
""" | ||
|
||
description = "Fibad CLI" | ||
epilog = "FIBAD is the Framework for Image-Based Anomaly Detection" | ||
|
||
#! We could potentially make this dynamic | ||
fibad_verbs = ["train", "predict"] | ||
|
||
parser = argparse.ArgumentParser(description=description, epilog=epilog) | ||
parser.add_argument("--version", dest="version", action="store_true", help="Show version") | ||
parser.add_argument("verb", nargs="?", choices=fibad_verbs, help="Verb to execute") | ||
parser.add_argument("args", nargs=argparse.REMAINDER, help="Arguments for the verb") | ||
|
||
args = parser.parse_args() | ||
|
||
if args.version: | ||
print(version("fibad")) | ||
return | ||
|
||
if not args.verb: | ||
parser.print_help() | ||
sys.exit(1) | ||
|
||
fibad_action = f"fibad-{args.verb}" | ||
|
||
# Ensure the action is available | ||
if not shutil.which(fibad_action): | ||
print(f"Error: '{fibad_action}' is not available.") | ||
print("Is the action defined in the pyproject.toml project.scripts section?") | ||
sys.exit(1) | ||
|
||
# Execute the action with the remaining arguments | ||
try: | ||
result = subprocess.run([fibad_action] + args.args, check=True) | ||
sys.exit(result.returncode) | ||
except subprocess.CalledProcessError as e: | ||
print(f"Error: Command '{fibad_action}' failed with exit code {e.returncode}.") | ||
sys.exit(e.returncode) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import argparse | ||
|
||
|
||
def main(): | ||
"""Argument parser to process command line arguments when predicting with Fibad.""" | ||
|
||
parser = argparse.ArgumentParser(description="Predicting with Fibad.") | ||
|
||
parser.add_argument("-c", "--runtime-config", type=str, help="Full path to runtime config file") | ||
|
||
args = parser.parse_args() | ||
|
||
run(args) | ||
|
||
|
||
def run(args): | ||
"""Note: Don't import anything from Fibad outside of this run function. | ||
Keeping all the imports inside the run function ensures that the --help option | ||
returns quickly without loading all the dependencies. | ||
""" | ||
from fibad.predict import run | ||
|
||
run(args) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import argparse | ||
|
||
|
||
def main(): | ||
"""Argument parser to process command line arguments when training with Fibad.""" | ||
|
||
parser = argparse.ArgumentParser(description="Training with Fibad.") | ||
|
||
parser.add_argument("-c", "--runtime-config", type=str, help="Full path to runtime config file") | ||
|
||
args = parser.parse_args() | ||
|
||
run(args) | ||
|
||
|
||
def run(args): | ||
"""Note: Don't import anything from Fibad outside of this run function. | ||
Keeping all the imports inside the run function ensures that the --help option | ||
returns quickly without loading all the dependencies. | ||
""" | ||
from fibad.train import run | ||
|
||
run(args) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |