-
Notifications
You must be signed in to change notification settings - Fork 6
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
Changes from 39 commits
72a123f
8220f66
99a5b82
282fcd6
021df2e
4ce505f
9275c03
390887e
2b78876
e764c22
f059970
d9cb6d0
8883830
7ed7af7
9729ea5
c574c15
7cb32e6
63a3132
61d3d00
e9ee35d
1663c59
78d474a
bc7ab11
9a98403
09ebc5b
132e11a
d0e16c2
31dc2b9
d1e2376
058f898
e06ed1c
aa633a8
3cb28c5
b7a853c
916969f
a8d1f25
bd5538a
e3b642d
e987d24
d14030e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: all this could be simplfied in one line: |
||
|
||
|
||
class RawStudy(Study): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
@@ -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" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was unused |
||
data = {"titi": 43} | ||
study = Mock() | ||
|
There was a problem hiding this comment.
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