|
7 | 7 |
|
8 | 8 | import vvm
|
9 | 9 | import vyper
|
| 10 | +from packaging.version import Version as PVersion |
10 | 11 | from requests.exceptions import ConnectionError
|
11 | 12 | from semantic_version import Version
|
12 | 13 | from vyper.cli import vyper_json
|
@@ -46,11 +47,14 @@ def set_vyper_version(version: Union[str, Version]) -> str:
|
46 | 47 | if isinstance(version, str):
|
47 | 48 | version = Version(version)
|
48 | 49 | 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) |
49 | 53 | try:
|
50 |
| - vvm.set_vyper_version(version, silent=True) |
| 54 | + vvm.set_vyper_version(version_str, silent=True) |
51 | 55 | except vvm.exceptions.VyperNotInstalled:
|
52 | 56 | install_vyper(version)
|
53 |
| - vvm.set_vyper_version(version, silent=True) |
| 57 | + vvm.set_vyper_version(version_str, silent=True) |
54 | 58 | _active_version = version
|
55 | 59 | return str(_active_version)
|
56 | 60 |
|
@@ -82,13 +86,13 @@ def get_abi(contract_source: str, name: str) -> Dict:
|
82 | 86 |
|
83 | 87 | def _get_vyper_version_list() -> Tuple[List, List]:
|
84 | 88 | global AVAILABLE_VYPER_VERSIONS
|
85 |
| - installed_versions = vvm.get_installed_vyper_versions() |
| 89 | + installed_versions = _convert_to_semver(vvm.get_installed_vyper_versions()) |
86 | 90 | lib_version = Version(vyper.__version__)
|
87 | 91 | if lib_version not in installed_versions:
|
88 | 92 | installed_versions.append(lib_version)
|
89 | 93 | if AVAILABLE_VYPER_VERSIONS is None:
|
90 | 94 | try:
|
91 |
| - AVAILABLE_VYPER_VERSIONS = vvm.get_installable_vyper_versions() |
| 95 | + AVAILABLE_VYPER_VERSIONS = _convert_to_semver(vvm.get_installable_vyper_versions()) |
92 | 96 | except ConnectionError:
|
93 | 97 | if not installed_versions:
|
94 | 98 | raise ConnectionError("Vyper not installed and cannot connect to GitHub")
|
@@ -237,11 +241,14 @@ def compile_from_input_json(
|
237 | 241 | outputs.remove("devdoc")
|
238 | 242 | if version == Version(vyper.__version__):
|
239 | 243 | try:
|
240 |
| - return vyper_json.compile_json(input_json, root_path=allow_paths) |
| 244 | + return vyper_json.compile_json(input_json) |
241 | 245 | except VyperException as exc:
|
242 | 246 | raise exc.with_traceback(None)
|
243 | 247 | else:
|
244 | 248 | 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) |
245 | 252 | return vvm.compile_standard(input_json, base_path=allow_paths, vyper_version=version)
|
246 | 253 | except vvm.exceptions.VyperError as exc:
|
247 | 254 | raise CompilerError(exc, "vyper")
|
@@ -397,7 +404,7 @@ def _generate_coverage_data(
|
397 | 404 |
|
398 | 405 | if node["ast_type"] in ("Assert", "If") or (
|
399 | 406 | 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" |
401 | 408 | ):
|
402 | 409 | # branch coverage
|
403 | 410 | pc_list[-1]["branch"] = count
|
@@ -449,3 +456,24 @@ def _get_statement_nodes(ast_json: List) -> List:
|
449 | 456 | else:
|
450 | 457 | stmt_nodes.append(node)
|
451 | 458 | 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 | + ] |
0 commit comments