Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support Vyper 0.3.10 #97

Merged
merged 16 commits into from
Oct 26, 2023
9 changes: 5 additions & 4 deletions ape_vyper/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_version_pragma_spec(source: Union[str, Path]) -> Optional[SpecifierSet]:
if pragma_match is None:
# support new pragma syntax
pragma_match = next(
re.finditer(r"(?:\n|^)\s*#pragma\s+version\s*([^\n]*)", source_str), None
re.finditer(r"(?:\n|^)\s*#\s*pragma\s+version\s*([^\n]*)", source_str), None
z80dev marked this conversation as resolved.
Show resolved Hide resolved
)
if pragma_match is None:
return None # Try compiling with latest
Expand All @@ -100,19 +100,20 @@ def get_version_pragma_spec(source: Union[str, Path]) -> Optional[SpecifierSet]:
return None


def get_optimization_pragma(source: Union[str, Path]) -> Union[str, bool]:
def get_optimization_pragma(source: Union[str, Path]) -> Optional[str]:
"""
Extracts optimization pragma information from Vyper source code.

Args:
source (str): Vyper source code
z80dev marked this conversation as resolved.
Show resolved Hide resolved

Returns:
z80dev marked this conversation as resolved.
Show resolved Hide resolved
``str``, or True if no valid pragma is found (for backwards compatibility).
"""
source_str = source if isinstance(source, str) else source.read_text()
pragma_match = next(re.finditer(r"(?:\n|^)\s*#pragma\s+optimize\s+([^\n]*)", source_str), None)
if pragma_match is None:
return True
return None
z80dev marked this conversation as resolved.
Show resolved Hide resolved
return pragma_match.groups()[0]


Expand Down Expand Up @@ -307,7 +308,7 @@ def compile(

for optimization, source_paths in optimizations_map.items():
settings: Dict[str, Any] = version_settings.copy()
settings["optimize"] = optimization
settings["optimize"] = optimization or True
path_args = {
str(get_relative_path(p.absolute(), base_path)): p for p in source_paths
}
Expand Down
7 changes: 7 additions & 0 deletions tests/contracts/passing_contracts/pragma_with_space.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pragma version 0.3.10

x: uint256

@external
def __init__():
self.x = 0
1 change: 1 addition & 0 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def test_get_version_map(project, compiler, all_versions):
"use_iface2.vy",
"contract_no_pragma.vy", # no pragma should compile with latest version
"empty.vy", # empty file still compiles with latest version
"pragma_with_space.vy",
]

# Add the 0.3.10 contracts.
Expand Down
Loading