Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/config_files/CONFIG_CUSTOM_SR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"socket_to_name": {
"CAM_B": "right",
"CAM_C": "left"
},
"inverted": false,
"fisheye": true,
"mono": true
}
9 changes: 9 additions & 0 deletions src/config_files/CONFIG_IMX296.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"socket_to_name": {
"CAM_B": "right",
"CAM_C": "left"
},
"inverted": false,
"fisheye": true,
"mono": false
}
Empty file added src/config_files/__init__.py
Empty file.
38 changes: 38 additions & 0 deletions src/example/cam_config.py
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -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