-
Notifications
You must be signed in to change notification settings - Fork 45
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
Allow execution of included OCaml code blocks #446
Conversation
Signed-off-by: Paul-Elliot <[email protected]>
I see the new flag has been added for retro-compatibility, but it sounds confusing to me to have the It sounds acceptable to me to make this a breaking change and make people add a |
I would be very happy to remove the However, there is a bit more "breaking changes" than what we first think:
If we remove the
If we do i. and do not change the "skip" behavior, it is not anymore possible to have the old "no tag" behavior: inclusion but no execution. If we go with ii. we can still have the old "skip" behavior by removing the "file" tag. So what would you think of ii.:
? I'm happy with this, but I think it is quite a big breaking change for any code that has some side effects (such as creating a file, ...) |
I have another suggestion based on the behavior of other kind of blocks. I had a look in
Previously the
|
That's a sensible idea. But I'm not super happy with reusing a command with an associated semantics (the fact that the output/command is non deterministic). In particular, the I think the combination
|
I implemented your suggestion. I had to add a disctinction on the |
@panglesd I moved the |
I still think that In order to "skip" the inclusion, just omit the |
Signed-off-by: Paul-Elliot <[email protected]>
49235c8
to
c6e6906
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.
I cannot approve my own pull request, but I do approve!
ee53374
to
6842166
Compare
I'm a bit concerned with breaking existing users. A search on github yields quite a lot of results which rely on the code not being executed:
So, I think the decision to do this breaking change is OK (mdx is still in early versions) but the change should be well communicated! |
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.
Maybe it would still make sense to add skip
to the parts-begin-end
test and sync-to-md
tests as they were written with the idea of not executing the code, and the multiple errors are making it harder to read the thing that was actually tested.
6842166
to
befa05f
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.
Alright, looks good to me now, thanks @panglesd!
Waiting for the CI, then I will merge.
CHANGES: #### Added - Handle the error-blocks syntax (realworldocaml/mdx#439, @jonludlam, @gpetiot) - Allow execution of included OCaml code blocks (realworldocaml/mdx#446, @panglesd) - Make MDX compatible with OCaml 5.2 (realworldocaml/mdx#448, @gpetiot) #### Fixed - Reduce false-positives while detecting warnings (realworldocaml/mdx#440, @Julow)
MDX 2.4.0 fails on `lang-shader-graphics/README.md` with: ``` Line 2, characters 28-33: Error: Unbound module Env ``` It seems like MDX now checks file-part snippets, which is very frustrating if you want to show a snippet of code with imports and definitions that lie outside that snippet. I think this new behaviour might have been introduced in realworldocaml/mdx#446 – the eio developers seem to have run into this as well. There doesn’t seem to be a way to turn off this behaviour, so we’ll have to limit the version range for now.
Hello! I think this change broke my build. Previously file parts, eg. in this README.md were not checked, but now I’m getting: File "lang-shader-graphics/README.md", line 1, characters 0-0:
diff --git a/_build/default/lang-shader-graphics/README.md b/_build/default/lang-shader-graphics/.mdx/README.md.corrected
index 35fa4cc..1717a2e 100644
--- a/_build/default/lang-shader-graphics/README.md
+++ b/_build/default/lang-shader-graphics/.mdx/README.md.corrected
@@ -27,6 +27,10 @@ let scene : (vec3f repr) Env.t =
(* The final output colour to render at the current UV coordinate. *)
Env.pure (background_color |> overlay ~shape:shape ~color:shape_color)
```
+```mdx-error
+Line 2, characters 28-33:
+Error: Unbound module Env
+```
The resulting DSL is clunkier than I’d like. This is due to OCaml’s odd approach
to custom operators (which don’t allow for custom precedences), and lack of This is an issue if you want to include file parts where modules and definitions lie outside the code snippets. Is there a way to disable this behavior? I didn’t see any instructions in the changelog or README with guidance, so I’ve limited my MDX version for now, brendanzab/language-garden@3e890a8, following the example of the eio developers in ocaml-multicore/eio#706. |
You can use the - <!-- $MDX file=examples/Readme.ml,part=scene -->
+ <!-- $MDX file=examples/Readme.ml,part=scene,skip --> @gpetiot, do you want to announce the release on discuss? It was suggested a few times already, and we can see it is not clear enough how to upgrade to 2.4! Also, mentioning
|
Signed-off-by: Paul-Elliot <[email protected]>
Hmm, I just tried using I had actually assumed this would be the case, which is why I didn’t think there was a workaround, but I should have checked and mentioned it when reporting! |
Mmmh, I tried on your specific case, and it seems that doing However, without the |
Ahh! Yeah it seems like maybe At any rate, I do think it’s very surprising in general for file parts to be executed by default, seeing as they are usually part of an existing file. I’m also wondering if it would it be better to make the code execution behavior opt-in in? It does seem like a big change in the default behavior for a minor release at any rate? 🤔 |
Wait! It’s not dune, it’s part of how mdx collects dependencies! Lines 19 to 26 in bf33f76
|
This PR in its original form included a new
Well spotted, thanks! |
We can but it's gonna take some sweat since the commits have been squashed to clean up the history. |
The commit wit the |
Signed-off-by: Paul-Elliot <[email protected]>
CHANGES: #### Changed - Revert realworldocaml/mdx#446: "Allow execution of included OCaml code blocks" (realworldocaml/mdx#451, @gpetiot). Included OCaml code blocks preserve their pre-2.4.0 behavior.
realworldocaml/mdx#446 adds an ability to run included blocks. Our included block is not meant to be run, however, and it appears that there's no easy way to skip the running. So as a temporary workaround, we set the upper bound on the MDX version until a satisfactory solution emerges.
realworldocaml/mdx#446 adds an ability to run included blocks. Our included block is not meant to be run, however, and it appears that there's no easy way to skip the running. So as a temporary workaround, we set the upper bound on the MDX version until a satisfactory solution emerges.
This PR allows to execute OCaml code blocks.
This is useful whenever someone wants to separate the actual code from the mdx-experiments on it.
For instance:
Without this PR, we would have an "unbound value" error for the
compute
function. This will prove especially useful for the odoc reference driver.I added a
exec
flag to execute an included code block only for backward compatibility.