Skip to content

Commit

Permalink
fix: address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev committed Oct 24, 2023
1 parent b13e2a1 commit 8bd0013
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
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
)
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
Returns:
``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
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

0 comments on commit 8bd0013

Please sign in to comment.