Skip to content

Commit be39ed7

Browse files
committed
Remove argsparse from hailo
1 parent bc9809e commit be39ed7

9 files changed

Lines changed: 18 additions & 808 deletions

abraia/hailo/camera_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ def _get_usb_video_devices_windows():
486486
hailo_logger.debug(f"USB video devices found on Windows: {usb_video_devices}")
487487
return usb_video_devices
488488

489+
489490
def main():
490491
hailo_logger.debug("Running main() to check for USB cameras.")
491492
usb_video_devices = get_usb_video_devices()

abraia/hailo/config_manager.py

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535

3636
from __future__ import annotations
3737

38-
import argparse
39-
import sys
4038
import yaml
4139
from dataclasses import dataclass
4240
from functools import lru_cache
@@ -1578,71 +1576,3 @@ def _print_result(name: str, result, error=None, indent=2):
15781576
else:
15791577
print("\n 🎉 All functions passed!")
15801578
return True
1581-
1582-
1583-
def main():
1584-
1585-
"""CLI entry point."""
1586-
parser = argparse.ArgumentParser(
1587-
description="Hailo Apps Configuration Manager",
1588-
formatter_class=argparse.RawDescriptionHelpFormatter,
1589-
epilog="""
1590-
Examples:
1591-
python -m hailo_apps.config.config_manager --dry-run
1592-
python -m hailo_apps.config.config_manager --test-all
1593-
python -m hailo_apps.config.config_manager --list-apps
1594-
python -m hailo_apps.config.config_manager --show-models detection hailo8
1595-
python -m hailo_apps.config.config_manager --show-paths
1596-
""",
1597-
)
1598-
1599-
parser.add_argument(
1600-
"--dry-run",
1601-
action="store_true",
1602-
help="Validate all configuration files and show summary",
1603-
)
1604-
parser.add_argument(
1605-
"--list-apps", action="store_true", help="List all available applications"
1606-
)
1607-
parser.add_argument(
1608-
"--show-models",
1609-
nargs=2,
1610-
metavar=("APP", "ARCH"),
1611-
help="Show models for an app and architecture",
1612-
)
1613-
parser.add_argument(
1614-
"--show-paths",
1615-
action="store_true",
1616-
help="Show configuration file paths",
1617-
)
1618-
parser.add_argument(
1619-
"--test-all",
1620-
action="store_true",
1621-
help="Test all API functions and print their outputs",
1622-
)
1623-
1624-
args = parser.parse_args()
1625-
1626-
if args.dry_run:
1627-
success = _dry_run()
1628-
sys.exit(0 if success else 1)
1629-
elif args.test_all:
1630-
success = _test_all_functions()
1631-
sys.exit(0 if success else 1)
1632-
elif args.list_apps:
1633-
_list_apps()
1634-
elif args.show_models:
1635-
_show_models(args.show_models[0], args.show_models[1])
1636-
elif args.show_paths:
1637-
_print_header("Configuration File Paths")
1638-
print(f" Repo Root: {ConfigPaths.repo_root()}")
1639-
print(f" Main Config: {ConfigPaths.main_config()}")
1640-
print(f" Resources Config: {ConfigPaths.resources_config()}")
1641-
print(f" Test Definition: {ConfigPaths.test_definition_config()}")
1642-
print(f" Test Control: {ConfigPaths.test_control_config()}")
1643-
else:
1644-
parser.print_help()
1645-
1646-
1647-
if __name__ == "__main__":
1648-
main()

abraia/hailo/core.py

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
"""Core helpers: arch detection, parser, buffer utils, model resolution."""
2+
"""Core helpers: arch detection, buffer utils, model resolution."""
33

44
import os
55
import queue
@@ -9,8 +9,6 @@
99
from typing import Optional, Tuple
1010
from dataclasses import dataclass
1111
from dotenv import load_dotenv
12-
from . import parser as common_parser
13-
import argparse
1412

