Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(study): normalize study path #2316

Merged
merged 40 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
72a123f
feature(study): wip
Jan 22, 2025
8220f66
feature(study): normalize path using the slqlachemy property decorator
Jan 23, 2025
99a5b82
Merge branch 'dev' into feature/2547-normalize-study-path
Jan 23, 2025
282fcd6
feature(study): normalize folder path using sqlachemy property
Jan 24, 2025
021df2e
fix(studies): use hybrid property instead of property
Jan 24, 2025
4ce505f
Merge branch 'dev' into feature/2547-normalize-study-path
Jan 24, 2025
9275c03
fix(study): fix test and typing
Jan 27, 2025
390887e
fix(study): use validate instead of property
Jan 27, 2025
2b78876
fix(study): fix tests on windows
Jan 27, 2025
e764c22
fix(build): fix test
Jan 27, 2025
f059970
fix(build): fix types
Jan 27, 2025
d9cb6d0
fix(build): fix tests
Jan 27, 2025
8883830
test only on windows
Jan 28, 2025
7ed7af7
wip
Jan 28, 2025
9729ea5
wip
Jan 28, 2025
c574c15
wip
Jan 28, 2025
7cb32e6
wip
Jan 28, 2025
63a3132
wip debug
Jan 28, 2025
61d3d00
debug
Jan 28, 2025
e9ee35d
debug
Jan 28, 2025
1663c59
debug
Jan 28, 2025
78d474a
debug
Jan 28, 2025
bc7ab11
debug
Jan 28, 2025
9a98403
debug
Jan 28, 2025
09ebc5b
debug
Jan 28, 2025
132e11a
debug
Jan 28, 2025
d0e16c2
debug
Jan 28, 2025
31dc2b9
debug
Jan 28, 2025
d1e2376
debug
Jan 28, 2025
058f898
debug
Jan 28, 2025
e06ed1c
revert tests
Jan 29, 2025
aa633a8
wip
Jan 29, 2025
3cb28c5
wip
Jan 29, 2025
b7a853c
debug
Jan 29, 2025
916969f
debug
Jan 29, 2025
a8d1f25
fix build
Jan 30, 2025
bd5538a
refactor typing
Jan 30, 2025
e3b642d
refactor typing
Jan 30, 2025
e987d24
remove uselless pure windows path
Jan 30, 2025
d14030e
Merge branch 'dev' into feature/2547-normalize-study-path
Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion antarest/study/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import typing as t
import uuid
from datetime import datetime, timedelta
from pathlib import Path
from pathlib import Path, PurePath

from antares.study.version import StudyVersion
from pydantic import BeforeValidator, ConfigDict, Field, PlainSerializer, computed_field, field_validator
Expand All @@ -31,6 +31,7 @@
String,
)
from sqlalchemy.orm import relationship # type: ignore
from sqlalchemy.orm import validates
from typing_extensions import override

from antarest.core.exceptions import ShouldNotHappenException
Expand Down Expand Up @@ -288,6 +289,23 @@ def __eq__(self, other: t.Any) -> bool:
def to_json_summary(self) -> t.Any:
return {"id": self.id, "name": self.name}

@validates("folder") # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sqlachemu doesn't provide a type for this decorator

def validate_folder(self, key: str, folder: t.Optional[str]) -> t.Optional[str]:
"""
We want to store the path in posix format in the database, even on windows.
"""
return normalize_path(folder)


def normalize_path(path: t.Optional[str]) -> t.Optional[str]:
"""
Turns any path including a windows path (with \ separator) to a posix path (with / separator).
"""
if not path:
return path
pure_path = PurePath(path)
return pure_path.as_posix()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: all this could be simplfied in one line:
return PurePath(path).as_posix() if path else path



class RawStudy(Study):
"""
Expand Down
4 changes: 0 additions & 4 deletions tests/storage/business/test_raw_study_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ def test_get(tmp_path: str, project_path) -> None:
data = {"titi": 43}
sub_route = "settings"

path = path_study / "settings"
key = "titi"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables were unused

study = Mock()
study.get.return_value = data
study_factory = Mock()
Expand Down Expand Up @@ -100,7 +97,6 @@ def test_get_cache(tmp_path: str) -> None:
path_study.mkdir()
(path_study / "settings").mkdir()
(path_study / "study.antares").touch()
path = path_study / "settings"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused

data = {"titi": 43}
study = Mock()
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def test_partial_sync_studies_from_disk() -> None:
id=ANY,
path=f"directory{os.sep}f",
name="f",
folder=f"directory{os.sep}f",
folder="directory/f",
created_at=ANY,
missing=None,
public_mode=PublicMode.FULL,
Expand Down
Loading