From f813e1f9ba8774123431e8a3d135aa8a2d3f9f5d Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Tue, 17 Sep 2024 17:19:04 +0200 Subject: [PATCH] fix: reject npm-style version specifiers above v0.4.0 (#24) * Reject npm specifier for >=0.4.0 --------- Co-authored-by: Charles Cooper --- tests/test_versioning.py | 17 ++++++++++------- vvm/utils/versioning.py | 6 ++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/test_versioning.py b/tests/test_versioning.py index 3ed491d..4a24d3b 100644 --- a/tests/test_versioning.py +++ b/tests/test_versioning.py @@ -6,12 +6,6 @@ from vvm.exceptions import UnexpectedVersionError from vvm.utils.versioning import _detect_version_specifier, _pick_vyper_version -LAST_PER_MINOR = { - 1: Version("0.1.0b17"), - 2: Version("0.2.16"), - 3: Version("0.3.10"), -} - def test_foo_vyper_version(foo_source, vyper_version): specifier = _detect_version_specifier(foo_source) @@ -23,9 +17,10 @@ def test_foo_vyper_version(foo_source, vyper_version): @pytest.mark.parametrize( "version_str,decorator,pragma,expected_specifier,expected_version", [ - ("^0.1.1", "public", "@version", "~=0.1", "latest"), + ("^0.2.0", "public", "@version", "~=0.2.0", "0.2.16"), ("~0.3.0", "external", "pragma version", "~=0.3.0", "0.3.10"), ("0.1.0b17", "public", "@version", "==0.1.0b17", "0.1.0b17"), + ("^0.1.0b16", "public", "@version", "~=0.1.0b16", "0.1.0b17"), (">=0.3.0-beta17", "external", "@version", ">=0.3.0-beta17", "latest"), ("0.4.0rc6", "external", "pragma version", "==0.4.0rc6", "0.4.0rc6"), ], @@ -57,3 +52,11 @@ def test_version_does_not_exist(): with pytest.raises(UnexpectedVersionError) as excinfo: detect_vyper_version_from_source("# pragma version 2024.0.1") assert str(excinfo.value) == "No installable Vyper satisfies the specifier ==2024.0.1" + + +def test_npm_version_for_04_release(): + with pytest.raises(UnexpectedVersionError) as excinfo: + detect_vyper_version_from_source("# pragma version ^0.4.0") + + expected_msg = "Please use the pypi-style version specifier for vyper versions >= 0.4.0" + assert str(excinfo.value) == expected_msg diff --git a/vvm/utils/versioning.py b/vvm/utils/versioning.py index b59ebb0..cbbc625 100644 --- a/vvm/utils/versioning.py +++ b/vvm/utils/versioning.py @@ -31,8 +31,10 @@ def _detect_version_specifier(source_code: str) -> Specifier: specifier, version_str = match.groups() if specifier in ("~", "^"): # convert from npm-style to pypi-style - if specifier == "^": # minor match, remove the patch from the version - version_str = ".".join(version_str.split(".")[:-1]) + if Version(version_str) >= Version("0.4.0"): + error = "Please use the pypi-style version specifier for vyper versions >= 0.4.0" + raise UnexpectedVersionError(error) + # for v0.x, both specifiers are equivalent specifier = "~=" # finds compatible versions if specifier == "":