Skip to content

Commit

Permalink
use vvm for version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
trocher committed Nov 18, 2024
1 parent fc10a52 commit 2a9964f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 45 deletions.
21 changes: 8 additions & 13 deletions boa/interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import vvm
import vyper
from packaging.specifiers import SpecifierSet
from packaging.version import Version
from vvm.utils.versioning import detect_vyper_version_from_source
from vyper.ast.parse import parse_to_ast
from vyper.cli.vyper_compile import get_search_paths
from vyper.compiler.input_bundle import (
Expand All @@ -35,7 +36,6 @@
from boa.rpc import json
from boa.util.abi import Address
from boa.util.disk_cache import DiskCache
from boa.util.version import detect_version

if TYPE_CHECKING:
from vyper.semantics.analysis.base import ImportInfo
Expand Down Expand Up @@ -251,11 +251,13 @@ def loads_partial(
if dedent:
source_code = textwrap.dedent(source_code)

version_set = detect_version(source_code)
if version_set is not None and not version_set.contains(vyper.__version__):
# TODO: let vvm know our preferred version (vyper.__version__)
version = detect_vyper_version_from_source(source_code)
if version is not None and version != Version(vyper.__version__):
filename = str(filename) # help mypy
# TODO: pass name to loads_partial_vvm, not filename
return _loads_partial_vvm(source_code, version_set, filename)
return _loads_partial_vvm(source_code, version, filename)

compiler_args = compiler_args or {}

deployer_class = _get_default_deployer_class()
Expand All @@ -270,16 +272,9 @@ def load_partial(filename: str, compiler_args=None):
)


def _loads_partial_vvm(source_code: str, version_set: SpecifierSet, filename: str):
def _loads_partial_vvm(source_code: str, version: Version, filename: str):
global _disk_cache

available = vvm.get_installable_vyper_versions()
# get the most recent version compatible with the set
version = next(version_set.filter(available), None)

if version is None:
raise ValueError(f"no matching version found for {version_set}")

# install the requested version if not already installed
vvm.install_vyper(version=version)

Expand Down
22 changes: 0 additions & 22 deletions boa/util/version.py

This file was deleted.

21 changes: 14 additions & 7 deletions tests/unitary/contracts/vvm/test_vvm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

import boa

mock_3_10_path = "tests/unitary/contracts/vvm/mock_3_10.vy"
Expand Down Expand Up @@ -29,18 +31,23 @@ def test_load_vvm():
assert contract.bar() == 43


def test_load_complex_version_vvm():
contracts = [
@pytest.mark.parametrize(
"version_pragma",
[
"# @version ^0.3.1",
"# @version ^0.3.7",
"# @version ==0.3.10",
"# pragma version >=0.3.8, <0.4.0, !=0.3.10",
"# @version ~=0.3.10",
"# @version 0.3.10",
# "# pragma version >=0.3.8, <0.4.0, !=0.3.10",
# TODO: uncomment when vvm accept Specifier sets
# "# pragma version ==0.4.0rc3",
# TODO: uncomment when vvm is fixed (https://github.com/vyperlang/vvm/pull/29)
]
for contract in contracts:
contract = boa.loads(contract + "\nfoo: public(uint256)")
assert contract.foo() == 0
],
)
def test_load_complex_version_vvm(version_pragma):
contract = boa.loads(version_pragma + "\nfoo: public(uint256)")
assert contract.foo() == 0


def test_loads_vvm():
Expand Down
6 changes: 3 additions & 3 deletions tests/unitary/utils/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest.mock import patch

import pytest
from packaging.specifiers import SpecifierSet
from packaging.version import Version
from vyper.compiler import CompilerData

from boa.contracts.vyper.vyper_contract import VyperDeployer
Expand Down Expand Up @@ -35,8 +35,8 @@ def test_cache_vvm():
code = """
x: constant(int128) = 1000
"""
version = SpecifierSet("==0.2.8")
version2 = SpecifierSet("==0.3.1")
version = Version("0.2.8")
version2 = Version("0.3.1")
assert _disk_cache is not None

# Mock vvm.compile_source
Expand Down

0 comments on commit 2a9964f

Please sign in to comment.