-
Notifications
You must be signed in to change notification settings - Fork 441
Make examples runnable #900
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
Conversation
SimplyDanny
commented
Oct 8, 2022
- Add main method to both examples.
- Provide package defining executables for each example.
- Update examples to use SwiftParser.
The medium-term plan was for the examples to be migrated to Swift 5.7 snippets, which would let users run the examples using This was already implemented in #477, but reverted due to an Xcode issue, and therefore currently put on hold. cc @ahoppen |
Thanks for the idea but I agree with @fwcd that we should be using SwiftPM’s snippets to make sure the examples compile one they are available in Xcode. That way we don’t spam the targets in Package.swift. Also, I think the primary used case for these example should be to show how the API can be used and not a set of scripts should be easy to run. |
I accept the decision to keep everything as it is, but I also have some thoughts I would like to share:
|
I think the central idea is that these scripts are really intended to be more of a documentation on how to quickly get started using the API rather than standalone programs. So ideally they'd have as little noise as possible around them (main methods, argument parsing, ...). I definitely agree that being able to run them directly can be very useful and from what I understand we also do want to have them as part of the build pipeline, e.g. to make sure that they stay in sync with the (rapidly evolving) API. Snippets let us do all of this without the added complexity of another package layer. For |
Regarding the outdated APIs: Fixes are definitely welcomed there, I think especially the |
Oh, sorry, I somehow missed that you also adjusted these scripts, I inferred too much from the PR title, sorry.
|
Created #929 to address the accepted changes. I'm still not happy with the examples not being easily executable. Hope the issue Xcode is having with the Snippets will be resolved shortly. On the other hand, why not just name the folder back to |
What would your use case of having these example being runnable be? I can’t really see any but I might be missing something. What I would like to avoid is that these examples start becoming a grab-bag of scripts based on SwiftSyntax that people rely on in production use cases.
Yes, exactly, if you rename the folder to Snippets, building the package in Xcode fails with
in the snippets |
I see two: First off, you can easily run them to verify they still compile and produce reasonable results, in other words, they are not outdated. Secondly, people discovering the project can readily use them to get an idea on how the stuff works. They may change their content experimenting a bit with the API. I expect most of the people to write their own |
Thinking over it for a few days, maybe I was wrong to close this. I think we should move to snippets as soon as they are available but in the meantime a separate package is probably right after all. If you want to re-open this, could you modify |
Sorry if my comments came across a bit harsh. As long as we keep the examples simple scripts, having a package manifest for them probably doesn't hurt, that's true. Ultimately making them snippets would be nice, but being able to run them now benefits everyone and also makes it easier to test against regressions. |
No worries! Happy I was able to convince you in the end. 😉 I've updated my branch incorporating the newly added example, letting the build script know about the examples and rebasing it onto I guess, the changes in |
I can’t re-open it either. It says ”The runnable-examples branch was force-pushed or recreated.”. Could you just open a new PR?
Sure. |
Ah, I should not have updated the branch. Created #1007. |
You could have force-pushed the old commit, reopened and then force-pushed back the new commit :D But yeah, a new PR works too |