diff --git a/setup.cfg b/setup.cfg index 7fb17e1..69763d1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,11 +16,15 @@ include_package_data = True package_dir= =src install_requires = - numpy + numpy==1.25.1 [options.packages.find] where=src +[options.package_data] +config_files = + *.json + [options.extras_require] dev = black==23.12.1 flake8==7.0.0 diff --git a/src/config_files/CONFIG_CUSTOM_SR.json b/src/config_files/CONFIG_CUSTOM_SR.json new file mode 100644 index 0000000..7218f57 --- /dev/null +++ b/src/config_files/CONFIG_CUSTOM_SR.json @@ -0,0 +1,9 @@ +{ + "socket_to_name": { + "CAM_B": "right", + "CAM_C": "left" + }, + "inverted": false, + "fisheye": true, + "mono": true +} \ No newline at end of file diff --git a/src/config_files/CONFIG_IMX296.json b/src/config_files/CONFIG_IMX296.json new file mode 100644 index 0000000..17e0393 --- /dev/null +++ b/src/config_files/CONFIG_IMX296.json @@ -0,0 +1,9 @@ +{ + "socket_to_name": { + "CAM_B": "right", + "CAM_C": "left" + }, + "inverted": false, + "fisheye": true, + "mono": false +} \ No newline at end of file diff --git a/src/config_files/__init__.py b/src/config_files/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/example/cam_config.py b/src/example/cam_config.py new file mode 100644 index 0000000..1a6c849 --- /dev/null +++ b/src/example/cam_config.py @@ -0,0 +1,38 @@ +import json +from importlib.resources import files +from typing import Any, List + + +class CamConfig: + def __init__( + self, + cam_config_json: str, + ) -> None: + self.cam_config_json = cam_config_json + + config = json.load(open(self.cam_config_json, "rb")) + self.socket_to_name = config["socket_to_name"] + self.inverted = config["inverted"] + self.fisheye = config["fisheye"] + self.mono = config["mono"] + + def to_string(self) -> str: + ret_string = "Camera Config: \n" + ret_string += "Inverted: {}\n".format(self.inverted) + ret_string += "Fisheye: {}\n".format(self.fisheye) + ret_string += "Mono: {}\n".format(self.mono) + + return ret_string + + +def get_config_files_names() -> List[str]: + path = files("config_files") + return [file.stem for file in path.glob("**/*.json")] # type: ignore[attr-defined] + + +def get_config_file_path(name: str) -> Any: + path = files("config_files") + for file in path.glob("**/*"): # type: ignore[attr-defined] + if file.stem == name: + return file.resolve() + return None diff --git a/src/main.py b/src/main.py index 53b190c..79042be 100644 --- a/src/main.py +++ b/src/main.py @@ -2,6 +2,7 @@ import logging import sys +from example.cam_config import CamConfig, get_config_file_path, get_config_files_names from example.celcius import Celsius from example.foo import Foo from example.xterrabot import XTerraBot @@ -26,6 +27,10 @@ def main(args: argparse.Namespace) -> int: xt_bot = XTerraBot() logging.info(xt_bot.get_object_in_gripper_frame()) + # usage of data stored in config_files + cam_conf = CamConfig(get_config_file_path(args.config)) + logging.info(cam_conf.to_string()) + return 0 @@ -37,8 +42,19 @@ def main(args: argparse.Namespace) -> int: parser.add_argument("--int_param", type=int, default=5) parser.add_argument("--float_param", type=float, default=2.5) parser.add_argument("--verbose", action="store_true", default=False) + + valid_configs = get_config_files_names() + parser.add_argument( + "--config", + type=str, + required=True, + choices=valid_configs, + help=f"Configutation file name : {valid_configs}", + ) + args = parser.parse_args() + # activate the --verbose to see more output if args.verbose: logging.basicConfig(level=logging.INFO) diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..8ec3845 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,14 @@ +import pytest + +from src.example.cam_config import ( + CamConfig, + get_config_file_path, + get_config_files_names, +) + + +def test_config() -> None: + list_config = get_config_files_names() + for conf in list_config: + c = CamConfig(get_config_file_path(conf)) + assert c is not None