Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reject npm-style version specifiers above v0.4.0 #24

Merged
merged 6 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 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,12 @@ 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")
assert (
str(excinfo.value)
== "Please use the pypi-style version specifier for vyper versions >= 0.4.0"
)
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved
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
Loading