Skip to content

Commit 23eaf93

Browse files
Fix CI usage of uv (huggingface#970)
1 parent e374d1b commit 23eaf93

File tree

4 files changed

+53
-30
lines changed

4 files changed

+53
-30
lines changed

.github/workflows/quality.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Quality Check
22

33
on: [pull_request]
44

5+
env:
6+
UV_SYSTEM_PYTHON: 1
7+
58
jobs:
69
check_code_quality:
710
runs-on: ubuntu-latest
@@ -16,15 +19,14 @@ jobs:
1619
python-version: "3.12"
1720

1821
# Setup venv
19-
- name: Setup venv + uv
22+
- name: Setup uv
2023
run: |
2124
pip install --upgrade uv
22-
uv venv
2325
2426
- name: Install dependencies
2527
run: uv pip install "smolagents[quality] @ ."
2628

2729
# Equivalent of "make quality" but step by step
28-
- run: uv run ruff check examples src tests utils # linter
29-
- run: uv run ruff format --check examples src tests utils # formatter
30-
- run: uv run python utils/check_tests_in_ci.py
30+
- run: ruff check examples src tests utils # linter
31+
- run: ruff format --check examples src tests utils # formatter
32+
- run: python utils/check_tests_in_ci.py

.github/workflows/tests.yml

+22-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Python tests
22

33
on: [pull_request]
44

5+
env:
6+
UV_SYSTEM_PYTHON: 1
7+
58
jobs:
69
build-ubuntu:
710
runs-on: ubuntu-latest
@@ -21,10 +24,9 @@ jobs:
2124
python-version: ${{ matrix.python-version }}
2225

2326
# Setup venv
24-
- name: Setup venv + uv
27+
- name: Setup uv
2528
run: |
2629
pip install --upgrade uv
27-
uv venv
2830
2931
# Install dependencies
3032
- name: Install dependencies
@@ -36,89 +38,89 @@ jobs:
3638
# See https://stackoverflow.com/a/62112985
3739
- name: Import tests
3840
run: |
39-
uv run pytest ./tests/test_import.py
41+
pytest ./tests/test_import.py
4042
if: ${{ success() || failure() }}
4143

4244
- name: Agent tests
4345
run: |
44-
uv run pytest ./tests/test_agents.py
46+
pytest ./tests/test_agents.py
4547
if: ${{ success() || failure() }}
4648

4749
- name: Default tools tests
4850
run: |
49-
uv run pytest ./tests/test_default_tools.py
51+
pytest ./tests/test_default_tools.py
5052
if: ${{ success() || failure() }}
5153

5254
# - name: Docs tests # Disabled for now (slow test + requires API keys)
5355
# run: |
54-
# uv run pytest ./tests/test_all_docs.py
56+
# pytest ./tests/test_all_docs.py
5557

5658
- name: CLI tests
5759
run: |
58-
uv run pytest ./tests/test_cli.py
60+
pytest ./tests/test_cli.py
5961
if: ${{ success() || failure() }}
6062

6163
- name: Final answer tests
6264
run: |
63-
uv run pytest ./tests/test_final_answer.py
65+
pytest ./tests/test_final_answer.py
6466
if: ${{ success() || failure() }}
6567

6668
- name: Models tests
6769
run: |
68-
uv run pytest ./tests/test_models.py
70+
pytest ./tests/test_models.py
6971
if: ${{ success() || failure() }}
7072

7173
- name: Memory tests
7274
run: |
73-
uv run pytest ./tests/test_memory.py
75+
pytest ./tests/test_memory.py
7476
if: ${{ success() || failure() }}
7577

7678
- name: Monitoring tests
7779
run: |
78-
uv run pytest ./tests/test_monitoring.py
80+
pytest ./tests/test_monitoring.py
7981
if: ${{ success() || failure() }}
8082

8183
- name: Local Python executor tests
8284
run: |
83-
uv run pytest ./tests/test_local_python_executor.py
85+
pytest ./tests/test_local_python_executor.py
8486
if: ${{ success() || failure() }}
8587

8688
- name: Remote executor tests
8789
run: |
88-
uv run pytest ./tests/test_remote_executors.py
90+
pytest ./tests/test_remote_executors.py
8991
if: ${{ success() || failure() }}
9092

9193
- name: Search tests
9294
run: |
93-
uv run pytest ./tests/test_search.py
95+
pytest ./tests/test_search.py
9496
if: ${{ success() || failure() }}
9597

9698
- name: Tools tests
9799
run: |
98-
uv run pytest ./tests/test_tools.py
100+
pytest ./tests/test_tools.py
99101
if: ${{ success() || failure() }}
100102

101103
- name: Tool validation tests
102104
run: |
103-
uv run pytest ./tests/test_tool_validation.py
105+
pytest ./tests/test_tool_validation.py
104106
if: ${{ success() || failure() }}
105107

106108
- name: Types tests
107109
run: |
108-
uv run pytest ./tests/test_types.py
110+
pytest ./tests/test_types.py
109111
if: ${{ success() || failure() }}
110112

111113
- name: Utils tests
112114
run: |
113-
uv run pytest ./tests/test_utils.py
115+
pytest ./tests/test_utils.py
114116
if: ${{ success() || failure() }}
115117

116118
- name: Gradio UI tests
117119
run: |
118-
uv run pytest ./tests/test_gradio_ui.py
120+
pytest ./tests/test_gradio_ui.py
119121
if: ${{ success() || failure() }}
120122

121123
- name: Function type hints utils tests
122124
run: |
123-
uv run pytest ./tests/test_function_type_hints_utils.py
125+
pytest ./tests/test_function_type_hints_utils.py
124126
if: ${{ success() || failure() }}

tests/test_import.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
import os
12
import subprocess
3+
import tempfile
24

35

4-
def test_import_smolagents_without_extras():
5-
# Run the import statement in an isolated virtual environment
6-
result = subprocess.run(
7-
["uv", "run", "--isolated", "--no-editable", "-"], input="import smolagents", text=True, capture_output=True
8-
)
6+
def test_import_smolagents_without_extras(monkeypatch):
7+
monkeypatch.delenv("VIRTUAL_ENV", raising=False)
8+
with tempfile.TemporaryDirectory() as temp_dir:
9+
# Create a virtual environment
10+
venv_dir = os.path.join(temp_dir, "venv")
11+
subprocess.run(["uv", "venv", venv_dir], check=True)
12+
13+
# Install smolagents in the virtual environment
14+
subprocess.run(
15+
["uv", "pip", "install", "--python", os.path.join(venv_dir, "bin", "python"), "smolagents @ ."], check=True
16+
)
17+
18+
# Run the import test in the virtual environment
19+
result = subprocess.run(
20+
[os.path.join(venv_dir, "bin", "python"), "-c", "import smolagents"],
21+
capture_output=True,
22+
text=True,
23+
)
24+
925
# Check if the import was successful
1026
assert result.returncode == 0, (
1127
"Import failed with error: "

tests/test_tools.py

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
from smolagents.agent_types import _AGENT_TYPE_MAPPING, AgentAudio, AgentImage, AgentText
3131
from smolagents.tools import AUTHORIZED_TYPES, Tool, ToolCollection, tool
3232

33+
from .utils.markers import require_run_all
34+
3335

3436
if is_torch_available():
3537
import torch
@@ -506,6 +508,7 @@ def test_from_mcp(self, mock_server_parameters, mock_mcp_adapt, mock_smolagents_
506508
assert "tool1" in tool_collection.tools
507509
assert "tool2" in tool_collection.tools
508510

511+
@require_run_all
509512
def test_integration_from_mcp(self):
510513
# define the most simple mcp server with one tool that echoes the input text
511514
mcp_server_script = dedent("""\

0 commit comments

Comments
 (0)