Skip to content

Commit cf0b176

Browse files
authored
fix(web): adjusting paths to fix windows (#5998)
Signed-off-by: Cortland Goffena <30168413+cmgoffena13@users.noreply.github.com>
1 parent c99553f commit cf0b176

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

‎tests/web/test_main.py‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import threading
4-
from pathlib import Path
4+
from pathlib import Path, PureWindowsPath
55

66
import pyarrow as pa # type: ignore
77
import pytest
@@ -75,6 +75,32 @@ def test_get_file(client: TestClient, project_tmp_path: Path) -> None:
7575
}
7676

7777

78+
def test_get_file_nested_path_matches_directory_listing(
79+
client: TestClient, project_tmp_path: Path
80+
) -> None:
81+
models_dir = project_tmp_path / "models"
82+
models_dir.mkdir()
83+
(models_dir / "mymodel.sql").write_text("SELECT 1")
84+
85+
response = client.get("/api/files/models/mymodel.sql")
86+
assert response.status_code == 200
87+
assert response.json()["path"] == "models/mymodel.sql"
88+
89+
90+
def test_get_file_relative_path_uses_posix_separators(tmp_path: Path) -> None:
91+
file_path = tmp_path / "models" / "mymodel.sql"
92+
file_path.parent.mkdir(parents=True)
93+
file_path.write_text("SELECT 1")
94+
95+
windows_relative = PureWindowsPath("models/mymodel.sql")
96+
assert windows_relative.as_posix() == "models/mymodel.sql"
97+
assert str(windows_relative) == "models\\mymodel.sql"
98+
99+
file = _get_file_with_content(file_path, windows_relative.as_posix())
100+
assert file.path == "models/mymodel.sql"
101+
assert file.path != str(windows_relative)
102+
103+
78104
def test_get_file_not_found(client: TestClient) -> None:
79105
response = client.get("/api/files/not_found.txt")
80106
assert response.status_code == 404

‎web/server/api/endpoints/files.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_file(
3737
"""Get a file, including its contents."""
3838
try:
3939
file_path = Path(path)
40-
file = _get_file_with_content(settings.project_path / file_path, str(file_path))
40+
file = _get_file_with_content(settings.project_path / file_path, file_path.as_posix())
4141
except FileNotFoundError:
4242
raise HTTPException(status_code=HTTP_404_NOT_FOUND)
4343

@@ -155,7 +155,7 @@ def walk_path(
155155
return sorted(directories, key=lambda x: x.name), sorted(files, key=lambda x: x.name)
156156

157157
directories, files = walk_path(path)
158-
relative_path = str(Path(path).relative_to(settings.project_path))
158+
relative_path = Path(path).relative_to(settings.project_path).as_posix()
159159

160160
return models.Directory(
161161
name=os.path.basename(path),

‎web/server/watcher.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def watch_project() -> None:
5555
changes.append(
5656
models.ArtifactChange(
5757
change=Change.deleted,
58-
path=str(relative_path),
58+
path=relative_path.as_posix(),
5959
)
6060
)
6161
elif change == Change.added:
@@ -69,9 +69,9 @@ async def watch_project() -> None:
6969
models.ArtifactChange(
7070
type=models.ArtifactType.file,
7171
change=change,
72-
path=str(relative_path),
72+
path=relative_path.as_posix(),
7373
file=_get_file_with_content(
74-
settings.project_path / relative_path, str(relative_path)
74+
settings.project_path / relative_path, relative_path.as_posix()
7575
),
7676
)
7777
)

0 commit comments

Comments
 (0)