Skip to content

Commit

Permalink
Fix issue with ^0. version specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Sep 17, 2024
1 parent c9a294b commit b3e2895
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 2 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
5 changes: 4 additions & 1 deletion vvm/utils/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ 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
if specifier == "^" and not version_str.startswith("0."):
# Minor match, remove the patch from the version
# Note: not for 0.x versions, they should only match minor versions
version_str = ".".join(version_str.split(".")[:-1])

specifier = "~=" # finds compatible versions

if specifier == "":
Expand Down

0 comments on commit b3e2895

Please sign in to comment.