1513
from .defines import (
1614
DEFAULT_DOTENV_PATH,
@@ -75,31 +73,6 @@ def load_environment(env_file=DEFAULT_DOTENV_PATH, required_vars=None) -> bool:
7573
return True
7674

7775

78-
def get_base_parser():
79-
"""Proxy to the shared base parser implementation."""
80-
return common_parser.get_base_parser()
81-
82-
83-
def get_pipeline_parser():
84-
"""Proxy to the shared pipeline parser implementation."""
85-
return common_parser.get_pipeline_parser()
86-
87-
88-
def get_standalone_parser():
89-
"""Proxy to the shared standalone parser implementation."""
90-
return common_parser.get_standalone_parser()
91-
92-
93-
def get_default_parser():
94-
"""Legacy proxy preserved for backward compatibility."""
95-
return common_parser.get_default_parser()
96-
97-
98-
def configure_multi_model_hef_path(parser):
99-
"""Proxy to configure --hef-path for multi-model apps."""
100-
return common_parser.configure_multi_model_hef_path(parser)
101-
102-
10376
def get_resource_path(
10477
pipeline_name: str, resource_type: str, arch: str | None = None, model: str | None = None
10578
) -> Path | None:
@@ -790,7 +763,7 @@ def _map_app_to_resource_group(app_name: str) -> str:
790763
# =============================================================================
791764
# Handle and Resolve Common Args
792765
# =============================================================================
793-
def handle_and_resolve_args(args: argparse.Namespace, APP_NAME: str, multi_hef: bool = False, using_onnx_pp=False) -> None:
766+
def handle_and_resolve_args(args, APP_NAME: str, multi_hef: bool = False, using_onnx_pp=False) -> None:
794767
"""
795768
Handle common CLI argument logic for Hailo applications.
796769
@@ -805,7 +778,7 @@ def handle_and_resolve_args(args: argparse.Namespace, APP_NAME: str, multi_hef:
805778
- This helper is intended mainly for standalone applications.
806779
807780
Args:
808-
args: Parsed argparse.Namespace from the application
781+
args: Parsed args from the application
809782
APP_NAME: The application name for model/input resolution
810783
using_onnx_pp: Whether the app uses ONNX postprocessing
811784
"""

abraia/hailo/download_resources.py

Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
- Force-redownload capability
1717
"""
1818

19-
import argparse
2019
import os
2120
import sys
2221
import tempfile
@@ -1560,149 +1559,3 @@ def list_models_for_arch(
15601559
if include_extra:
15611560
total_msg += f", {len(extra_models)} extra model(s)"
15621561
print(total_msg)
1563-
1564-
1565-
# =============================================================================
1566-
# CLI Entry Point
1567-
# =============================================================================
1568-
1569-
def main():
1570-
parser = argparse.ArgumentParser(
1571-
description="Download Hailo resources (models, videos, images, configs)",
1572-
formatter_class=argparse.RawDescriptionHelpFormatter,
1573-
epilog="""
1574-
Examples:
1575-
# Download default resources for detected architecture
1576-
%(prog)s
1577-
1578-
# Download all models (default + extra) for all apps
1579-
%(prog)s --all
1580-
1581-
# Download resources for a specific app
1582-
%(prog)s --group detection
1583-
1584-
# Download a specific resource (strict targeted mode)
1585-
%(prog)s --group detection --resource-type model --resource-name yolov8m
1586-
%(prog)s --group detection --resource-type image --resource-name bus.jpg
1587-
%(prog)s --group detection --resource-type video --resource-name example.mp4
1588-
1589-
# Download for a specific architecture
1590-
%(prog)s --arch hailo10h
1591-
1592-
# Preview what would be downloaded (dry run)
1593-
%(prog)s --dry-run
1594-
1595-
# Force re-download existing files
1596-
%(prog)s --force
1597-
1598-
# Download gen-ai app (auto-includes gen-ai models)
1599-
%(prog)s --group vlm_chat --arch hailo10h
1600-
1601-
# Include gen-ai apps in bulk download (downloads ALL apps including VLM, LLM, Whisper)
1602-
%(prog)s --all --include-gen-ai --arch hailo10h
1603-
"""
1604-
)
1605-
1606-
parser.add_argument(
1607-
"--all",
1608-
action="store_true",
1609-
help="Download all models (default + extra) for all apps"
1610-
)
1611-
parser.add_argument(
1612-
"--config",
1613-
type=str,
1614-
default=DEFAULT_RESOURCES_CONFIG_PATH,
1615-
help="Path to config file"
1616-
)
1617-
parser.add_argument(
1618-
"--arch",
1619-
type=str,
1620-
default=None,
1621-
choices=["hailo8", "hailo8l", "hailo10h"],
1622-
help="Hailo architecture override"
1623-
)
1624-
parser.add_argument(
1625-
"--group",
1626-
type=str,
1627-
default=None,
1628-
help="Group/app name to download resources for (e.g., detection, vlm_chat)"
1629-
)
1630-
parser.add_argument(
1631-
"--resource-name",
1632-
type=str,
1633-
default=None,
1634-
help="Specific resource name to download"
1635-
)
1636-
parser.add_argument(
1637-
"--resource-type",
1638-
type=str,
1639-
default=None,
1640-
choices=sorted(RESOURCE_TYPES),
1641-
help="Type of the resource specified by --resource-name (model/image/video/onnx)"
1642-
)
1643-
parser.add_argument(
1644-
"--list-models",
1645-
action="store_true",
1646-
help="List all available models for the detected/selected architecture"
1647-
)
1648-
parser.add_argument(
1649-
"--dry-run",
1650-
action="store_true",
1651-
help="Show what would be downloaded without actually downloading"
1652-
)
1653-
parser.add_argument(
1654-
"--force",
1655-
action="store_true",
1656-
help="Force re-download even if files already exist"
1657-
)
1658-
parser.add_argument(
1659-
"--no-parallel",
1660-
action="store_true",
1661-
help="Disable parallel downloads (download sequentially)"
1662-
)
1663-
parser.add_argument(
1664-
"--include-gen-ai",
1665-
action="store_true",
1666-
help="Include gen-ai apps in bulk downloads (not needed with --group, gen-ai models are auto-included when group has them)"
1667-
)
1668-
1669-
args = parser.parse_args()
1670-
1671-
load_environment()
1672-
1673-
# List models and exit
1674-
if args.list_models:
1675-
list_models_for_arch(
1676-
resource_config_path=args.config,
1677-
arch=args.arch,
1678-
include_extra=True
1679-
)
1680-
return
1681-
1682-
# Validate targeted mode arguments
1683-
if args.resource_name and not args.resource_type:
1684-
parser.error("--resource-name requires --resource-type")
1685-
1686-
if args.resource_type and not args.resource_name:
1687-
parser.error("--resource-type requires --resource-name")
1688-
1689-
1690-
# Download resources
1691-
download_resources(
1692-
resource_config_path=args.config,
1693-
arch=args.arch,
1694-
group=args.group,
1695-
all_models=args.all,
1696-
resource_name=args.resource_name,
1697-
resource_type=args.resource_type,
1698-
dry_run=args.dry_run,
1699-
force=args.force,
1700-
parallel=not args.no_parallel,
1701-
include_gen_ai=args.include_gen_ai
1702-
)
1703-
1704-
hailo_logger.info("Resource download completed.")
1705-
1706-
1707-
if __name__ == "__main__":
1708-
main()

abraia/hailo/hailo_logger.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -266,45 +266,6 @@ def get_logger(name: str) -> logging.Logger:
266266
return logging.getLogger(name)
267267

268268

269-
def add_logging_cli_args(parser: Any) -> None:
270-
"""Add --log-level/--debug/--log-file flags to an argparse parser.
271-
272-
Typical usage:
273-
274-
from hailo_logger import add_logging_cli_args, init_logging, level_from_args
275-
276-
parser = argparse.ArgumentParser()
277-
add_logging_cli_args(parser)
278-
args = parser.parse_args()
279-
init_logging(level=level_from_args(args), log_file=args.log_file)
280-
"""
281-
parser.add_argument(
282-
"--log-level",
283-
default=os.getenv("HAILO_LOG_LEVEL", "INFO"),
284-
choices=[k.lower() for k in _LEVELS.keys()],
285-
help="Logging level (default: %(default)s or $HAILO_LOG_LEVEL).",
286-
)
287-
parser.add_argument(
288-
"--debug",
289-
action="store_true",
290-
help="Shortcut for DEBUG log level (overrides --log-level).",
291-
)
292-
parser.add_argument(
293-
"--log-file",
294-
default=os.getenv("HAILO_LOG_FILE"),
295-
help="Optional log file path (also respects $HAILO_LOG_FILE).",
296-
)
297-
298-
299-
def level_from_args(args: Any) -> str:
300-
"""Resolve level string from argparse args."""
301-
return (
302-
"DEBUG"
303-
if getattr(args, "debug", False)
304-
else str(getattr(args, "log_level", "INFO")).upper()
305-
)
306-
307-
308269
# Auto-configuration: set HAILO_LOG_AUTOCONFIG=1 to call init_logging() at import time.
309270
# Level comes from HAILO_LOG_LEVEL env var (defaults to INFO).
310271
# Noisy loggers are NOT suppressed when level is set via env var.

0 commit comments

Comments
 (0)