Skip to content

Commit

Permalink
Fix server_to_ansys_version (#2013)
Browse files Browse the repository at this point in the history
* Fix/refactor ansys.dpf.core._version.ServerToAnsysVersion

* Add testing

* Refactor using packaging.version, add comments.

* Remove support for proposed DPF versioning YEAR.REVISION.PATCH

* Update test_checkversion.test_version
  • Loading branch information
PProfizi authored Jan 14, 2025
1 parent f89b36c commit a1bfa92
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
35 changes: 11 additions & 24 deletions src/ansys/dpf/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,23 @@

"""Version for ansys-dpf-core."""

from packaging.version import parse as parse_version

# Minimal DPF server version supported
min_server_version = "4.0"


class ServerToAnsysVersion:
legacy_version_map = {
"1.0": "2021R1",
"2.0": "2021R2",
"3.0": "2022R1",
"4.0": "2022R2",
"5.0": "2023R1",
"6.0": "2023R2",
"6.1": "2023R2",
"6.2": "2023R2",
"7.0": "2024R1",
"7.1": "2024R1",
"8.0": "2024R2",
"8.1": "2024R2",
"8.2": "2024R2",
"9.0": "2025R1",
"9.1": "2025R1",
"10.0": "2025R2",
}

def __getitem__(self, item):
if len(item) == 3:
return self.legacy_version_map[item]
else:
split = item.split(".")
return split[0] + "R" + split[1]
version = parse_version(item)
# The current DPF versioning scheme is MAJOR.MINOR.PATCH
# Compute release version equivalent (YEAR+'R'+REVISION)
# The revision is 'R1' for any odd major DPF version, 'R2' for even major versions.
ansys_revision = 2 - version.major % 2
# The year is 2021 for DPF 1.0, and bumped every two releases.
ansys_year = 2020 + version.major // 2 + version.major % 2
# Return the corresponding Ansys release
return f"{ansys_year}R{ansys_revision}"


server_to_ansys_version = ServerToAnsysVersion()
2 changes: 1 addition & 1 deletion tests/test_checkversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ def test_version():
from ansys.dpf.core._version import server_to_ansys_version

assert server_to_ansys_version["1.0"] == "2021R1"
assert server_to_ansys_version["2099.9"] == "2099R9"
assert server_to_ansys_version["10.0.12"] == "2025R2"
41 changes: 41 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (C) 2020 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import pytest

from ansys.dpf.core._version import server_to_ansys_version


@pytest.mark.parametrize(
"server_version,ansys_version",
[
# Current DPF versioning
("1.0", "2021R1"),
("2.0", "2021R2"),
("2.1", "2021R2"),
("3.0", "2022R1"),
("2023.0", "3032R1"),
("2023.1.12", "3032R1"),
],
)
def test_server_to_ansys_version(server_version, ansys_version):
assert server_to_ansys_version[server_version] == ansys_version

0 comments on commit a1bfa92

Please sign in to comment.