fix: detect modern vyper version pragmas - #166
Merged
Merged
Conversation
banteg
force-pushed
the
feat/vyper-pragma-version
branch
4 times, most recently
from
May 9, 2026 13:19
8e58fba to
62c7358
Compare
fubuloubu
approved these changes
May 9, 2026
banteg
force-pushed
the
feat/vyper-pragma-version
branch
from
May 9, 2026 13:42
62c7358 to
866d4f2
Compare
fubuloubu
approved these changes
May 9, 2026
fubuloubu
enabled auto-merge (squash)
May 9, 2026 13:43
antazoey
reviewed
May 26, 2026
|
|
||
|
|
||
| def _as_pep440_spec(pragma_str: str) -> str: | ||
| pragma_str = pragma_str.replace("^", "~=") |
Member
There was a problem hiding this comment.
This is wrong for post 1.0 vyper
Contributor
Author
There was a problem hiding this comment.
this is a direct port of how vyper itself does it https://github.com/vyperlang/vyper/blob/c219e6be2f230931be19a8eb945dc432538f9245/vyper/ast/pre_parser.py#L30
from my understanding ^1.0.0 in semver is >=1.0.0 <2.0.0
while the rewritten ~=1.0.0 in pep440 becomes >=1.0.0 <1.1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Current Vyper accepts source compiler constraints in both legacy
# @version ...comments and modern# pragma version ...comments.ape-vyperonly recognized the legacy spelling, so modern Vyper sources could be grouped with no-pragma sources and compiled with the wrong selected compiler before Vyper itself validated the source constraint.Vyper also changed the version-pragma grammar across releases:
v0.3.9and earlier use npm-style semantic version specs, whilev0.3.10and newer usepackaging.specifiers.SpecifierSet-style rules after caret translation. Ape needs to use the rules for each candidate compiler version, otherwise compiler selection can accept or reject a pragma differently than Vyper would.Malformed present pragmas now fail early as
VyperCompileErrorinstead of being treated as missing pragmas.Code References
validate_version_pragma().# pragma version.# @version.compiler_versionsource-only, not a compiler input.#pragma version, and import validation.v0.3.9usedNpmSpec;v0.3.10switched toSpecifierSet.Summary
# @version ...and# pragma version ....#pragma version ....<0.3.10, PEP 440-style for>=0.3.10.semantic-versionfor the legacy npm-style grammar.VyperCompileErrorwhen a present version pragma cannot be parsed.Tests
git diff --checkuv run --group lint ruff check .uv run --group lint ruff format --check .uv run --group lint --group test mypy .uv run --python 3.11 --group test python -m py_compile ape_vyper/_utils.py ape_vyper/compiler/api.py tests/functional/test_compiler.pyuv run --python 3.11 --group test pytest tests/functional/test_compiler.py -q -k "version_pragma_spec or version_map_modern_pragma or version_map_invalid_pragma"(29 passed, 102 deselected)Note:
uv run --python 3.11 --group test pytest tests/functional/test_compiler.py -qwas also attempted locally. The compile-heavy cases failed aftervvm.get_installable_vyper_versions()hit the GitHub API rate limit, leaving no installable0.4.xcompiler for the existing 0.4 fixtures. The focused parser/version-map coverage above passes.