Skip to content

Commit

Permalink
fix[tool]: keep experimentalCodegen blank in standard json input (v…
Browse files Browse the repository at this point in the history
…yperlang#4216)

in standard json input, `experimentalCodegen` would default
to true, creating a conflict if the user used `#pragma
experimental-codegen`. set it to `None`.

misc/refactor:
- refactor `get_settings` function.

---------

Co-authored-by: Ramana Kumar <ramana@member.fsf.org>
  • Loading branch information
charles-cooper and xrchz authored Sep 1, 2024
1 parent 973672a commit 9a208a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
13 changes: 12 additions & 1 deletion tests/unit/cli/vyper_json/test_get_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper.cli.vyper_json import get_evm_version
from vyper.cli.vyper_json import get_evm_version, get_settings
from vyper.exceptions import JSONError


Expand Down Expand Up @@ -30,3 +30,14 @@ def test_early_evm(evm_version_str):
@pytest.mark.parametrize("evm_version_str", ["london", "paris", "shanghai", "cancun"])
def test_valid_evm(evm_version_str):
assert evm_version_str == get_evm_version({"settings": {"evmVersion": evm_version_str}})


def test_experimental_codegen_settings():
input_json = {"settings": {}}
assert get_settings(input_json).experimental_codegen is None

input_json = {"settings": {"experimentalCodegen": True}}
assert get_settings(input_json).experimental_codegen is True

input_json = {"settings": {"experimentalCodegen": False}}
assert get_settings(input_json).experimental_codegen is False
20 changes: 12 additions & 8 deletions vyper/cli/vyper_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,11 @@ def get_search_paths(input_dict: dict) -> list[PurePath]:
return [PurePath(p) for p in ret]


def compile_from_input_dict(
input_dict: dict, exc_handler: Callable = exc_handler_raises
) -> tuple[dict, dict]:
if input_dict["language"] != "Vyper":
raise JSONError(f"Invalid language '{input_dict['language']}' - Only Vyper is supported.")

def get_settings(input_dict: dict) -> Settings:
evm_version = get_evm_version(input_dict)

optimize = input_dict["settings"].get("optimize")
experimental_codegen = input_dict["settings"].get("experimentalCodegen", False)
experimental_codegen = input_dict["settings"].get("experimentalCodegen")
if isinstance(optimize, bool):
# bool optimization level for backwards compatibility
warnings.warn(
Expand All @@ -271,10 +266,19 @@ def compile_from_input_dict(
else:
assert optimize is None

settings = Settings(
return Settings(
evm_version=evm_version, optimize=optimize, experimental_codegen=experimental_codegen
)


def compile_from_input_dict(
input_dict: dict, exc_handler: Callable = exc_handler_raises
) -> tuple[dict, dict]:
if input_dict["language"] != "Vyper":
raise JSONError(f"Invalid language '{input_dict['language']}' - Only Vyper is supported.")

settings = get_settings(input_dict)

no_bytecode_metadata = not input_dict["settings"].get("bytecodeMetadata", True)

integrity = input_dict.get("integrity")
Expand Down

0 comments on commit 9a208a6

Please sign in to comment.