Skip to content

Commit 50e19b4

Browse files
committed
fix: change the default save path of evalset file
1 parent 49ba1be commit 50e19b4

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

tests/test_misc.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import __main__
2+
from unittest import TestCase
3+
from unittest.mock import patch
4+
5+
from veadk.utils.misc import get_agents_dir
6+
7+
8+
class GetAgentsDirTest(TestCase):
9+
@patch.object(__main__, "__file__", "/test/path/app/main.py")
10+
def test_get_agents_dir_from_main(self):
11+
"""Test get_agents_dir using __main__.__file__"""
12+
self.assertEqual(get_agents_dir(), "/test/path")
13+
14+
def test_get_agents_dir_from_argv(self):
15+
"""Test get_agents_dir using sys.argv"""
16+
with patch("veadk.utils.misc.sys") as mock_sys:
17+
mock_sys.argv = ["/test/path/app/main.py"]
18+
with patch("veadk.utils.misc.hasattr") as mock_hasattr:
19+
mock_hasattr.return_value = False
20+
self.assertEqual(get_agents_dir(), "/test/path")
21+
22+
@patch("veadk.utils.misc.os.getcwd")
23+
@patch("veadk.utils.misc.sys")
24+
def test_get_agents_dir_from_cwd(self, mock_sys, mock_getcwd):
25+
"""Test get_agents_dir using os.getcwd"""
26+
mock_sys.argv = [""]
27+
mock_getcwd.return_value = "/test/path/app"
28+
with patch("veadk.utils.misc.hasattr") as mock_hasattr:
29+
mock_hasattr.return_value = False
30+
self.assertEqual(get_agents_dir(), "/test/path")
31+
32+
@patch("veadk.utils.misc.os.getcwd")
33+
@patch("veadk.utils.misc.sys")
34+
def test_get_agents_dir_from_cwd_empty_argv(self, mock_sys, mock_getcwd):
35+
"""Test get_agents_dir using os.getcwd with empty argv"""
36+
mock_sys.argv = []
37+
mock_getcwd.return_value = "/test/path/app"
38+
with patch("veadk.utils.misc.hasattr") as mock_hasattr:
39+
mock_hasattr.return_value = False
40+
self.assertEqual(get_agents_dir(), "/test/path")

veadk/evaluation/eval_set_recorder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from google.adk.sessions import BaseSessionService
2222

2323
from veadk.utils.logger import get_logger
24-
from veadk.utils.misc import formatted_timestamp, get_temp_dir
24+
from veadk.utils.misc import formatted_timestamp, get_agents_dir
2525

2626
logger = get_logger(__name__)
2727

@@ -53,7 +53,7 @@ def __init__(
5353
Raises:
5454
ValueError: If eval_set_id is invalid.
5555
"""
56-
super().__init__(agents_dir=get_temp_dir())
56+
super().__init__(agents_dir=get_agents_dir())
5757
self.eval_set_id = eval_set_id if eval_set_id != "" else "default"
5858
self.session_service: BaseSessionService = session_service
5959

veadk/utils/misc.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import requests
2424
from yaml import safe_load
25+
import __main__
2526

2627

2728
def read_file(file_path):
@@ -166,3 +167,23 @@ def get_temp_dir():
166167
else:
167168
# Non-Windows systems (macOS, Linux, etc.) uniformly return /tmp
168169
return "/tmp"
170+
171+
172+
def get_agents_dir():
173+
"""
174+
Get the directory of the currently executed entry script.
175+
176+
Returns:
177+
str: The agents directory (parent directory of the app)
178+
"""
179+
# Try using __main__.__file__ (works for most CLI scripts and uv run environments)
180+
if hasattr(__main__, "__file__"):
181+
full_path = os.path.dirname(os.path.abspath(__main__.__file__))
182+
# Fallback to sys.argv[0] (usually gives the entry script path)
183+
elif len(sys.argv) > 0 and sys.argv[0]:
184+
full_path = os.path.dirname(os.path.abspath(sys.argv[0]))
185+
# Fallback to current working directory (for REPL / Jupyter Notebook)
186+
else:
187+
full_path = os.getcwd()
188+
189+
return os.path.dirname(full_path)

0 commit comments

Comments
 (0)