Skip to content

Commit f813e1f

Browse files
fix: reject npm-style version specifiers above v0.4.0 (#24)
* Reject npm specifier for >=0.4.0 --------- Co-authored-by: Charles Cooper <[email protected]>
1 parent c9a294b commit f813e1f

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

tests/test_versioning.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
from vvm.exceptions import UnexpectedVersionError
77
from vvm.utils.versioning import _detect_version_specifier, _pick_vyper_version
88

9-
LAST_PER_MINOR = {
10-
1: Version("0.1.0b17"),
11-
2: Version("0.2.16"),
12-
3: Version("0.3.10"),
13-
}
14-
159

1610
def test_foo_vyper_version(foo_source, vyper_version):
1711
specifier = _detect_version_specifier(foo_source)
@@ -23,9 +17,10 @@ def test_foo_vyper_version(foo_source, vyper_version):
2317
@pytest.mark.parametrize(
2418
"version_str,decorator,pragma,expected_specifier,expected_version",
2519
[
26-
("^0.1.1", "public", "@version", "~=0.1", "latest"),
20+
("^0.2.0", "public", "@version", "~=0.2.0", "0.2.16"),
2721
("~0.3.0", "external", "pragma version", "~=0.3.0", "0.3.10"),
2822
("0.1.0b17", "public", "@version", "==0.1.0b17", "0.1.0b17"),
23+
("^0.1.0b16", "public", "@version", "~=0.1.0b16", "0.1.0b17"),
2924
(">=0.3.0-beta17", "external", "@version", ">=0.3.0-beta17", "latest"),
3025
("0.4.0rc6", "external", "pragma version", "==0.4.0rc6", "0.4.0rc6"),
3126
],
@@ -57,3 +52,11 @@ def test_version_does_not_exist():
5752
with pytest.raises(UnexpectedVersionError) as excinfo:
5853
detect_vyper_version_from_source("# pragma version 2024.0.1")
5954
assert str(excinfo.value) == "No installable Vyper satisfies the specifier ==2024.0.1"
55+
56+
57+
def test_npm_version_for_04_release():
58+
with pytest.raises(UnexpectedVersionError) as excinfo:
59+
detect_vyper_version_from_source("# pragma version ^0.4.0")
60+
61+
expected_msg = "Please use the pypi-style version specifier for vyper versions >= 0.4.0"
62+
assert str(excinfo.value) == expected_msg

vvm/utils/versioning.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ def _detect_version_specifier(source_code: str) -> Specifier:
3131

3232
specifier, version_str = match.groups()
3333
if specifier in ("~", "^"): # convert from npm-style to pypi-style
34-
if specifier == "^": # minor match, remove the patch from the version
35-
version_str = ".".join(version_str.split(".")[:-1])
34+
if Version(version_str) >= Version("0.4.0"):
35+
error = "Please use the pypi-style version specifier for vyper versions >= 0.4.0"
36+
raise UnexpectedVersionError(error)
37+
# for v0.x, both specifiers are equivalent
3638
specifier = "~=" # finds compatible versions
3739

3840
if specifier == "":

0 commit comments

Comments
 (0)