Skip to content

Commit

Permalink
fix: reject npm-style version specifiers above v0.4.0 (#24)
Browse files Browse the repository at this point in the history
* Reject npm specifier for >=0.4.0

---------

Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
  • Loading branch information
DanielSchiavini and charles-cooper committed Sep 17, 2024
1 parent c9a294b commit f813e1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 10 additions & 7 deletions tests/test_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"),
],
Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions vvm/utils/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "":
Expand Down

0 comments on commit f813e1f

Please sign in to comment.