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

Fix server_to_ansys_version #2013

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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"),
BClappe marked this conversation as resolved.
Show resolved Hide resolved
],
)
def test_server_to_ansys_version(server_version, ansys_version):
assert server_to_ansys_version[server_version] == ansys_version
Loading