Skip to content

Commit

Permalink
fix: Handle non-standard software versions with alpha characters in t…
Browse files Browse the repository at this point in the history
…he last part of the version. (tektronix#81)

Signed-off-by: qthompso <[email protected]>
  • Loading branch information
nfelt14 authored and qthompso committed Feb 15, 2024
1 parent 49257d6 commit 8c730fe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Things to be included in the next release go here.
### Fixed

- Updated the auto-generated commands for a handful of models to fix various issues
- Updated the function responsible for converting version strings into `Version` objects to be able to handle software versions with non-standard formats.

______________________________________________________________________

Expand Down
10 changes: 9 additions & 1 deletion src/tm_devices/helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ def get_version(version_string: str) -> Version:
The Version object.
"""
version_parts = version_string.split(".")
found_alpha = False
try:
version = Version(version_string)
except InvalidVersion:
Expand All @@ -413,7 +414,14 @@ def get_version(version_string: str) -> Version:
version_string.replace("." + version_parts[-1], "+" + version_parts[-1])
)
else:
raise
output_str = ""
for char in version_parts[-1]:
if char.isalpha() and not found_alpha:
output_str += "+" + char
found_alpha = True
else:
output_str += char
version = Version(version_string.replace(version_parts[-1], output_str))
return version


Expand Down
2 changes: 2 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ def test_detect_visa_resource_expression(
("1.2.3", Version("1.2.3")),
("1.265.301", Version("1.265.301")),
("1.2.3.abc", Version("1.2.3+abc")),
("1.2.3.4abc", Version("1.2.3.4+abc")),
("1.20.345.abc", Version("1.20.345+abc")),
("1.20.345.4abc123", Version("1.20.345.4+abc123")),
],
)
def test_get_version(version_string: str, expected_result: Version) -> None:
Expand Down

0 comments on commit 8c730fe

Please sign in to comment.