Skip to content

Commit 0155b8b

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

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

tests/test_misc.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import __main__
16+
from unittest import TestCase
17+
from unittest.mock import patch
18+
19+
from veadk.utils.misc import get_agents_dir
20+
21+
22+
class GetAgentsDirTest(TestCase):
23+
@patch.object(__main__, "__file__", "/test/path/app/main.py")
24+
def test_get_agents_dir_from_main(self):
25+
"""Test get_agents_dir using __main__.__file__"""
26+
self.assertEqual(get_agents_dir(), "/test/path")
27+
28+
def test_get_agents_dir_from_argv(self):
29+
"""Test get_agents_dir using sys.argv"""
30+
with patch("veadk.utils.misc.sys") as mock_sys:
31+
mock_sys.argv = ["/test/path/app/main.py"]
32+
with patch("veadk.utils.misc.hasattr") as mock_hasattr:
33+
mock_hasattr.return_value = False
34+
self.assertEqual(get_agents_dir(), "/test/path")
35+
36+
@patch("veadk.utils.misc.os.getcwd")
37+
@patch("veadk.utils.misc.sys")
38+
def test_get_agents_dir_from_cwd(self, mock_sys, mock_getcwd):
39+
"""Test get_agents_dir using os.getcwd"""
40+
mock_sys.argv = [""]
41+
mock_getcwd.return_value = "/test/path/app"
42+
with patch("veadk.utils.misc.hasattr") as mock_hasattr:
43+
mock_hasattr.return_value = False
44+
self.assertEqual(get_agents_dir(), "/test/path")
45+
46+
@patch("veadk.utils.misc.os.getcwd")
47+
@patch("veadk.utils.misc.sys")
48+
def test_get_agents_dir_from_cwd_empty_argv(self, mock_sys, mock_getcwd):
49+
"""Test get_agents_dir using os.getcwd with empty argv"""
50+
mock_sys.argv = []
51+
mock_getcwd.return_value = "/test/path/app"
52+
with patch("veadk.utils.misc.hasattr") as mock_hasattr:
53+
mock_hasattr.return_value = False
54+
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)