Skip to content

Commit

Permalink
FIX: Iterate over all frames on the stack to add to search path.
Browse files Browse the repository at this point in the history
  • Loading branch information
hhslepicka committed Mar 2, 2023
1 parent 79b8f57 commit fff20a1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions botcity/base/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def _resources_path(self, resource_folder="resources"):
res_path = sys.modules[self.__module__].__file__
return path.join(path.dirname(path.realpath(res_path)), resource_folder)

def _get_frame_path(self, frame):
frame_filename = inspect.getframeinfo(frame).filename
frame_dir = os.path.dirname(frame_filename)
return frame_dir

def _search_image_file(self, label):
"""
When finding images, this is the priority in which we will look into:
Expand Down Expand Up @@ -82,10 +87,12 @@ def _search_image_file(self, label):

# "resources" folder parallel to the `find` caller file.
try:
caller = inspect.currentframe().f_back.f_back
caller_filename = inspect.getframeinfo(caller).filename
caller_dir = os.path.dirname(caller_filename)
locations.append(os.path.join(caller_dir, "resources"))
frame = inspect.currentframe()
while frame is not None:
caller_dir = self._get_frame_path(frame)
caller_path = os.path.join(caller_dir, "resources")
locations.append(caller_path)
frame = frame.f_back
except: # noqa: E722
pass

Expand Down Expand Up @@ -125,7 +132,7 @@ def main(cls):
execution = None
# TODO: Refactor this later for proper parameters to be passed
# in a cleaner way
if len(sys.argv) == 4:
if len(sys.argv) >= 4:
if maestro_available:
server, task_id, token = sys.argv[1:4]
bot.maestro = BotMaestroSDK(server=server)
Expand Down

0 comments on commit fff20a1

Please sign in to comment.