From 69e310af9b8de6d8398b69c8c9a3c902663c928c Mon Sep 17 00:00:00 2001 From: Eugene Kalinin Date: Tue, 4 Jun 2024 21:42:31 +0300 Subject: [PATCH] Fix version discovery; #356, #357 (#358) --- nodeenv.py | 6 +++++- tests/nodeenv_test.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/nodeenv.py b/nodeenv.py index bbc19fb..245ccd0 100644 --- a/nodeenv.py +++ b/nodeenv.py @@ -175,7 +175,11 @@ def parse_version(version_str): """ Parse version string to a tuple of integer parts """ - return tuple(map(int, version_str.replace('v', '').split('.'))) + v = version_str.replace('v', '').split('.')[:3] + # remove all after '+' in the PATCH part of the version + if len(v) >= 3: + v[2] = v[2].split('+')[0] + return tuple(map(int, v)) def node_version_from_args(args): diff --git a/tests/nodeenv_test.py b/tests/nodeenv_test.py index 302e373..6094c16 100644 --- a/tests/nodeenv_test.py +++ b/tests/nodeenv_test.py @@ -161,3 +161,9 @@ def test__download_node_file(): n_attempt=5 ) assert m_urlopen.call_count == 5 + + +def test_parse_version(): + assert nodeenv.parse_version("v21.7") == (21, 7) + assert nodeenv.parse_version("v21.7.3") == (21, 7, 3) + assert nodeenv.parse_version("v21.7.3+0-b20240228T18452699") == (21, 7, 3)