-
Notifications
You must be signed in to change notification settings - Fork 10
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
Adding devel to CI, fix #161, fix #149 #169
Conversation
I am adding both stable (that will become 2.x soon) and devel (which is candidate for 2.x). Also update versions of cache and setup-nim-action
we have a failure with devel but it seems about |
ok, now we have failure only in devel |
It seems to be a regression of ORC. It doesn't work with ARC/ORC in 1.6.10 either. |
import nimib
nbInit
nbCode:
# a comment
let
x = 1
|
macro getCodeAsInSource*(source: string, command: static string, body: untyped): string =
## Returns string for the code in body from source.
# substitute for `toStr` in blocks.nim
let startPos = startPos(body)
let filename = startPos.filename.newLit
let endPos = finishPos(body)
let endFilename = endPos.filename.newLit
result = quote do:
if `filename` notin nb.sourceFiles:
nb.sourceFiles[`filename`] = readFile(`filename`)
doAssert `endFilename` == `filename`, """
Code from two different files were found in the same nbCode!
If you want to mix code from different files in nbCode, use -d:nimibCodeFromAst instead.
If you are not mixing code from different files, please open an issue on nimib's Github with a minimal reproducible example."""
getCodeBlock(nb.sourceFiles[`filename`], `command`, `startPos`, `endPos`) It seems that in |
so that is something we recently touched in #163 and I think @HugoGranstrom is better positioned than me to answer about it. |
Isn't this just a bug in the compiler and not a problem on our side? |
Yeah, It's a weird compiler bug, though. I don't have a solution or a workaround. |
Ok, that's problematic 🤔 because we do need the filename and it must come from the macro. I'll have a look in the coming days and see if I can find an alternative way 👍 |
I have tried to trick the compiler by wrapping the strung in a ident and running |
You might report the bug to Nim if you happen to find a reduced case. |
I'll give it a try 👍 |
I tried using nimib
So even if we manage to solve this specific issue I fear we have a few other orc bugs as well that isn't related to macros 🙃 |
But for the macro, it seems like it is the |
It seems to work if we create a literal of the
Then the question is whether the code without converting to a literal should work or not. |
@pietroppeter This is the new macro getCodeAsInSource*(source: string, command: static string, body: untyped): string =
## Returns string for the code in body from source.
# substitute for `toStr` in blocks.nim
let startPos = startPos(body)
let filename = startPos.filename.newLit
let endPos = finishPos(body)
let endFilename = endPos.filename.newLit
let endPosLit = endPos.newLit
let startPosLit = startPos.newLit
result = quote do:
if `filename` notin nb.sourceFiles:
nb.sourceFiles[`filename`] = readFile(`filename`)
doAssert `endFilename` == `filename`, """
Code from two different files were found in the same nbCode!
If you want to mix code from different files in nbCode, use -d:nimibCodeFromAst instead.
If you are not mixing code from different files, please open an issue on nimib's Github with a minimal reproducible example."""
getCodeBlock(nb.sourceFiles[`filename`], `command`, `startPosLit`, `endPosLit`) Now I'm getting the same runtime error as I got in nimib 0.3.0 though... |
Issue for macro opened: nim-lang/Nim#21326 |
I'm not able to wrap my head around the runtime error 😞 This reproduces it locally for me (I have installed import os
import "$nim/compiler/pathutils"
import nimib, nimib/[options, config]
var nb: NbDoc
nb.initDir = getCurrentDir().AbsoluteDir
loadOptions nb
loadCfg nb
let thisFile = "/home/hugo/code/nim/nimib/x_pathutils.nim".AbsoluteFile
echo thisFile
echo thisFile.splitFile
echo thisFile.splitFile.dir
echo thisFile.splitFile.dir.string / "a" This gives this output:
And we can note several things. First, the I have no clue what's going on and what to blame tbh. Is it toml_serialization with yet another orc bug or a bug in the compiler which just happens to show up when using toml_serialization for a totally different part of the program? |
This is getting really weird, did not have too much time to look into this myself and not sure how to help at the moment! |
I think anyway you did make a few good steps toward resolution, thanks for that! Last example with toml vs compiler bug I guess it could be nice to have it further simplified but it does not seem to be easy. |
It's definitely a toml problem, managed to reduce it to this: import toml_serialization
type NbConfig* = object
srcDir*, homeDir*: string
let f = readFile("nimib.toml")
let t = Toml.decode(f, NbConfig, "nimib")
echo t # error here # nimib.toml
[nimib]
srcDir = "docsrc"
homeDir = "docs" So we are still blocked by toml_serialization. I'm honestly tempted to change toml library to https://github.com/NimParsers/parsetoml which I just tried and it works under |
Ok then we should report the error on toml serialization, that at least is good news since there is not anything weirder. I agree we should consider changing library, apart the various dependencies we get from status (which I never liked), it makes it hard to fix it ourselves. The api of parseToml though at the moment does not support how we use it in nimib (also nimibook will be affected). The advantage of toml serialization was that you could target parsing a specific section and parse using a type as specification, similar to what jsony does. It is possible we might be able to add that feature to parseToml, I will look into it. |
Have opened an issue on toml_serialization: status-im/nim-toml-serialization#62 |
Do you want to give it a try? |
I don't have much free time this weekend but I could try it next weekend 👍 |
* fix orc macro bug * replace toml_serialization with parsetoml * clean up * use jsony for deserialzation as it can handle missing fields Co-authored-by: Hugo Granström <[email protected]>
should we bump to 0.4 or a minor bump to 0.3.6 given the parsetoml change? I would go with 0.3.6 but fine with the other too, @HugoGranstrom? |
and for the changelog I was thinking of bumping, releasing curating the automatic changelog and adding the results to changelog.md. We could actually change our workflow to "not update changelog during PRs" and only make sure that message in PR merge commit is a good for the automatic changelog provided by Github. I would still want for the moment to maintain the changelog.md (especially for the history part) by updating it after the release. |
ready to merge and release if you are ok with bumping to 0.3.6 @HugoGranstrom |
0.3.6 sounds good to me! 👌 Release it! Changelog idea sounds good for the future 👍 |
I am adding both stable (that will become 2.x soon) and devel (which is candidate for 2.x). Also update versions of cache and setup-nim-action.
Done to check if recent toml fix makes nimib works in 2.0rc
We could also decide to expand the test matrix to multiple os.
fix #161 and #149