Skip to content

Commit

Permalink
release-1.0.6 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle authored Sep 25, 2024
1 parent 615a313 commit fdf2bc8
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 31 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

v1.0.6 (2024-09-25)
-------------------

- revert change in release v1.0.5 as it was a mistake
- v8.6 update puts field `enable-first-step` at False instead of True

v1.0.5 (2024-09-25)
-------------------

Expand Down
14 changes: 7 additions & 7 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Using the `antares-study-version` module is straightforward:
from antares.study.version import StudyVersion

version = StudyVersion(8, 7, 2) # patch component is not used
print(version) # 870
print(version) # 8.7
```

You can also create a version object from a dotted string:
Expand All @@ -24,7 +24,7 @@ You can also create a version object from a dotted string:
from antares.study.version import StudyVersion

version = StudyVersion.parse("8.7")
print(version) # 870
print(version) # 8.7
```

You can create a version object from a compact string:
Expand All @@ -33,7 +33,7 @@ You can create a version object from a compact string:
from antares.study.version import StudyVersion

version = StudyVersion.parse("870")
print(version) # 870
print(version) # 8.7
```

You can create a version object from an integer:
Expand All @@ -42,7 +42,7 @@ You can create a version object from an integer:
from antares.study.version import StudyVersion

version = StudyVersion.parse(870)
print(version) # 870
print(version) # 8.7
```

You can compare versions:
Expand All @@ -61,10 +61,10 @@ You can convert a version to string using format specifiers:
from antares.study.version import StudyVersion

version = StudyVersion(8, 7)
print(f"{version}d.d.d") # 8.7
print(version) # 8.7
print(f"{version:02d}") # 08.07
print(f"{version:03d}") # 08.07.00
print(version) # 870
print(f"{version:ddd}") # 870
```

You can convert a version to an integer:
Expand All @@ -84,7 +84,7 @@ Of course, the same operations can be done with `SolverVersion` objects, but wit
from antares.study.version import SolverVersion

version = SolverVersion(8, 7, 2)
print(version) # 872
print(version) # 8.7.2
```

Objects of the `StudyVersion` and `SolverVersion` classes can be compared to each other:
Expand Down
2 changes: 1 addition & 1 deletion src/antares/study/version/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Standard project metadata

