Skip to content

Commit f399964

Browse files
committed
only top level dockerfile
1 parent a710578 commit f399964

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

eval_protocol/cli_commands/local_test.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99

1010

1111
def _find_dockerfiles(root: str) -> List[str]:
12-
skip_dirs = {".venv", "venv", "node_modules", "dist", "build", "__pycache__", ".git", "vendor"}
12+
"""Return Dockerfiles in the project root only (no recursive search)."""
1313
dockerfiles: List[str] = []
14-
for dirpath, dirnames, filenames in os.walk(root):
15-
dirnames[:] = [d for d in dirnames if d not in skip_dirs and not d.startswith(".")]
16-
for name in filenames:
17-
if name == "Dockerfile":
18-
dockerfiles.append(os.path.join(dirpath, name))
14+
root_dockerfile = os.path.join(root, "Dockerfile")
15+
if os.path.isfile(root_dockerfile):
16+
dockerfiles.append(root_dockerfile)
1917
return dockerfiles
2018

2119

tests/test_cli_local_test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@
44
import pytest
55

66

7+
def test_find_dockerfiles_top_level_only(tmp_path, monkeypatch):
8+
# Project root with both top-level and nested Dockerfiles – only top-level should be returned.
9+
project = tmp_path / "proj"
10+
project.mkdir()
11+
top_level = project / "Dockerfile"
12+
top_level.write_text("FROM python:3.11-slim\n", encoding="utf-8")
13+
nested_dir = project / "nested"
14+
nested_dir.mkdir()
15+
(nested_dir / "Dockerfile").write_text("FROM python:3.11-slim\n", encoding="utf-8")
16+
17+
from eval_protocol.cli_commands import local_test as lt
18+
19+
dockerfiles = lt._find_dockerfiles(str(project))
20+
assert dockerfiles == [str(top_level)]
21+
22+
23+
def test_find_dockerfiles_ignores_nested_only(tmp_path, monkeypatch):
24+
# Project root without top-level Dockerfile but with nested ones – should return empty.
25+
project = tmp_path / "proj"
26+
project.mkdir()
27+
nested_dir = project / "nested"
28+
nested_dir.mkdir()
29+
(nested_dir / "Dockerfile").write_text("FROM python:3.11-slim\n", encoding="utf-8")
30+
31+
from eval_protocol.cli_commands import local_test as lt
32+
33+
dockerfiles = lt._find_dockerfiles(str(project))
34+
assert dockerfiles == []
35+
36+
737
def test_local_test_runs_host_pytest_with_entry(tmp_path, monkeypatch):
838
project = tmp_path / "proj"
939
project.mkdir()

0 commit comments

Comments
 (0)