Closed knuesel closed 2 years ago
I guess we could add an in_nbinclude() = _in_nbinclude[]
function in the NBInclude modue, where we define the global const _in_nbinclude = Ref(false)
and then set _in_nbinclude[] = true
in the nbinclude
function by changing ret = my_include_string(m, s, string(path, ":In[", cellnum, "]"), prev, softscope)
to
ret = try
_in_nbinclude[] = true
my_include_string(m, s, string(path, ":In[", cellnum, "]"), prev, softscope)
finally
_in_nbinclude[] = false
end
Do you want to take a crack at a PR?
That looks good, thanks! I'm happy to make a PR (no time right now but in a few days).
Thinking about it a bit more, it should probably use task-local storage rather than a single global variable.
In particular, define:
const _in_nbinclude = :in_nbinclude_0db19996_df87_5ea3_a455_e3a50d440464 # unique symbol based on our UUID4
in_nbinclude() = get(Base.task_local_storage(), _in_nbinclude, false)::Bool
and then do
ret = Base.task_local_storage(_in_nbinclude, true) do
my_include_string(m, s, string(path, ":In[", cellnum, "]"), prev, softscope)
end
Thanks! (sorry for the silence, it's a busy time...)
It would be nice to have a function available in notebooks to check if code is being run by NBInclude. I currently do something like this:
This is related to #20. However using cell exclusions like in #20 requires setting
regex
in every@nbinclude
call.