Open mauro3 opened 1 year ago
Does it work if you do include
? nbinclude
is supposed to pick the path the same way.
It's a bit tricky to do with include
because the only other backend of Literate which allows execution is markdown, which does not produce executable files, i.e. the markdown file cannot be included then.
Anyway, I did a bit more digging and found that if I execute @__DIR__
in the script being processed by Literate, it will pick up the output folder (i.e. the notebooks/
folder). This seems to indicate that Literate is changing the current directory to the correct place but this is then not picked up by @nbinclude
.
Note that I have this work-around: https://github.com/eth-vaw-glaciology/GlacioTeaching.jl/blob/ce04d95629c73df2f3d23337a1a9aaba93770239/src/GlacioTeaching.jl#L14
I now updated the linked repo. The script which shows the issue is now scripts/lit-script-include.jl
and scripts/lit-script.jl
just does the @__DIR__
thingy.
Also, the script is now more realistic with https://github.com/mauro3/NBinclude-issue-tmp.jl/blob/caeb185732acaee10ddf99c7e7e39f4b56e3c1fd/scripts/lit-script-include.jl#L3-L4 being used for notebook creation and https://github.com/mauro3/NBinclude-issue-tmp.jl/blob/caeb185732acaee10ddf99c7e7e39f4b56e3c1fd/scripts/lit-script-include.jl#L6 otherwise.
When you do @nbinclude
, it acts like include
— it doesn't change the current working directory, but it should change @__FILE__
and @__DIR__
to that of the notebook file. And the path of the .ipynb
file itself should be interpreted relative to the path of the file that is calling @nbinclude
.
I'm a little confused about whether one of these behaviors is not happening in your case, or if it is happening but you want a different behavior.
When generating and evaluating notebooks with https://github.com/fredrikekre/Literate.jl via a scrip which is not in the output directory, then
@nbinclude
generates a path which contains the path of the Literate script and not the path of the notebook-directory. I'm pretty sure that this is a NBInclude issue, but happy to move to Literate.jl if that is not the case.To reproduce I setup a repo: https://github.com/mauro3/NBinclude-issue-tmp.jl
After cloning that repo, reproduce with:
Backtrace:
Stacktrace: [1] error(s::String) @ Base ./error.jl:35 [2] execute_block(sb::Module, block::String; inputfile::String, fake_source::String) @ Literate ~/.julia/packages/Literate/VQn4b/src/Literate.jl:866 [3] execute_notebook(nb::Dict{Any, Any}; inputfile::String, fake_source::String) @ Literate ~/.julia/packages/Literate/VQn4b/src/Literate.jl:764 [4] (::Literate.var"#38#40"{Dict{String, Any}})() @ Literate ~/.julia/packages/Literate/VQn4b/src/Literate.jl:744 [5] cd(f::Literate.var"#38#40"{Dict{String, Any}}, dir::String) @ Base.Filesystem ./file.jl:112 [6] jupyter_notebook(chunks::Vector{Literate.Chunk}, config::Dict{String, Any}) @ Literate ~/.julia/packages/Literate/VQn4b/src/Literate.jl:743 [7] notebook(inputfile::String, outputdir::String; config::Dict{Any, Any}, kwargs::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:execute,), Tuple{Bool}}}) @ Literate ~/.julia/packages/Literate/VQn4b/src/Literate.jl:680 [8] top-level scope @ ~/julia/issues/literate-nbinclude/gen-notebook.jl:6 [9] include(fname::String) @ Base.MainInclude ./client.jl:476 [10] top-level scope @ REPL[7]:1 in expression starting at ~/julia/issues/literate-nbinclude/gen-notebook.jl:6
julia>