Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circular imports in knowledge utilities #123

Merged
merged 3 commits into from
Jul 10, 2023
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
1 change: 1 addition & 0 deletions pyrobosim/pyrobosim/core/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(
self.hallways = []
self.locations = []
self.objects = []
self.set_metadata()

# Counters
self.num_rooms = 0
Expand Down
13 changes: 10 additions & 3 deletions pyrobosim/pyrobosim/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ def __init__(self, filename):
:param filename: Path to metadata YAML file.
:type filename: str
"""
self.filename = filename
with open(self.filename) as file:
self.data = yaml.load(file, Loader=yaml.FullLoader)
if filename:
if not os.path.isfile(filename):
raise FileNotFoundError(f"Metadata filename not found: {filename}")

self.filename = filename
with open(self.filename) as file:
self.data = yaml.load(file, Loader=yaml.FullLoader)
else:
self.filename = None
self.data = {}

def has_category(self, category):
"""
Expand Down
8 changes: 5 additions & 3 deletions pyrobosim/pyrobosim/utils/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import warnings
import numpy as np

from ..core.locations import Location, ObjectSpawn
from ..core.objects import Object


def apply_resolution_strategy(world, entity_list, resolution_strategy, robot=None):
"""
Expand Down Expand Up @@ -75,6 +72,9 @@ def query_to_entity(world, query_list, mode, resolution_strategy="first", robot=
:return: The entity that meets the mode and resolution strategy, or None.
:rtype: Entity
"""
from ..core.locations import Location, ObjectSpawn
from ..core.objects import Object

room = None
named_location = None
loc_category = None
Expand Down Expand Up @@ -208,6 +208,8 @@ def resolve_to_location(
:return: The location or object spawn that meets the category and/or room filters, or None.
:rtype: :class:`pyrobosim.core.locations.Location`/:class:`pyrobosim.core.locations.ObjectSpawn`
"""
from ..core.locations import Location

if room is None:
room_name = None
if category is None:
Expand Down