-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add 'for' statement #108
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new 'for' statement to craft-grammar as part of implementing a new variant of advanced grammar. The 'for' statement allows matching against platforms and includes restrictions to prevent mixing with other statement types.
- Adds
ForStatement
class with platform matching functionality - Implements variant checking to prevent mixing 'for' with other grammar statements
- Updates base processor to support platforms parameter
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
craft_grammar/_for.py | New ForStatement implementation with platform matching logic |
craft_grammar/_processor.py | Adds variant tracking and 'for' statement parsing |
craft_grammar/_base_processor.py | Extends base to accept platforms parameter |
craft_grammar/errors.py | Adds ForStatementSyntaxError exception class |
tests/unit/test_for.py | Comprehensive test coverage for ForStatement |
tests/unit/test_processor.py | Tests for variant mixing prevention |
tests/unit/test_to.py | Corrects test function names from 'on' to 'to' |
tests/unit/test_errors.py | Tests for new ForStatementSyntaxError |
pyproject.toml | Adds "Afor" to codespell ignore list |
craft_grammar/init.py | Exports ForStatement class |
065ff50
to
5e716bf
Compare
Signed-off-by: Callahan Kovacs <[email protected]>
5e716bf
to
0760b13
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. I was expecting a bigger change initially, but this is clean and nice!
docs/changelog.rst
Outdated
|
||
New features: | ||
|
||
- Add a new 'for' statement to select against a platform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add a new 'for' statement to select against a platform. | |
- Add a new ``for`` statement to select against a platform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: 493f9fc
docs/changelog.rst
Outdated
|
||
.. _release 2.1.0: | ||
|
||
2.1.0 (2025-08-06) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.1.0 (2025-08-06) | |
2.1.0 (2025-08-11) |
Even if we merge today let's do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, this should have been undated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: 493f9fc
craft_grammar/_processor.py
Outdated
@@ -53,12 +70,15 @@ def __init__( | |||
returning true if it is valid. | |||
:param arch: the architecture the system is on. | |||
:param target_arch: the architecture the system is to build for. | |||
:param platforms: the platforms to build. Duplicates are ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since for a,b
is invalid, what is the use-case for platforms
having more than 1 item? Does this refer to all the possible platforms that a project declares, or just to the single platform that is currently being built?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall this discussion during the Frankfurt sprint but I don't know if it was written down:
Given
platforms:
[email protected]:amd64:
[email protected]:riscv64:
[email protected]:amd64:
[email protected]:riscv64:
When craft-application goes to build the [email protected]:riscv64
platform, craft-grammar could be invoked with
GrammarProcessor(
arch="riscv64",
target_arch="riscv64",
platforms=["[email protected]:riscv64", "24.04", "ubuntu", "riscv64"],
)
By default, craft-application would pass a single element list containing the entire platform name. An app can choose to override this and generate a list, like in the example above.
I'm fine to change this parameter to a string or clarify the docstrings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see, I remember some of that conversation now. I think I tripped on "the platforms to build", it made me think of the full set of platforms. Maybe something like "the currently active platform identifiers" would be less confusing? Well, less confusing in this particular aspect I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I cleaned up the whole docstring: 493f9fc
Signed-off-by: Callahan Kovacs <[email protected]>
make lint && make test
?Adds a
for
statement to craft-grammar. This is the first step towards a new variant of advanced grammar, so some restrictions apply:for a,b
is invalid)(IMAGECRAFT-38)