Skip to content

Commit

Permalink
Update config to new pydantic version
Browse files Browse the repository at this point in the history
and move config from settings folder to config folder
  • Loading branch information
tsundvoll committed Nov 2, 2023
1 parent 078c534 commit 7fecef9
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 23 deletions.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
package_dir={"": "src"},
package_data={
"isar_turtlebot": [
"settings/maps/turtleworld.json",
"settings/maps/klab_turtlebot_old.json",
"settings/maps/klab_turtlebot.json",
"config/maps/turtleworld.json",
"config/maps/klab_turtlebot_old.json",
"config/maps/klab_turtlebot.json",
"config/settings.env",
]
},
Expand Down
1 change: 1 addition & 0 deletions src/isar_turtlebot/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from isar_turtlebot.config.settings import settings
2 changes: 2 additions & 0 deletions src/isar_turtlebot/config/settings.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
CAPABILITIES = '["take_thermal_image","take_image","drive_to_pose"]'
ROBOT_MODEL = Turtlebot

TURTLEBOT_MAP = klab_turtlebot
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from pydantic import BaseSettings, Field
import importlib.resources as pkg_resources

from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
def __init__(self) -> None:
try:
with pkg_resources.path(f"isar_turtlebot.config", "settings.env") as path:
env_file_path = path
except ModuleNotFoundError:
env_file_path = None
super().__init__(_env_file=env_file_path)

IMAGE_FILETYPE: str = Field(default="jpg")
THERMAL_IMAGE_FILETYPE: str = Field(default="png")

Expand All @@ -17,8 +28,11 @@ class Settings(BaseSettings):

LOGGER_NAME: str = Field(default="isar_turtlebot")

class Config:
env_prefix = "ISAR_TURTLEBOT_"
model_config = SettingsConfigDict(
env_prefix="ISAR_TURTLEBOT_",
env_file_encoding="utf-8",
case_sensitive=True,
)


settings = Settings()
4 changes: 2 additions & 2 deletions src/isar_turtlebot/robotinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from robot_interface.robot_interface import RobotInterface
from robot_interface.telemetry.mqtt_client import MqttTelemetryPublisher

from isar_turtlebot.config import settings
from isar_turtlebot.ros_bridge.ros_bridge import RosBridge, RosBridgeInterface
from isar_turtlebot.settings import settings
from isar_turtlebot.turtlebot import Turtlebot


Expand All @@ -25,7 +25,7 @@ def __init__(self, bridge: RosBridgeInterface = RosBridge):
map_alignment: MapAlignment = MapAlignment.from_config(
Path(
os.path.dirname(os.path.realpath(__file__)),
f"settings/maps/{settings.TURTLEBOT_MAP}.json",
f"config/maps/{settings.TURTLEBOT_MAP}.json",
)
)
transform: Transform = align_maps(
Expand Down
2 changes: 1 addition & 1 deletion src/isar_turtlebot/ros_bridge/ros_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
)
from roslibpy import Ros

from isar_turtlebot.config import settings
from isar_turtlebot.ros_bridge.topic import ImageTopic, Topic
from isar_turtlebot.settings import settings


class RosBridgeInterface(ABC):
Expand Down
2 changes: 1 addition & 1 deletion src/isar_turtlebot/ros_bridge/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from roslibpy import Message, Ros
from roslibpy import Topic as RosTopic

from isar_turtlebot.settings import settings
from isar_turtlebot.config import settings


class TopicInterface(ABC):
Expand Down
1 change: 0 additions & 1 deletion src/isar_turtlebot/settings/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion src/isar_turtlebot/settings/settings.env

This file was deleted.

2 changes: 1 addition & 1 deletion src/isar_turtlebot/turtlebot/step_handlers/driveto.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
)
from robot_interface.models.mission.step import DriveToPose

from isar_turtlebot.config import settings
from isar_turtlebot.models.turtlebot_status import Status
from isar_turtlebot.ros_bridge.ros_bridge import RosBridge
from isar_turtlebot.settings import settings
from isar_turtlebot.turtlebot.step_handlers.stephandler import StepHandler
from isar_turtlebot.utilities.pose_message import encode_pose_message

Expand Down
2 changes: 1 addition & 1 deletion src/isar_turtlebot/turtlebot/step_handlers/stephandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from robot_interface.models.exceptions.robot_exceptions import RobotAPIException
from robot_interface.models.mission.step import Step

from isar_turtlebot.config import settings
from isar_turtlebot.models.turtlebot_status import Status
from isar_turtlebot.settings import settings


class StepHandler(ABC):
Expand Down
7 changes: 2 additions & 5 deletions src/isar_turtlebot/turtlebot/step_handlers/takeimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@
RobotCommunicationException,
RobotInfeasibleStepException,
)
from robot_interface.models.inspection.inspection import (
Image,
ImageMetadata,
)
from robot_interface.models.inspection.inspection import Image, ImageMetadata
from robot_interface.models.mission.step import TakeImage

from isar_turtlebot.config import settings
from isar_turtlebot.models.turtlebot_status import Status
from isar_turtlebot.ros_bridge.ros_bridge import RosBridge
from isar_turtlebot.settings import settings
from isar_turtlebot.turtlebot.step_handlers.stephandler import StepHandler
from isar_turtlebot.utilities.inspection_pose import get_inspection_pose
from isar_turtlebot.utilities.pose_message import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from typing import Optional
from uuid import uuid4

import PIL.Image as PILImage
import numpy as np
import PIL.Image as PILImage
from alitra import Pose, Position, Transform
from robot_interface.models.exceptions.robot_exceptions import (
RobotCommunicationException,
Expand All @@ -21,9 +21,9 @@
)
from robot_interface.models.mission.step import TakeThermalImage

from isar_turtlebot.config import settings
from isar_turtlebot.models.turtlebot_status import Status
from isar_turtlebot.ros_bridge.ros_bridge import RosBridge
from isar_turtlebot.settings import settings
from isar_turtlebot.turtlebot.step_handlers.stephandler import StepHandler
from isar_turtlebot.utilities.inspection_pose import get_inspection_pose
from isar_turtlebot.utilities.pose_message import (
Expand Down
3 changes: 1 addition & 2 deletions src/isar_turtlebot/turtlebot/turtlebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
RobotRetrieveInspectionException,
RobotTelemetryException,
)

from robot_interface.models.inspection.inspection import Inspection
from robot_interface.models.mission.status import StepStatus
from robot_interface.models.mission.step import InspectionStep, Step
Expand All @@ -21,9 +20,9 @@
)
from robot_interface.utilities.json_service import EnhancedJSONEncoder

from isar_turtlebot.config import settings
from isar_turtlebot.models.turtlebot_status import Status
from isar_turtlebot.ros_bridge import RosBridge
from isar_turtlebot.settings import settings
from isar_turtlebot.turtlebot.step_handlers import (
DriveToHandler,
TakeImageHandler,
Expand Down

0 comments on commit 7fecef9

Please sign in to comment.