Skip to content

Commit e8d78c4

Browse files
Merge pull request #1793 from velodrome-finance/vyper-v0.4
Vyper v0.4
2 parents 196e94f + 326cce6 commit e8d78c4

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

brownie/project/compiler/utils.py

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
def expand_source_map(source_map_str: str) -> List:
1010
# Expands the compressed sourceMap supplied by solc into a list of lists
11+
12+
if isinstance(source_map_str, dict):
13+
# NOTE: vyper >= 0.4 gives us a dict that contains the source map
14+
source_map_str = source_map_str["pc_pos_map_compressed"]
15+
if not isinstance(source_map_str, str):
16+
raise TypeError(source_map_str)
17+
1118
source_map: List = [_expand_row(i) if i else None for i in source_map_str.split(";")]
1219
for i, value in enumerate(source_map[1:], 1):
1320
if value is None:

brownie/project/compiler/vyper.py

+34-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import vvm
99
import vyper
10+
from packaging.version import Version as PVersion
1011
from requests.exceptions import ConnectionError
1112
from semantic_version import Version
1213
from vyper.cli import vyper_json
@@ -46,11 +47,14 @@ def set_vyper_version(version: Union[str, Version]) -> str:
4647
if isinstance(version, str):
4748
version = Version(version)
4849
if version != Version(vyper.__version__):
50+
# NOTE: vvm uses `packaging.version.Version` which is not compatible with
51+
# `semantic_version.Version` so we first must cast it as a string
52+
version_str = str(version)
4953
try:
50-
vvm.set_vyper_version(version, silent=True)
54+
vvm.set_vyper_version(version_str, silent=True)
5155
except vvm.exceptions.VyperNotInstalled:
5256
install_vyper(version)
53-
vvm.set_vyper_version(version, silent=True)
57+
vvm.set_vyper_version(version_str, silent=True)
5458
_active_version = version
5559
return str(_active_version)
5660

@@ -82,13 +86,13 @@ def get_abi(contract_source: str, name: str) -> Dict:
8286

8387
def _get_vyper_version_list() -> Tuple[List, List]:
8488
global AVAILABLE_VYPER_VERSIONS
85-
installed_versions = vvm.get_installed_vyper_versions()
89+
installed_versions = _convert_to_semver(vvm.get_installed_vyper_versions())
8690
lib_version = Version(vyper.__version__)
8791
if lib_version not in installed_versions:
8892
installed_versions.append(lib_version)
8993
if AVAILABLE_VYPER_VERSIONS is None:
9094
try:
91-
AVAILABLE_VYPER_VERSIONS = vvm.get_installable_vyper_versions()
95+
AVAILABLE_VYPER_VERSIONS = _convert_to_semver(vvm.get_installable_vyper_versions())
9296
except ConnectionError:
9397
if not installed_versions:
9498
raise ConnectionError("Vyper not installed and cannot connect to GitHub")
@@ -237,11 +241,14 @@ def compile_from_input_json(
237241
outputs.remove("devdoc")
238242
if version == Version(vyper.__version__):
239243
try:
240-
return vyper_json.compile_json(input_json, root_path=allow_paths)
244+
return vyper_json.compile_json(input_json)
241245
except VyperException as exc:
242246
raise exc.with_traceback(None)
243247
else:
244248
try:
249+
# NOTE: vvm uses `packaging.version.Version` which is not compatible with
250+
# `semantic_version.Version` so we first must cast it as a string
251+
version = str(version)
245252
return vvm.compile_standard(input_json, base_path=allow_paths, vyper_version=version)
246253
except vvm.exceptions.VyperError as exc:
247254
raise CompilerError(exc, "vyper")
@@ -397,7 +404,7 @@ def _generate_coverage_data(
397404

398405
if node["ast_type"] in ("Assert", "If") or (
399406
node["ast_type"] == "Expr"
400-
and node["value"]["func"].get("id", None) == "assert_modifiable"
407+
and node["value"].get("func", {}).get("id", None) == "assert_modifiable"
401408
):
402409
# branch coverage
403410
pc_list[-1]["branch"] = count
@@ -449,3 +456,24 @@ def _get_statement_nodes(ast_json: List) -> List:
449456
else:
450457
stmt_nodes.append(node)
451458
return stmt_nodes
459+
460+
461+
def _convert_to_semver(versions: List[PVersion]) -> List[Version]:
462+
"""
463+
Converts a list of `packaging.version.Version` objects to a list of
464+
`semantic_version.Version` objects.
465+
466+
vvm 0.2.0 switched to packaging.version but we are not ready to
467+
migrate brownie off of semantic-version.
468+
469+
This function serves as a stopgap.
470+
"""
471+
return [
472+
Version(
473+
major=version.major,
474+
minor=version.minor,
475+
patch=version.micro,
476+
prerelease="".join(str(x) for x in version.pre) if version.pre else None,
477+
)
478+
for version in versions
479+
]

requirements.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ requests>=2.25.0,<3
2323
rlp
2424
semantic-version<3
2525
tqdm<5
26-
vvm==0.1.0 # 0.2.0 switches from semantic-version to packaging.version and things break
27-
vyper>=0.3.8,<0.4
26+
vvm==0.2.1
27+
vyper>=0.4.0,<0.5
2828
web3>=6,<7
2929
wrapt>=1.12.1,<2

requirements.txt

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.11
2+
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
55
# pip-compile requirements.in
@@ -10,6 +10,8 @@ aiosignal==1.3.1
1010
# via aiohttp
1111
asttokens==2.4.1
1212
# via vyper
13+
async-timeout==4.0.3
14+
# via aiohttp
1315
attrs==23.2.0
1416
# via
1517
# aiohttp
@@ -125,6 +127,7 @@ packaging==23.2
125127
# via
126128
# black
127129
# pytest
130+
# vvm
128131
# vyper
129132
parsimonious==0.9.0
130133
# via eth-abi
@@ -200,7 +203,6 @@ semantic-version==2.10.0
200203
# via
201204
# -r requirements.in
202205
# py-solc-x
203-
# vvm
204206
six==1.16.0
205207
# via
206208
# asttokens
@@ -209,20 +211,23 @@ sortedcontainers==2.4.0
209211
# via hypothesis
210212
toml==0.10.2
211213
# via pytest
214+
tomli==2.0.1
215+
# via black
212216
toolz==0.12.1
213217
# via cytoolz
214218
tqdm==4.66.2
215219
# via -r requirements.in
216220
typing-extensions==4.9.0
217221
# via
222+
# black
218223
# eth-rlp
219224
# eth-typing
220225
# web3
221226
urllib3==2.2.1
222227
# via requests
223-
vvm==0.1.0
228+
vvm==0.2.1
224229
# via -r requirements.in
225-
vyper==0.3.10
230+
vyper==0.4.0
226231
# via -r requirements.in
227232
wcwidth==0.2.13
228233
# via prompt-toolkit

0 commit comments

Comments
 (0)