Skip to content

Commit

Permalink
Refactor using packaging.version, add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
PProfizi committed Jan 14, 2025
1 parent 84c76c3 commit 5cb6408
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/ansys/dpf/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 3 additions & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
)
Expand Down

0 comments on commit 5cb6408

Please sign in to comment.