From 866d4f2047c22fde666b1416b7d2f317e5b827e4 Mon Sep 17 00:00:00 2001 From: banteg <4562643+banteg@users.noreply.github.com> Date: Sat, 9 May 2026 16:16:54 +0400 Subject: [PATCH] fix: detect modern vyper version pragmas --- ape_vyper/_utils.py | 122 ++++++++++++++++++++++++------ ape_vyper/compiler/api.py | 10 ++- pyproject.toml | 1 + tests/functional/test_compiler.py | 101 ++++++++++++++++++++++++- 4 files changed, 208 insertions(+), 26 deletions(-) diff --git a/ape_vyper/_utils.py b/ape_vyper/_utils.py index 61e9755..ce697c2 100644 --- a/ape_vyper/_utils.py +++ b/ape_vyper/_utils.py @@ -2,7 +2,7 @@ import re import subprocess import time -from collections.abc import Iterable +from collections.abc import Iterable, Iterator from enum import Enum from pathlib import Path from typing import TYPE_CHECKING, Any @@ -15,14 +15,16 @@ from eth_utils import is_0x_prefixed from ethpm_types import ASTNode, PCMap, SourceMapItem from packaging.specifiers import InvalidSpecifier, SpecifierSet +from packaging.version import Version +from semantic_version import NpmSpec # type: ignore[import-untyped] +from semantic_version import Version as NpmVersion # type: ignore[import-untyped] from vvm.exceptions import UnknownOption, UnknownValue # type: ignore -from ape_vyper.exceptions import RuntimeErrorType, VyperError, VyperInstallError +from ape_vyper.exceptions import RuntimeErrorType, VyperCompileError, VyperError, VyperInstallError if TYPE_CHECKING: from ape.types.trace import SourceTraceback from ethpm_types.source import Function - from packaging.version import Version Optimization = str | bool EVM_VERSION_DEFAULT = { @@ -82,7 +84,82 @@ def install_vyper(version: "Version"): ) from err -def get_version_pragma_spec(source: str | Path) -> SpecifierSet | None: +VERSION_PRAGMA_PATTERN = re.compile( + r"(?:\n|^)\s*#\s*(?P