diff --git a/src/ansys/dpf/core/_version.py b/src/ansys/dpf/core/_version.py index ebe63301a7..6968146a5a 100644 --- a/src/ansys/dpf/core/_version.py +++ b/src/ansys/dpf/core/_version.py @@ -22,21 +22,27 @@ """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: def __getitem__(self, item): - split = item.split(".") - major = int(split[0]) - minor = int(split[1]) - if major < 2024: - # Detect new cases of XX.Y versions (necessarily XX<2024) - # Compute release version equivalent - minor = 2 - major % 2 - major = 2020 + major // 2 + major % 2 - return f"{major}R{minor}" + version = parse_version(item) + if version.major < 2024: + # Support the current DPF versioning scheme (XX.Y where necessarily XX<2024) + # 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}" + else: + # Support the YEAR.REVISION versioning scheme for DPF + return f"{version.major}R{version.minor}" server_to_ansys_version = ServerToAnsysVersion() diff --git a/tests/test_version.py b/tests/test_version.py index 99110fc030..f3d6a2ea35 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -28,14 +28,16 @@ @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"), + # Proposed calendar-like versioning ("2024.0", "2024R0"), - ("2024.1", "2024R1"), + ("2024.1.12", "2024R1"), ("2024.1.pre0", "2024R1"), ], )