From 8bd0013d87c5e8507f05dd44f5d67fa3f848db73 Mon Sep 17 00:00:00 2001 From: z80 Date: Tue, 24 Oct 2023 18:07:19 -0400 Subject: [PATCH] fix: address PR comments --- ape_vyper/compiler.py | 9 +++++---- tests/contracts/passing_contracts/pragma_with_space.vy | 7 +++++++ tests/test_compiler.py | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 tests/contracts/passing_contracts/pragma_with_space.vy diff --git a/ape_vyper/compiler.py b/ape_vyper/compiler.py index 23c5c20c..169de7d6 100644 --- a/ape_vyper/compiler.py +++ b/ape_vyper/compiler.py @@ -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 @@ -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] @@ -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 } diff --git a/tests/contracts/passing_contracts/pragma_with_space.vy b/tests/contracts/passing_contracts/pragma_with_space.vy new file mode 100644 index 00000000..7b69ecf8 --- /dev/null +++ b/tests/contracts/passing_contracts/pragma_with_space.vy @@ -0,0 +1,7 @@ +# pragma version 0.3.10 + +x: uint256 + +@external +def __init__(): + self.x = 0 diff --git a/tests/test_compiler.py b/tests/test_compiler.py index 2d0b728c..b4258b5f 100644 --- a/tests/test_compiler.py +++ b/tests/test_compiler.py @@ -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.