Skip to content

Commit e68e150

Browse files
committed
add a utility function for resolving the path to a resource file
1 parent 9047c2c commit e68e150

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

skill_framework/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
'SkillVisualization',
1111
'ExportData',
1212
'wire_layout',
13+
'skill_resource_path',
1314
]
1415

1516
from skill_framework.skills import (skill, SkillInput, SkillParameter, SkillOutput, ExitFromSkillException,
1617
ParameterDisplayDescription, SuggestedQuestion, SkillVisualization, ExportData)
1718
from skill_framework.preview import preview_skill
1819
from skill_framework.layouts import wire_layout
20+
from skill_framework.resources import skill_resource_path
1921

2022
__version__ = '0.3.10'

skill_framework/resources.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
3+
4+
def skill_resource_path(filename: str):
5+
"""
6+
Helper for resolving the path of a resource file regardless of where the skill is running.
7+
"""
8+
base_path = os.environ.get('AR_SKILL_BASE_PATH') or ''
9+
return os.path.join(base_path, 'resources', filename)

skill_framework/skills.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inspect
21
import jinja2
32
import keyword
43
import os

test/test_resources.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from skill_framework import skill_resource_path
2+
3+
4+
def test_local_path():
5+
path = skill_resource_path('test.txt')
6+
assert path == 'resources/test.txt'
7+
8+
9+
def test_path_with_base(monkeypatch):
10+
monkeypatch.setenv('AR_SKILL_BASE_PATH', 'some_base_dir')
11+
path = skill_resource_path('test.txt')
12+
assert path == 'some_base_dir/resources/test.txt'
13+

0 commit comments

Comments
 (0)