__version__ = "1.0.5"
__version__ = "1.0.6"
__author__ = "RTE, Antares Web Team"
__date__ = "2024-07-06"
__credits__ = "© Réseau de Transport de l’Électricité (RTE)"
2 changes: 1 addition & 1 deletion src/antares/study/version/model/study_antares.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def to_ini_file(self, study_dir: t.Union[str, Path], update_save_date: bool = Tr

if self.version < DOTTED_VERSION: # type: ignore
# Old versions of Antares Studies used a different format for the version number
section_dict["version"] = f"{self.version:}"
section_dict["version"] = f"{self.version:ddd}"
else:
section_dict["version"] = f"{self.version.major}.{self.version.minor}"

Expand Down
20 changes: 10 additions & 10 deletions src/antares/study/version/model/study_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def parse(cls: t.Type[T], other: object) -> T:
# Conversion methods

def __str__(self) -> str:
return f"{int(self):03d}"
if self.patch:
return f"{self.major}.{self.minor}.{self.patch}"
elif self.minor:
return f"{self.major}.{self.minor}"
else:
return f"{self.major}"

def __int__(self) -> int:
return self.major * 100 + self.minor * 10 + self.patch
Expand Down Expand Up @@ -90,12 +95,12 @@ def __format__(self, format_spec: str) -> str:
"""
Format the version number "X.Y.Z" according to the format specifier:
- "" => "XYZ"
- "" => "X.Y.Z" or "X.Y" if patch is 0, or "X" if minor is 0.
- "1d" => "X",
- "2d" => "X.Y",
- "01d" => "0X",
- "02d" => "0X.0Y"
- "d.d.d" => "X.Y.Z" or "X.Y" if patch is 0, or "X" if minor is 0.
- "d.d.d" => "XYZ"
:param format_spec: format specifier.
Expand All @@ -116,13 +121,8 @@ def __format__(self, format_spec: str) -> str:
return f"{major:02d}.{minor:02d}"
elif format_spec == "03d":
return f"{major:02d}.{minor:02d}.{patch:02d}"
elif format_spec == "d.d.d":
if self.patch:
return f"{self.major}.{self.minor}.{self.patch}"
elif self.minor:
return f"{self.major}.{self.minor}"
else:
return f"{self.major}"
elif format_spec == "ddd":
return f"{int(self):03d}"
else:
raise ValueError(f"Invalid format specifier: '{format_spec}'")

Expand Down
2 changes: 1 addition & 1 deletion src/antares/study/version/upgrade_app/upgrader_0806.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def upgrade(cls, study_dir: Path) -> None:
study_dir: The study directory.
"""
data = GeneralData.from_ini_file(study_dir)
data["adequacy patch"]["enable-first-step "] = True
data["adequacy patch"]["enable-first-step"] = False
data.to_ini_file(study_dir)

study_dir.joinpath("input", "st-storage", "clusters").mkdir(parents=True, exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/create_app/test_create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_no_template_available(self, tmp_path: Path):
study_dir = tmp_path.joinpath("my-new-study")
study_version = StudyVersion.parse("2.8")
app = CreateApp(study_dir=study_dir, caption="My New App", version=study_version, author="Robert Smith")
with pytest.raises(ApplicationError, match=re.escape(str(study_version))):
with pytest.raises(ApplicationError, match=re.escape(f"{study_version:2d}")):
app()

@pytest.mark.parametrize("study_version", AVAILABLE_VERSIONS)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_cli__create(self, tmp_path: Path, study_version: StudyVersion) -> None:
parser.read(study_antares_file, encoding="utf-8")
section_dict = dict(parser["antares"])
if study_version < 900:
expected_version = f"{study_version:}"
expected_version = f"{study_version:ddd}"
else:
expected_version = f"{study_version.major}.{study_version.minor}"

Expand Down
18 changes: 9 additions & 9 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test___str__(self) -> None:
version = SolverVersion(4, 5, 6)
result = version.__str__()
assert isinstance(result, str)
assert result == "456"
assert result == "4.5.6"

def test___int__(self) -> None:
version = SolverVersion(4, 5, 6)
Expand All @@ -51,14 +51,14 @@ def test_parse(self) -> None:
@pytest.mark.parametrize(
"format_spec, expected",
[
pytest.param("d.d.d", "4.5.6", id="empty"),
pytest.param("", "4.5.6", id="empty"),
pytest.param("1d", "4", id="format-1d"),
pytest.param("2d", "4.5", id="format-2d"),
pytest.param("3d", "4.5.6", id="format-3d"),
pytest.param("01d", "04", id="format-01d"),
pytest.param("02d", "04.05", id="format-02d"),
pytest.param("03d", "04.05.06", id="format-03d"),
pytest.param("", "456", id="format-ddd"),
pytest.param("ddd", "456", id="format-ddd"),
pytest.param("X", "", marks=pytest.mark.xfail(raises=ValueError, strict=True)),
],
)
Expand Down Expand Up @@ -93,7 +93,7 @@ def test___str__(self) -> None:
version = StudyVersion(4, 5)
result = version.__str__()
assert isinstance(result, str)
assert result == "450"
assert result == "4.5"

def test___int__(self) -> None:
version = StudyVersion(4, 5)
Expand All @@ -109,14 +109,14 @@ def test_parse(self) -> None:
@pytest.mark.parametrize(
"format_spec, expected",
[
pytest.param("d.d.d", "4.5", id="empty"),
pytest.param("", "4.5", id="empty"),
pytest.param("1d", "4", id="format-1d"),
pytest.param("2d", "4.5", id="format-2d"),
pytest.param("3d", "4.5.0", id="format-3d"),
pytest.param("01d", "04", id="format-01d"),
pytest.param("02d", "04.05", id="format-02d"),
pytest.param("03d", "04.05.00", id="format-03d"),
pytest.param("", "450", id="format-ddd"),
pytest.param("ddd", "450", id="format-ddd"),
pytest.param("X", "", marks=pytest.mark.xfail(raises=ValueError, strict=True)),
],
)
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_ini_file(self):

# We can write the study version to an INI file
version = StudyVersion(10, 2)
config["antares"]["version"] = version.__format__("d.d.d")
config["antares"]["version"] = str(version)

stream.seek(0)
config.write(stream)
Expand Down Expand Up @@ -252,7 +252,7 @@ def test_version_str(self):
assert version == StudyVersion(8, 7)

# We can convert a version number to a string
assert str(version) == "870"
assert str(version) == "8.7"

# We can compare string versions using the standard comparison operators
assert version == "8.7"
Expand All @@ -272,7 +272,7 @@ def test_version_str(self):
# We can construct a version number from a string with a single number
version = StudyVersion.parse("8")
assert version == StudyVersion(8)
assert str(version) == "800"
assert str(version) == "8"

# noinspection PyDataclass,PyTypeChecker
def test_version_triplet(self):
Expand Down
8 changes: 8 additions & 0 deletions tests/upgrade_app/test_upgrade_0806.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from antares.study.version.ini_reader import IniReader
from antares.study.version.upgrade_app.upgrader_0806 import UpgradeTo0806
from tests.conftest import StudyAssets
from tests.helpers import are_same_dir
Expand All @@ -15,3 +16,10 @@ def test_nominal_case(study_assets: StudyAssets):
actual_input_path = study_assets.study_dir.joinpath("input")
expected_input_path = study_assets.expected_dir.joinpath("input")
assert are_same_dir(actual_input_path, expected_input_path)

# compare generaldata.ini
actual_path = study_assets.study_dir.joinpath("settings/generaldata.ini")
actual = IniReader().read(actual_path)
expected_path = study_assets.expected_dir.joinpath("settings/generaldata.ini")
expected = IniReader().read(expected_path)
assert actual == expected
Binary file not shown.

0 comments on commit fdf2bc8

Please sign in to comment.