Skip to content

Commit

Permalink
Update pkg_rouces functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Christdej committed May 29, 2024
1 parent d07e60e commit 8bc07fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/isar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pkg_resources import DistributionNotFound, get_distribution
from importlib.metadata import PackageNotFoundError, distribution

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
__version__ = distribution(__name__).version
except PackageNotFoundError:
pass # package is not installed
7 changes: 4 additions & 3 deletions src/isar/config/log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import importlib.resources as pkg_resources
import logging
import logging.config
from importlib.resources import as_file, files

import yaml
from opencensus.ext.azure.log_exporter import AzureLogHandler
Expand All @@ -14,8 +14,9 @@

def setup_loggers(keyvault: Keyvault) -> None:
log_levels: dict = settings.LOG_LEVELS
with pkg_resources.path("isar.config", "logging.conf") as path:
log_config = yaml.safe_load(open(path))
source = files("isar").joinpath("config").joinpath("logging.conf")
with as_file(source) as f:
log_config = yaml.safe_load(open(f))

logging.config.dictConfig(log_config)

Expand Down
26 changes: 15 additions & 11 deletions src/isar/config/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import importlib.resources as pkg_resources
import os
from importlib.resources import as_file, files
from typing import Any, List, Optional

from dotenv import load_dotenv
Expand All @@ -14,11 +14,12 @@
class Settings(BaseSettings):
def __init__(self) -> None:
try:
with pkg_resources.path(f"isar.config", "settings.env") as path:
env_file_path = path
source = files("isar").joinpath("config").joinpath("settings.env")
with as_file(source) as eml:
env_file = eml
except ModuleNotFoundError:
env_file_path = None
super().__init__(_env_file=env_file_path)
env_file = None
super().__init__(_env_file=env_file)

# Determines which robot package ISAR will attempt to import
# Name must match with an installed python package in the local environment
Expand Down Expand Up @@ -310,13 +311,16 @@ def prefix_isar_topics(cls, v: Any, info: ValidationInfo):
class RobotSettings(BaseSettings):
def __init__(self) -> None:
try:
with pkg_resources.path(
f"{settings.ROBOT_PACKAGE}.config", "settings.env"
) as path:
env_file_path = path
source = (
files(f"{settings.ROBOT_PACKAGE}")
.joinpath("config")
.joinpath("settings.env")
)
with as_file(source) as eml:
env_file = eml
except ModuleNotFoundError:
env_file_path = None
super().__init__(_env_file=env_file_path)
env_file = None
super().__init__(_env_file=env_file)

# ISAR steps the robot is capable of performing
# This should be set in the robot package settings.env file
Expand Down

0 comments on commit 8bc07fa

Please sign in to comment.